TaskView.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. Image(systemName: task.status.label)
  18. .frame(width: 20)
  19. .padding(.trailing, -10)
  20. Picker("", selection: $task.status) {
  21. ForEach(Status.allCases) { unit in
  22. Text(String(describing: unit))
  23. }
  24. }
  25. .fixedSize(horizontal: true, vertical: false)
  26. .onChange(of: task.status) {
  27. if task.status.isStrong {
  28. task.subtasks
  29. .filter({ !$0.status.isStrong })
  30. .forEach({ subtask in subtask.status = task.status })
  31. }
  32. }
  33. TextField("Task Name", text: $task.name)
  34. Button() {
  35. task.subtasks.append(SubTask(name: "Subtask"))
  36. } label: {
  37. Image(systemName: "plus")
  38. .help("Add a Subtask")
  39. }
  40. }
  41. if showTags || !(hideTags || task.tags.isEmpty) {
  42. HStack {
  43. TagBarView(tags: $task.tags)
  44. .font(.footnote)
  45. .padding(.leading, 30)
  46. ShowHideTapper(shown: $showTags, hideToggle: $hideTags)
  47. }
  48. }
  49. if showNotes || !(hideNotes || task.notes.isEmpty) {
  50. HStack {
  51. TextField("Notes", text: $task.notes)
  52. .font(.footnote)
  53. .padding(.leading, 30)
  54. ShowHideTapper(shown: $showNotes, hideToggle: $hideNotes)
  55. }
  56. }
  57. VStack {
  58. ForEach($task.subtasks) { subtask in
  59. HStack {
  60. Label("", systemImage: "chevron.right")
  61. SubTaskView(task: subtask)
  62. }
  63. }
  64. }
  65. }.onHover { yes in
  66. showTags = yes
  67. showNotes = yes
  68. }
  69. }
  70. }
  71. #Preview {
  72. @Previewable @State var task = Task(name: "New Task")
  73. TaskView(task: $task)
  74. .frame(minHeight: 100) // Preview does not resize window properly
  75. }