Sam Jaffe 3 недель назад
Родитель
Сommit
eca268dcf2
3 измененных файлов с 46 добавлено и 2 удалено
  1. 1 0
      Todos/Model/Task.swift
  2. 35 0
      Todos/View/TagBarView.swift
  3. 10 2
      Todos/View/TaskView.swift

+ 1 - 0
Todos/Model/Task.swift

@@ -22,6 +22,7 @@ enum Status : String, CaseIterable, Identifiable, Codable {
 @Model
 final class Task {
   var name: String
+  var tags: [String] = []
   var notes: String = ""
   var status: Status = Status.Default
   

+ 35 - 0
Todos/View/TagBarView.swift

@@ -0,0 +1,35 @@
+//
+//  TagBarView.swift
+//  Todos
+//
+//  Created by Sam Jaffe on 2/28/26.
+//
+
+import SwiftUI
+
+struct TagBarView: View {
+  @Binding var tags: [String]
+  @State private var active: String = ""
+
+    var body: some View {
+      HStack {
+        TextField("Tag", text: $active)
+          .onSubmit {
+            tags.append(active)
+            active = ""
+          }
+        ForEach($tags, id: \.self) { tag in
+          TextField("", text: tag)
+            .onSubmit {
+              tags.removeAll(where: { $0.isEmpty })
+            }
+            .scaledToFit()
+        }
+      }
+    }
+}
+
+#Preview {
+  @Previewable @State var tags = Array<String>()
+  TagBarView(tags: $tags)
+}

+ 10 - 2
Todos/View/TaskView.swift

@@ -9,8 +9,9 @@ import SwiftUI
 
 struct TaskView: View {
   @Binding var task: Task
-  @State var showNotes: Bool = false
-  
+  @State private var showTags: Bool = false
+  @State private var showNotes: Bool = false
+
   var body: some View {
     VStack {
       HStack {
@@ -21,12 +22,18 @@ struct TaskView: View {
         }.scaledToFit()
         TextField("Task Name", text: $task.name)
       }
+      if showTags {
+        TagBarView(tags: $task.tags)
+          .font(.footnote)
+          .padding(.leading, 30)
+      }
       if showNotes {
         TextField("Notes", text: $task.notes)
           .font(.footnote)
           .padding(.leading, 30)
       }
     }.onHover { yes in
+      showTags = yes || !task.tags.isEmpty
       showNotes = yes || !task.notes.isEmpty
     }
   }
@@ -35,4 +42,5 @@ struct TaskView: View {
 #Preview {
   @Previewable @State var task = Task(name: "New Task")
   TaskView(task: $task)
+      .frame(minHeight: 100) // Preview does not resize window properly
 }