TaskView.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }.scaledToFit()
  22. TextField("Task Name", text: $task.name)
  23. }
  24. if showTags {
  25. HStack {
  26. TagBarView(tags: $task.tags)
  27. .font(.footnote)
  28. .padding(.leading, 30)
  29. ShowHideTapper(shown: $showTags, hideToggle: $hideTags)
  30. }
  31. }
  32. if showNotes {
  33. HStack {
  34. TextField("Notes", text: $task.notes)
  35. .font(.footnote)
  36. .padding(.leading, 30)
  37. ShowHideTapper(shown: $showNotes, hideToggle: $hideNotes)
  38. }
  39. }
  40. }.onHover { yes in
  41. showTags = yes || !(hideTags || task.tags.isEmpty)
  42. showNotes = yes || !(hideNotes || task.notes.isEmpty)
  43. }
  44. }
  45. }
  46. #Preview {
  47. @Previewable @State var task = Task(name: "New Task")
  48. TaskView(task: $task)
  49. .frame(minHeight: 100) // Preview does not resize window properly
  50. }