Преглед на файлове

feat: reset the status of all Tasks when running an autosave()

Sam Jaffe преди 3 седмици
родител
ревизия
6a5e66bb68
променени са 1 файла, в които са добавени 19 реда и са изтрити 0 реда
  1. 19 0
      Todos/View/ContentView.swift

+ 19 - 0
Todos/View/ContentView.swift

@@ -78,6 +78,7 @@ struct ContentView: View {
     let ymd = weekStart.formatted(.iso8601.year().month().day())
     save(to: URL.documentsDirectory.appending(path: "Todo \(ymd).yaml"))
     weekStart = now
+    cleanup()
   }
   
   private func save(to: URL) {
@@ -91,6 +92,24 @@ struct ContentView: View {
     }
   }
   
+  private func cleanup() {
+    for item in items {
+      item.tasks.removeAll(where: { $0.status == .Complete })
+      for task in item.tasks {
+        if task.status == .InProgress {
+          task.status = .Todo
+        }
+
+        task.subtasks.removeAll(where: { $0.status == .Complete })
+        for subtask in task.subtasks {
+          if subtask.status == .InProgress {
+            subtask.status = .Todo
+          }
+        }
+      }
+    }
+  }
+  
   private func deleteItem(item: Category) {
     withAnimation {
       modelContext.delete(item)