Files
honeyDueKMP/iosApp/iosApp/Subviews/Task/TasksSection.swift
Trey t 7dce211681 wip
2025-11-08 16:02:01 -06:00

149 lines
6.4 KiB
Swift

import SwiftUI
import ComposeApp
struct TasksSection: View {
let tasksResponse: TaskColumnsResponse
let onEditTask: (TaskDetail) -> Void
let onCancelTask: (Int32) -> Void
let onUncancelTask: (Int32) -> Void
let onMarkInProgress: (Int32) -> Void
let onCompleteTask: (TaskDetail) -> Void
let onArchiveTask: (Int32) -> Void
let onUnarchiveTask: (Int32) -> Void
private var hasNoTasks: Bool {
tasksResponse.columns.allSatisfy { $0.tasks.isEmpty }
}
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text("Tasks")
.font(.title2)
.fontWeight(.bold)
if hasNoTasks {
EmptyTasksView()
} else {
GeometryReader { geometry in
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 16) {
// Dynamically create columns from response
ForEach(Array(tasksResponse.columns.enumerated()), id: \.element.name) { index, column in
DynamicTaskColumnView(
column: column,
onEditTask: { task in
onEditTask(task)
},
onCancelTask: { taskId in
onCancelTask(taskId)
},
onUncancelTask: { taskId in
onUncancelTask(taskId)
},
onMarkInProgress: { taskId in
onMarkInProgress(taskId)
},
onCompleteTask: { task in
onCompleteTask(task)
},
onArchiveTask: { taskId in
onArchiveTask(taskId)
},
onUnarchiveTask: { taskId in
onUnarchiveTask(taskId)
}
)
.frame(width: geometry.size.width - 48)
}
}
.scrollTargetLayout()
.padding(.horizontal, 16)
}
.scrollTargetBehavior(.viewAligned)
}
.frame(height: 500)
}
}
}
}
#Preview {
TasksSection(
tasksResponse: TaskColumnsResponse(
columns: [
TaskColumn(
name: "upcoming_tasks",
displayName: "Upcoming",
buttonTypes: ["edit", "cancel", "uncancel", "mark_in_progress", "complete", "archive"],
icons: ["ios": "calendar", "android": "CalendarToday", "web": "calendar"],
color: "#007AFF",
tasks: [
TaskDetail(
id: 1,
residence: 1,
title: "Clean Gutters",
description: "Remove all debris",
category: TaskCategory(id: 1, name: "maintenance", description: ""),
priority: TaskPriority(id: 2, name: "medium", displayName: "Medium", description: ""),
frequency: TaskFrequency(id: 1, name: "monthly", lookupName: "", displayName: "Monthly", daySpan: 0, notifyDays: 0),
status: TaskStatus(id: 1, name: "pending", displayName: "Pending", description: ""),
dueDate: "2024-12-15",
estimatedCost: "150.00",
actualCost: nil,
notes: nil,
archived: false,
createdAt: "2024-01-01T00:00:00Z",
updatedAt: "2024-01-01T00:00:00Z",
nextScheduledDate: nil,
showCompletedButton: true,
completions: []
)
],
count: 1
),
TaskColumn(
name: "done_tasks",
displayName: "Done",
buttonTypes: ["edit", "archive"],
icons: ["ios": "checkmark.circle", "android": "CheckCircle", "web": "check-circle"],
color: "#34C759",
tasks: [
TaskDetail(
id: 2,
residence: 1,
title: "Fix Leaky Faucet",
description: "Kitchen sink fixed",
category: TaskCategory(id: 2, name: "plumbing", description: ""),
priority: TaskPriority(id: 3, name: "high", displayName: "High", description: ""),
frequency: TaskFrequency(id: 6, name: "once", lookupName: "", displayName: "One Time", daySpan: 0, notifyDays: 0),
status: TaskStatus(id: 3, name: "completed", displayName: "Completed", description: ""),
dueDate: "2024-11-01",
estimatedCost: "200.00",
actualCost: nil,
notes: nil,
archived: false,
createdAt: "2024-10-01T00:00:00Z",
updatedAt: "2024-11-05T00:00:00Z",
nextScheduledDate: nil,
showCompletedButton: false,
completions: []
)
],
count: 1
)
],
daysThreshold: 30,
residenceId: "1"
),
onEditTask: { _ in },
onCancelTask: { _ in },
onUncancelTask: { _ in },
onMarkInProgress: { _ in },
onCompleteTask: { _ in },
onArchiveTask: { _ in },
onUnarchiveTask: { _ in }
)
.padding()
}