// // TaskView.swift // Todos // // Created by Sam Jaffe on 2/28/26. // import SwiftUI struct TaskView: View { @Binding var task: Task @State private var hideTags: Bool = false @State private var hideNotes: Bool = false @FocusState private var isFocused: Bool var body: some View { VStack { HStack { Image(systemName: task.status.label) .frame(width: 20) .padding(.trailing, -10) Picker("", selection: $task.status) { ForEach(Status.allCases) { unit in Text(String(describing: unit)) } } .fixedSize(horizontal: true, vertical: false) .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) .focused($isFocused) Button() { task.subtasks.append(SubTask(name: "Subtask")) } label: { Image(systemName: "plus") .help("Add a Subtask") } } if isFocused || !(hideTags || task.tags.isEmpty) { HStack { TagBarView(tags: $task.tags) .font(.footnote) .focused($isFocused) .padding(.leading, 30) VisibilityTapper(hideToggle: $hideTags) .focused($isFocused) } } if isFocused || !(hideNotes || task.notes.isEmpty) { HStack { TextField("Notes", text: $task.notes, axis: .vertical) .font(.footnote) .focused($isFocused) .padding(.leading, 30) VisibilityTapper(hideToggle: $hideNotes) .focused($isFocused) } } VStack { ForEach($task.subtasks) { subtask in SubTaskView(task: subtask) .padding(.leading, 5) } } } } } #Preview { @Previewable @State var task = Task(name: "New Task") TaskView(task: $task) .frame(minHeight: 100) // Preview does not resize window properly }