Explorar o código

feat: add SubTask and views
fix: remove scaledToFit calls as they cause issues in the real frame

Sam Jaffe hai 3 semanas
pai
achega
c582797409

+ 15 - 0
Todos/Model/Task.swift

@@ -17,12 +17,27 @@ enum Status : String, CaseIterable, Identifiable, Codable {
   
   var id: Self { self }
   var description: String { self.rawValue }
+  var isStrong: Bool {
+    self == .Complete || self == .Hiatus || self == .Waiting
+  }
+}
+
+@Model
+final class SubTask {
+  var name: String
+  var notes: String = ""
+  var status: Status = Status.Default
+  
+  init(name: String) {
+    self.name = name
+  }
 }
 
 @Model
 final class Task {
   var name: String
   var tags: [String] = []
+  var subtasks: [SubTask] = []
   var notes: String = ""
   var status: Status = Status.Default
   

+ 46 - 0
Todos/View/SubTaskView.swift

@@ -0,0 +1,46 @@
+//
+//  TaskView.swift
+//  Todos
+//
+//  Created by Sam Jaffe on 2/28/26.
+//
+
+import SwiftUI
+
+struct SubTaskView: View {
+  @Binding var task: SubTask
+  
+  @State private var showNotes: Bool = false
+  @State private var hideNotes: Bool = false
+
+  var body: some View {
+    VStack {
+      HStack {
+        Picker(""  /* TODO: Add Icons */, selection: $task.status) {
+          ForEach(Status.allCases) { unit in
+            Text(String(describing: unit))
+          }
+        }
+        TextField("Task Name", text: $task.name)
+      }
+            
+      if showNotes {
+        HStack {
+          TextField("Notes", text: $task.notes)
+            .font(.footnote)
+            .padding(.leading, 30)
+          ShowHideTapper(shown: $showNotes, hideToggle: $hideNotes)
+        }
+      }
+      
+    }.onHover { yes in
+      showNotes = yes || !(hideNotes || task.notes.isEmpty)
+    }
+  }
+}
+
+#Preview {
+  @Previewable @State var task = SubTask(name: "New Task")
+  SubTaskView(task: $task)
+      .frame(minHeight: 100) // Preview does not resize window properly
+}

+ 0 - 1
Todos/View/TagBarView.swift

@@ -23,7 +23,6 @@ struct TagBarView: View {
             .onSubmit {
               tags.removeAll(where: { $0.isEmpty })
             }
-            .scaledToFit()
         }
       }
     }

+ 24 - 1
Todos/View/TaskView.swift

@@ -22,8 +22,22 @@ struct TaskView: View {
           ForEach(Status.allCases) { unit in
             Text(String(describing: unit))
           }
-        }.scaledToFit()
+        }
+        .onChange(of: task.status) {
+          if task.status.isStrong {
+            task.subtasks
+              .filter({ $0.status.isStrong })
+              .forEach({ subtask in subtask.status = task.status })
+          }
+        }
+        
         TextField("Task Name", text: $task.name)
+        Button() {
+          task.subtasks.append(SubTask(name: "Subtask"))
+        } label: {
+          Image(systemName: "plus")
+            .help("Add a Subtask")
+        }
       }
       
       if showTags {
@@ -43,6 +57,15 @@ struct TaskView: View {
           ShowHideTapper(shown: $showNotes, hideToggle: $hideNotes)
         }
       }
+      
+      VStack {
+        ForEach($task.subtasks) { subtask in
+          HStack {
+            Label("", systemImage: "chevron.right")
+            SubTaskView(task: subtask)
+          }
+        }
+      }
     }.onHover { yes in
       showTags = yes || !(hideTags || task.tags.isEmpty)
       showNotes = yes || !(hideNotes || task.notes.isEmpty)