| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- //
- // ProjectPanelView.swift
- // Todos
- //
- // Created by Sam Jaffe on 2/28/26.
- //
- import SwiftUI
- import SwiftData
- struct ProjectPanelView: View {
- @AppStorage(UserDefaultsKeys.Category) var allGroups = CodableArray<Category>()
- @Bindable var item: Project
- @State private var empty = Category()
- var body: some View {
- let style = Date.FormatStyle(date: .numeric, time: .standard)
- HStack {
- Text(item.name)
- .font(.title)
- .padding(.leading, 10)
- Spacer()
- Button(action: addItem) {
- Image(systemName: "plus")
- }
- .help("New Task")
- .padding(.trailing, 10)
- }
- HStack {
- if !item.category.isEmpty {
- let grp = $allGroups.first(where: { $0.name.wrappedValue == item.category })
- ColorPicker("", selection: grp!.color).disabled(true)
- }
- Picker("", selection: $item.category) {
- Text(empty.name).tag("")
- ForEach(allGroups) { group in
- Text(group.name)
- }
- }
- Text("Created on \(item.timestamp, format: style)")
- }
- List {
- ForEach($item.tasks) { task in
- TaskView(task: task)
- }
- }
- }
-
- private func addItem() {
- withAnimation {
- let newTask = Task(name: "New Task")
- item.tasks.append(newTask)
- }
- }
- }
- #Preview {
- @Previewable @State var item = Project(timestamp: Date())
- ProjectPanelView(item: item)
- }
|