TaskView.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // TaskView.swift
  3. // Todos
  4. //
  5. // Created by Sam Jaffe on 2/28/26.
  6. //
  7. import SwiftUI
  8. struct TaskView: View {
  9. @Binding var task: Task
  10. @State private var showTags: Bool = false
  11. @State private var hideTags: Bool = false
  12. @State private var showNotes: Bool = false
  13. @State private var hideNotes: Bool = false
  14. var body: some View {
  15. VStack {
  16. HStack {
  17. Picker("" /* TODO: Add Icons */, selection: $task.status) {
  18. ForEach(Status.allCases) { unit in
  19. Text(String(describing: unit))
  20. }
  21. }
  22. .onChange(of: task.status) {
  23. if task.status.isStrong {
  24. task.subtasks
  25. .filter({ $0.status.isStrong })
  26. .forEach({ subtask in subtask.status = task.status })
  27. }
  28. }
  29. TextField("Task Name", text: $task.name)
  30. Button() {
  31. task.subtasks.append(SubTask(name: "Subtask"))
  32. } label: {
  33. Image(systemName: "plus")
  34. .help("Add a Subtask")
  35. }
  36. }
  37. if showTags {
  38. HStack {
  39. TagBarView(tags: $task.tags)
  40. .font(.footnote)
  41. .padding(.leading, 30)
  42. ShowHideTapper(shown: $showTags, hideToggle: $hideTags)
  43. }
  44. }
  45. if showNotes {
  46. HStack {
  47. TextField("Notes", text: $task.notes)
  48. .font(.footnote)
  49. .padding(.leading, 30)
  50. ShowHideTapper(shown: $showNotes, hideToggle: $hideNotes)
  51. }
  52. }
  53. VStack {
  54. ForEach($task.subtasks) { subtask in
  55. HStack {
  56. Label("", systemImage: "chevron.right")
  57. SubTaskView(task: subtask)
  58. }
  59. }
  60. }
  61. }.onHover { yes in
  62. showTags = yes || !(hideTags || task.tags.isEmpty)
  63. showNotes = yes || !(hideNotes || task.notes.isEmpty)
  64. }
  65. }
  66. }
  67. #Preview {
  68. @Previewable @State var task = Task(name: "New Task")
  69. TaskView(task: $task)
  70. .frame(minHeight: 100) // Preview does not resize window properly
  71. }