work around widgets ... not sure if they work

This commit is contained in:
Trey t
2022-01-15 18:05:48 -06:00
parent 0298b3bf5e
commit 7c2de764b4
23 changed files with 375 additions and 199 deletions

View File

@@ -26,7 +26,7 @@ struct AddMoodHeaderView: View {
ForEach(Mood.allValues.reversed()) { mood in
VStack {
Button(action: {
addItem(withMoodValue: mood.rawValue)
addItem(withMood: mood)
}, label: {
mood.icon
.resizable()
@@ -47,21 +47,9 @@ struct AddMoodHeaderView: View {
.padding()
}
private func addItem(withMoodValue moodValue: Int) {
private func addItem(withMood mood: Mood) {
withAnimation {
let newItem = MoodEntry(context: viewContext)
newItem.timestamp = Date()
newItem.moodValue = Int16(moodValue)
newItem.forDate = Date()
do {
try viewContext.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
PersistenceController.shared.add(mood: mood, forDate: Date())
}
}
}