This commit is contained in:
Trey t
2025-11-05 21:35:52 -06:00
parent a8083380aa
commit e272e45689
5 changed files with 129 additions and 108 deletions

View File

@@ -12,8 +12,8 @@ struct ResidenceDetailView: View {
@State private var showEditResidence = false
@State private var showEditTask = false
@State private var selectedTaskForEdit: TaskDetail?
@State private var showCompletedTasks = false
@State private var showCancelledTasks = false
@State private var showInProgressTasks = false
@State private var showDoneTasks = false
var body: some View {
ZStack {
@@ -38,8 +38,8 @@ struct ResidenceDetailView: View {
if let tasksResponse = tasksResponse {
TasksSection(
tasksResponse: tasksResponse,
showCompletedTasks: $showCompletedTasks,
showCancelledTasks: $showCancelledTasks,
showInProgressTasks: $showInProgressTasks,
showDoneTasks: $showDoneTasks,
onEditTask: { task in
selectedTaskForEdit = task
showEditTask = true
@@ -134,7 +134,7 @@ struct ResidenceDetailView: View {
tasksError = nil
let taskApi = TaskApi(client: ApiClient_iosKt.createHttpClient())
taskApi.getTasksByResidence(token: token, residenceId: residenceId) { result, error in
taskApi.getTasksByResidence(token: token, residenceId: residenceId, days: 30) { result, error in
if let successResult = result as? ApiResultSuccess<TasksByResidenceResponse> {
self.tasksResponse = successResult.data
self.isLoadingTasks = false

View File

@@ -3,8 +3,8 @@ import ComposeApp
struct TasksSection: View {
let tasksResponse: TasksByResidenceResponse
@Binding var showCompletedTasks: Bool
@Binding var showCancelledTasks: Bool
@Binding var showInProgressTasks: Bool
@Binding var showDoneTasks: Bool
let onEditTask: (TaskDetail) -> Void
let onCancelTask: (TaskDetail) -> Void
let onUncancelTask: (TaskDetail) -> Void
@@ -19,16 +19,17 @@ struct TasksSection: View {
Spacer()
HStack(spacing: 8) {
TaskPill(count: tasksResponse.summary.total, label: "Total", color: .blue)
TaskPill(count: tasksResponse.summary.pending, label: "Pending", color: .orange)
TaskPill(count: tasksResponse.summary.completed, label: "Done", color: .green)
TaskPill(count: Int32(tasksResponse.summary.upcoming), label: "Upcoming", color: .blue)
TaskPill(count: Int32(tasksResponse.summary.inProgress), label: "In Progress", color: .orange)
TaskPill(count: Int32(tasksResponse.summary.done), label: "Done", color: .green)
}
}
if tasksResponse.tasks.isEmpty && tasksResponse.completedTasks.isEmpty && tasksResponse.cancelledTasks.isEmpty {
if tasksResponse.upcomingTasks.isEmpty && tasksResponse.inProgressTasks.isEmpty && tasksResponse.doneTasks.isEmpty {
EmptyTasksView()
} else {
ForEach(tasksResponse.tasks, id: \.id) { task in
// Upcoming tasks
ForEach(tasksResponse.upcomingTasks, id: \.id) { task in
TaskCard(
task: task,
onEdit: { onEditTask(task) },
@@ -37,31 +38,32 @@ struct TasksSection: View {
)
}
if !tasksResponse.completedTasks.isEmpty {
// In Progress tasks section
if !tasksResponse.inProgressTasks.isEmpty {
VStack(alignment: .leading, spacing: 12) {
HStack {
Label("Completed Tasks (\(tasksResponse.completedTasks.count))", systemImage: "checkmark.circle")
Label("In Progress (\(tasksResponse.inProgressTasks.count))", systemImage: "play.circle")
.font(.headline)
.foregroundColor(.green)
.foregroundColor(.orange)
Spacer()
Image(systemName: showCompletedTasks ? "chevron.up" : "chevron.down")
Image(systemName: showInProgressTasks ? "chevron.up" : "chevron.down")
.foregroundColor(.secondary)
.font(.caption)
}
.padding(.top, 8)
.contentShape(Rectangle())
.onTapGesture {
showCompletedTasks.toggle()
showInProgressTasks.toggle()
}
if showCompletedTasks {
ForEach(tasksResponse.completedTasks, id: \.id) { task in
if showInProgressTasks {
ForEach(tasksResponse.inProgressTasks, id: \.id) { task in
TaskCard(
task: task,
onEdit: { onEditTask(task) },
onCancel: nil,
onCancel: { onCancelTask(task) },
onUncancel: nil
)
}
@@ -69,32 +71,33 @@ struct TasksSection: View {
}
}
if !tasksResponse.cancelledTasks.isEmpty {
// Done tasks section
if !tasksResponse.doneTasks.isEmpty {
VStack(alignment: .leading, spacing: 12) {
HStack {
Label("Cancelled Tasks (\(tasksResponse.cancelledTasks.count))", systemImage: "xmark.circle")
Label("Done (\(tasksResponse.doneTasks.count))", systemImage: "checkmark.circle")
.font(.headline)
.foregroundColor(.red)
.foregroundColor(.green)
Spacer()
Image(systemName: showCancelledTasks ? "chevron.up" : "chevron.down")
Image(systemName: showDoneTasks ? "chevron.up" : "chevron.down")
.foregroundColor(.secondary)
.font(.caption)
}
.padding(.top, 8)
.contentShape(Rectangle())
.onTapGesture {
showCancelledTasks.toggle()
showDoneTasks.toggle()
}
if showCancelledTasks {
ForEach(tasksResponse.cancelledTasks, id: \.id) { task in
if showDoneTasks {
ForEach(tasksResponse.doneTasks, id: \.id) { task in
TaskCard(
task: task,
onEdit: { onEditTask(task) },
onCancel: nil,
onUncancel: { onUncancelTask(task) }
onUncancel: nil
)
}
}
@@ -109,14 +112,13 @@ struct TasksSection: View {
TasksSection(
tasksResponse: TasksByResidenceResponse(
residenceId: "1",
summary: TaskSummary(
total: 3,
completed: 1,
pending: 2,
inProgress: 0,
overdue: 1
daysThreshold: 30,
summary: CategorizedTaskSummary(
upcoming: 3,
inProgress: 1,
done: 2
),
tasks: [
upcomingTasks: [
TaskDetail(
id: 1,
residence: 1,
@@ -137,7 +139,8 @@ struct TasksSection: View {
completions: []
)
],
completedTasks: [
inProgressTasks: [],
doneTasks: [
TaskDetail(
id: 2,
residence: 1,
@@ -157,11 +160,10 @@ struct TasksSection: View {
showCompletedButton: false,
completions: []
)
],
cancelledTasks: []
]
),
showCompletedTasks: .constant(true),
showCancelledTasks: .constant(true),
showInProgressTasks: .constant(true),
showDoneTasks: .constant(true),
onEditTask: { _ in },
onCancelTask: { _ in },
onUncancelTask: { _ in }