3 Коміти 225b79f071 ... 8cbf58c442

Автор SHA1 Опис Дата
  Sam Jaffe 8cbf58c442 refactor: improve names in ProjectPanel 2 тижнів тому
  Sam Jaffe 91dace4193 refactor: use anonymous function when propogating subtask updates 2 тижнів тому
  Sam Jaffe 77f4340966 refactor: pull out CategoryPicker and CategoryColorDisplay for brevity 2 тижнів тому

+ 25 - 0
Todos/View/Components/CategoryColorDisplay.swift

@@ -0,0 +1,25 @@
+//
+//  CategoryColorDisplay.swift
+//  Todos
+//
+//  Created by Sam Jaffe on 3/7/26.
+//
+
+import SwiftUI
+
+struct CategoryColorDisplay: View {
+  @AppStorage(UserDefaultsKeys.Category) var allGroups = CodableArray<Category>()
+
+  @Binding var category: String
+
+  var body: some View {
+    if let grp = $allGroups.first(where: { $0.name.wrappedValue == category }) {
+      ColorPicker("", selection: grp.color).disabled(true).scaledToFit()
+    }
+  }
+}
+
+#Preview {
+  @Previewable @State var category = ""
+  CategoryColorDisplay(category: $category)
+}

+ 29 - 0
Todos/View/Components/CategoryPicker.swift

@@ -0,0 +1,29 @@
+//
+//  CategoryPicker.swift
+//  Todos
+//
+//  Created by Sam Jaffe on 3/7/26.
+//
+
+import SwiftUI
+
+struct CategoryPicker: View {
+  @AppStorage(UserDefaultsKeys.Category) var allGroups = CodableArray<Category>()
+  @State private var empty = Category()
+
+  @Binding var category: String
+
+  var body: some View {
+    Picker("Category", selection: $category) {
+      Text(empty.name).tag("")
+      ForEach(allGroups) { group in
+        Text(group.name)
+      }
+    }
+  }
+}
+
+#Preview {
+  @Previewable @State var category = ""
+  CategoryPicker(category: $category)
+}

+ 13 - 21
Todos/View/ProjectPanelView.swift

@@ -10,31 +10,28 @@ import SwiftData
 
 struct ProjectPanelView: View {
   @Environment(\.modelContext) private var modelContext
-  @AppStorage(UserDefaultsKeys.Category) var allGroups = CodableArray<Category>()
 
   @Bindable var item: Project
-  @State private var empty = Category()
 
   @State private var showDialogue = false
-  @State private var move = false
+  @State private var moveGuestureEnabled = false
+
   @State private var taskFilter = ""
-  @State private var statuses = StatusList()
+  @State private var statusFilter = StatusList()
 
   var body: some View {
     HStack {
       TextField("Project Name", text: $item.name)
         .font(.title)
         .padding(.leading, 10)
-      if let grp = $allGroups.first(where: { $0.name.wrappedValue == item.category }) {
-        ColorPicker("", selection: grp.color).disabled(true).scaledToFit()
-      }
+      CategoryColorDisplay(category: $item.category)
       Spacer()
       Button(action: addItem) {
         Image(systemName: "plus")
       }
       .help("New Task")
       .padding(.trailing, 10)
-      if move {
+      if moveGuestureEnabled {
         Label("", systemImage: "arrow.up.arrow.down")
           .foregroundStyle(.red)
           .font(.title2)
@@ -46,11 +43,11 @@ struct ProjectPanelView: View {
           .font(.title2)
           .help("Only showing text matching '\(taskFilter)'")
       }
-      if !statuses.all {
+      if !statusFilter.all {
         Label("", systemImage: "exclamationmark.magnifyingglass")
           .foregroundStyle(.blue)
           .font(.title2)
-          .help(statuses.description)
+          .help(statusFilter.description)
       }
       Button {
         showDialogue = !showDialogue
@@ -64,23 +61,18 @@ struct ProjectPanelView: View {
         List {
           Label("Settings", systemImage: "gearshape")
             .font(.title)
-          Picker("Category", selection: $item.category) {
-            Text(empty.name).tag("")
-            ForEach(allGroups) { group in
-              Text(group.name)
-            }
-          }
+          CategoryPicker(category: $item.category)
           Label("Filters", systemImage: "magnifyingglass")
             .font(.title)
           HStack {
             Label("", systemImage: "arrow.up.arrow.down")
-            Toggle("Move Tasks", isOn: $move)
+            Toggle("Move Tasks", isOn: $moveGuestureEnabled)
           }
           HStack {
             Label("", systemImage: "text.magnifyingglass")
             TextField("Filter Tasks", text: $taskFilter)
           }
-          StatusChecklist(statuses: $statuses)
+          StatusChecklist(statuses: $statusFilter)
         }
       }
       Text("")
@@ -105,10 +97,10 @@ struct ProjectPanelView: View {
             }
         }
         .onMove(perform: { moveItem(task.wrappedValue, $0, $1) })
-        .moveDisabled(!move)
+        .moveDisabled(!moveGuestureEnabled)
       }
       .onMove(perform: { moveItem(item, $0, $1) })
-      .moveDisabled(!move)
+      .moveDisabled(!moveGuestureEnabled)
     }
   }
 
@@ -116,7 +108,7 @@ struct ProjectPanelView: View {
     return items.sorted(by: T.less).filter({
       let value = $0.wrappedValue
       return value.name.isEmpty ||
-        (statuses.test(value.status) &&
+        (statusFilter.test(value.status) &&
          (taskFilter.isEmpty || value.containsText(taskFilter)))
     })
   }

+ 4 - 13
Todos/View/TaskView.swift

@@ -10,13 +10,11 @@ import SwiftData
 
 struct TaskView: View {
   @Environment(\.modelContext) private var modelContext
-  @AppStorage(UserDefaultsKeys.Category) var allGroups = CodableArray<Category>()
   @Binding var task: Task
 
   @State private var showDialogue: Bool = false
   @State private var hideTags: Bool = false
   @State private var hideNotes: Bool = false
-  @State private var empty = Category()
   let unset: Priority? = nil
 
   @FocusState private var isFocused: Bool
@@ -37,16 +35,14 @@ struct TaskView: View {
             if task.status.isStrong {
               task.subtasks
                 .filter({ !$0.status.isStrong })
-                .forEach({ subtask in subtask.status = task.status })
+                .forEach({ $0.status = task.status })
             }
           }
 
         TextField("Task Name", text: $task.name)
           .focused($isFocused)
 
-        if let grp = $allGroups.first(where: { $0.name.wrappedValue == task.category }) {
-          ColorPicker("", selection: grp.color).disabled(true).scaledToFit()
-        }
+        CategoryColorDisplay(category: $task.category)
 
         Button(action: addItem) {
           Image(systemName: "plus")
@@ -62,13 +58,8 @@ struct TaskView: View {
         .buttonStyle(.borderless)
         .popover(isPresented: $showDialogue) {
           List {
-            Picker("Category", selection: $task.category) {
-              Text(empty.name).tag("")
-              ForEach(allGroups) { group in
-                Text(group.name)
-              }
-            }
-            .fixedSize(horizontal: true, vertical: false)
+            CategoryPicker(category: $task.category)
+              .fixedSize(horizontal: true, vertical: false)
 
             Picker("Priority", selection: $task.priority) {
               Text("").tag(unset)