From 04c27dde38a03fd7f4b2b7c73ebd37669704d035 Mon Sep 17 00:00:00 2001 From: Alexis Drai Date: Sat, 10 Jun 2023 19:13:09 +0200 Subject: [PATCH] :bug: Fix #6 : Make cancelling make more sense --- Graduator/Graduator/Data/UnitsStore.swift | 2 +- Graduator/Graduator/View/Cells/SubjectViewCell.swift | 3 --- Graduator/Graduator/View/Views/UnitView.swift | 9 +++++++++ Graduator/Graduator/ViewModel/UnitsManagerVM.swift | 1 - 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Graduator/Graduator/Data/UnitsStore.swift b/Graduator/Graduator/Data/UnitsStore.swift index 045b439..a8ebfbe 100644 --- a/Graduator/Graduator/Data/UnitsStore.swift +++ b/Graduator/Graduator/Data/UnitsStore.swift @@ -16,7 +16,7 @@ class UnitsStore: ObservableObject { in: .userDomainMask, appropriateFor: nil, create: false - ).appendingPathComponent("my.data") + ).appendingPathComponent("my.local.data") } func load(defaultValue: [T]) async throws -> [T] { diff --git a/Graduator/Graduator/View/Cells/SubjectViewCell.swift b/Graduator/Graduator/View/Cells/SubjectViewCell.swift index 54fc022..89b3f6c 100644 --- a/Graduator/Graduator/View/Cells/SubjectViewCell.swift +++ b/Graduator/Graduator/View/Cells/SubjectViewCell.swift @@ -17,9 +17,6 @@ struct SubjectViewCell: View { var body: some View { HStack { VStack { - // FIXME (later, maybe) when getting updated from the UnitView, these two changes are persisted right away instead of waiting for user - // to confirm changes. They just don't get brought into the main UnitsManager, so the average is not recalculated when a unit's weight changes - // when 'cancel' is hit, it would be nice to reset these two values as well, like a user might expect HStack { TextField("", text: $subjectVM.model.name) .disabled(!unitsManagerVM.isAllEditable) diff --git a/Graduator/Graduator/View/Views/UnitView.swift b/Graduator/Graduator/View/Views/UnitView.swift index 3a4650a..93dc0c6 100644 --- a/Graduator/Graduator/View/Views/UnitView.swift +++ b/Graduator/Graduator/View/Views/UnitView.swift @@ -15,6 +15,8 @@ struct UnitView: View { @State private var showingForm: Bool = false var formVM = SubjectFormVM() + // TODO maybe later: when a subject is deleted this way, if the user clicks on 'Annuler', the deletion should be cancelled + // then update the readme accrodingly private func delete(at offsets: IndexSet) { guard let index = offsets.first else { return } let subjectVMToDelete = unitVM.SubjectsVM[index] @@ -75,9 +77,15 @@ struct UnitView: View { Button(action: { showingForm = true }) { Image(systemName: "plus") } + // FIXME this does cancel the changes made **to unit and subject** names and weights, + // but whereas names visibly revert instantaneously to old values, like we should expect, + // weights are displayed as new, cancelled values until user clicks on 'Modifier' again, when it finally takes on the true, old, value + // ... weights should visibly revert instantaneously to old values Button(action: { + unitVM.isEdited = false unitsManagerVM.isAllEditable.toggle() unitVM.onEdited(isCancelled: true) + unitVM.SubjectsVM.forEach { $0.onEdited(isCancelled: true) } }) { Text("Annuler") } @@ -137,6 +145,7 @@ struct UnitView: View { // If user navigates back while editing but before clicking 'OK', the changes are cancelled .onDisappear(perform: { if unitsManagerVM.isAllEditable { + unitVM.isEdited = false unitVM.onEdited(isCancelled: true) unitsManagerVM.isAllEditable = false } diff --git a/Graduator/Graduator/ViewModel/UnitsManagerVM.swift b/Graduator/Graduator/ViewModel/UnitsManagerVM.swift index 296a6d4..5f44b52 100644 --- a/Graduator/Graduator/ViewModel/UnitsManagerVM.swift +++ b/Graduator/Graduator/ViewModel/UnitsManagerVM.swift @@ -44,7 +44,6 @@ class UnitsManagerVM : ObservableObject { private var original: UnitsManager @Published var model: UnitsManager.Data - @Published var isEdited: Bool = false @Published var isAllEditable: Bool = false private var unitsVM: [UnitVM]