CategoryPanelView.swift 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // CategorySidebarView.swift
  3. // Todos
  4. //
  5. // Created by Sam Jaffe on 2/28/26.
  6. //
  7. import SwiftUI
  8. import SwiftData
  9. struct CategoryPanelView: View {
  10. @Bindable var item: Category
  11. var body: some View {
  12. let style = Date.FormatStyle(date: .numeric, time: .standard)
  13. HStack {
  14. Text(" ")
  15. Text(item.name).font(.title)
  16. Spacer()
  17. Button(action: addItem) {
  18. Image(systemName: "plus")
  19. }.help("New Task")
  20. Text(" ")
  21. }
  22. Text("Created on \(item.timestamp, format: style)")
  23. List {
  24. ForEach($item.tasks) { task in
  25. TaskView(task: task)
  26. }
  27. }
  28. }
  29. private func addItem() {
  30. withAnimation {
  31. let newTask = Task(name: "New Task")
  32. item.tasks.append(newTask)
  33. }
  34. }
  35. }
  36. #Preview {
  37. @Previewable @State var item = Category(timestamp: Date())
  38. CategoryPanelView(item: item)
  39. }