diff --git a/CHDataManagement/Main/MainView.swift b/CHDataManagement/Main/MainView.swift index 38d2a89..f0944df 100644 --- a/CHDataManagement/Main/MainView.swift +++ b/CHDataManagement/Main/MainView.swift @@ -244,6 +244,8 @@ struct MainView: App { showInitialSheet() case .isSaved, .needsSave: content.saveUnconditionally() + case .isSaving: + break case .failedToSave, .savingPausedDueToLoadErrors: showStorageErrorSheet = true } diff --git a/CHDataManagement/Model/Content+Save.swift b/CHDataManagement/Model/Content+Save.swift index 7ae1ce9..11e5b8d 100644 --- a/CHDataManagement/Model/Content+Save.swift +++ b/CHDataManagement/Model/Content+Save.swift @@ -6,7 +6,7 @@ extension Content { setModificationTimestamp() if saveState == .isSaved { - update(saveState: saveState) + update(saveState: .needsSave) } // Wait a few seconds for a save, to allow additional changes // Reduces the number of saves @@ -17,18 +17,16 @@ extension Content { func saveIfNeeded() { switch saveState { - case .isSaved, .savingPausedDueToLoadErrors, .storageNotInitialized: + case .isSaved, .savingPausedDueToLoadErrors, .storageNotInitialized, .isSaving: return - default: + case .needsSave, .failedToSave: break } - if Date.now.timeIntervalSince(lastModification) < 5 { // Additional modification made // Wait for next scheduled invocation of saveIfNeeded() // if the overall unsaved time is not too long if Date.now.timeIntervalSince(lastSave) < 30 { - //print("Waiting while modifying") return } print("Saving after 30 seconds of modifications") @@ -37,6 +35,7 @@ extension Content { } func saveUnconditionally() { + update(saveState: .isSaving) guard saveToDisk() else { update(saveState: .failedToSave) // TODO: Try to save again diff --git a/CHDataManagement/Model/Content.swift b/CHDataManagement/Model/Content.swift index d900974..4ddcdae 100644 --- a/CHDataManagement/Model/Content.swift +++ b/CHDataManagement/Model/Content.swift @@ -184,9 +184,7 @@ final class Content: ObservableObject { private(set) var lastModification: Date = .now func update(saveState: SaveState) { - DispatchQueue.main.async { - self.saveState = saveState - } + self.saveState = saveState } func setModificationTimestamp() { diff --git a/CHDataManagement/Storage/SaveState.swift b/CHDataManagement/Storage/SaveState.swift index 5372b24..cb5cb54 100644 --- a/CHDataManagement/Storage/SaveState.swift +++ b/CHDataManagement/Storage/SaveState.swift @@ -7,6 +7,7 @@ enum SaveState { case isSaved case needsSave case failedToSave + case isSaving var symbol: SFSymbol { switch self { @@ -20,6 +21,8 @@ enum SaveState { return .hourglassCircleFill case .failedToSave: return .exclamationmarkTriangleFill + case .isSaving: + return .hourglassCircleFill } } @@ -27,7 +30,7 @@ enum SaveState { switch self { case .storageNotInitialized: return .red - case .isSaved: + case .isSaved, .isSaving: return .green case .needsSave: return .yellow diff --git a/CHDataManagement/Views/Generic/DatePropertyView.swift b/CHDataManagement/Views/Generic/DatePropertyView.swift index 8e1c66e..68b8056 100644 --- a/CHDataManagement/Views/Generic/DatePropertyView.swift +++ b/CHDataManagement/Views/Generic/DatePropertyView.swift @@ -13,7 +13,7 @@ struct DatePropertyView: View { VStack(alignment: .leading) { Text(title) .font(.headline) - DatePicker("", selection: $value, displayedComponents: .date) + DatePicker("", selection: $value, displayedComponents: [.date, .hourAndMinute]) .datePickerStyle(.compact) Text(footer) .foregroundStyle(.secondary)