Selaa lähdekoodia

refactor: alert on autosave

Sam Jaffe 2 viikkoa sitten
vanhempi
commit
46ff6a9c41
1 muutettua tiedostoa jossa 9 lisäystä ja 0 poistoa
  1. 9 0
      Todos/View/ContentView.swift

+ 9 - 0
Todos/View/ContentView.swift

@@ -15,6 +15,7 @@ struct ContentView: View {
 
   @Query(sort: \Project.sortOrder) private var items: [Project]
   @State private var selection: Project?
+  @State private var hasAutosave: Bool = false
 
   var body: some View {
     NavigationSplitView {
@@ -47,6 +48,13 @@ struct ContentView: View {
       }
     }
     .onAppear(perform: autosave)
+    .alert("Autosave", isPresented: $hasAutosave) {
+      Button("OK") {
+        hasAutosave = false
+      }
+    } message: {
+      Text("All completed tasks/subtasks have been deleted")
+    }
   }
 
   private func addItem() {
@@ -86,6 +94,7 @@ struct ContentView: View {
     SaveController.save(items, toUrl: SaveController.filename(date: ymd))
     weekStart = now
     cleanup()
+    hasAutosave = true
   }
 
   private func cleanup() {