Parcourir la source

refactor: fix capitalization of status, add unknown status

Sam Jaffe il y a 2 semaines
Parent
commit
c198f3babf

+ 24 - 13
Todos/Model/Status.swift

@@ -8,27 +8,38 @@
 import Foundation
 
 enum Status: String, CaseIterable, Identifiable, Codable {
-  case Todo = " "
-  case Complete = "V"
-  case InProgress = "C"
-  case Hiatus = "H"
-  case Waiting = "R"
+  case todo = " "
+  case complete = "V"
+  case inProgress = "C"
+  case hiatus = "H"
+  case waiting = "O"
+  case unknown = "?"
 
   var id: Self { self }
 
-  var description: String { self.rawValue }
-
   var isStrong: Bool {
-    self == .Complete || self == .Hiatus || self == .Waiting
+    self == .complete || self == .hiatus || self == .waiting
+  }
+
+  var description: String {
+    switch self {
+    case .todo: return "Todo"
+    case .complete: return "Complete"
+    case .inProgress: return "In Progress"
+    case .hiatus: return "Hiatus"
+    case .waiting: return "Waiting"
+    case .unknown: return "Proposed"
+    }
   }
 
   var label: String {
     switch self {
-    case .Todo: return "square.and.pencil"
-    case .Complete: return "checkmark"
-    case .InProgress: return "ellipsis.circle"
-    case .Hiatus: return "clock.badge.questionmark"
-    case .Waiting: return "airplane.circle"
+    case .todo: return "square.and.pencil"
+    case .complete: return "checkmark"
+    case .inProgress: return "ellipsis.circle"
+    case .hiatus: return "clock.badge.questionmark"
+    case .waiting: return "airplane.circle"
+    case .unknown: return "questionmark.circle.dashed"
     }
   }
 }

+ 1 - 1
Todos/Model/SubTask.swift

@@ -14,7 +14,7 @@ final class SubTask: Codable, Ordered {
   var name: String
   var task: Task?
   var notes: String = ""
-  var status: Status = Status.Todo
+  var status: Status = Status.todo
 
   init(name: String, parent: Task? = nil) {
     self.name = name

+ 1 - 1
Todos/Model/Task.swift

@@ -22,7 +22,7 @@ final class Task: Codable, Ordered, Aggregate {
   @Relationship(deleteRule: .cascade, inverse: \SubTask.task)
   var subtasks: [SubTask] = []
   var notes: String = ""
-  var status: Status = Status.Todo
+  var status: Status = Status.todo
 
   init(name: String, parent: Project? = nil) {
     self.name = name

+ 6 - 6
Todos/View/ContentView.swift

@@ -91,15 +91,15 @@ struct ContentView: View {
 
   private func cleanup() {
     for item in items {
-      item.tasks.removeAll(where: { $0.status == .Complete })
+      item.tasks.removeAll(where: { $0.status == .complete })
       for task in item.tasks {
-        if task.status == .InProgress {
-          task.status = .Todo
+        if task.status == .inProgress {
+          task.status = .todo
         }
 
-        task.subtasks.removeAll(where: { $0.status == .Complete })
-        for subtask in task.subtasks where subtask.status == .InProgress {
-          subtask.status = .Todo
+        task.subtasks.removeAll(where: { $0.status == .complete })
+        for subtask in task.subtasks where subtask.status == .inProgress {
+          subtask.status = .todo
         }
       }
     }

+ 1 - 1
Todos/View/SubTaskView.swift

@@ -25,7 +25,7 @@ struct SubTaskView: View {
           .padding(.trailing, -10)
         Picker("", selection: $task.status) {
           ForEach(Status.allCases) { unit in
-            Text(String(describing: unit))
+            Text(unit.description).tag(unit)
           }
         }
         .fixedSize(horizontal: true, vertical: false)

+ 1 - 1
Todos/View/TaskView.swift

@@ -27,7 +27,7 @@ struct TaskView: View {
           .padding(.trailing, -10)
         Picker("", selection: $task.status) {
           ForEach(Status.allCases) { unit in
-            Text(String(describing: unit))
+            Text(unit.description).tag(unit)
           }
         }
         .fixedSize(horizontal: true, vertical: false)