This commit is contained in:
Trey t
2025-11-07 12:57:25 -06:00
parent 1b777049a8
commit 4e14352cd1
11 changed files with 323 additions and 21 deletions

View File

@@ -60,6 +60,16 @@ struct ResidenceDetailView: View {
},
onCompleteTask: { task in
selectedTaskForComplete = task
},
onArchiveTask: { task in
taskViewModel.archiveTask(id: task.id) { _ in
loadResidenceTasks()
}
},
onUnarchiveTask: { task in
taskViewModel.unarchiveTask(id: task.id) { _ in
loadResidenceTasks()
}
}
)
.padding(.horizontal)

View File

@@ -8,6 +8,8 @@ struct TaskCard: View {
let onUncancel: (() -> Void)?
let onMarkInProgress: (() -> Void)?
let onComplete: (() -> Void)?
let onArchive: (() -> Void)?
let onUnarchive: (() -> Void)?
var body: some View {
VStack(alignment: .leading, spacing: 12) {
@@ -116,6 +118,28 @@ struct TaskCard: View {
.buttonStyle(.borderedProminent)
.tint(.blue)
}
if task.archived {
if let onUnarchive = onUnarchive {
Button(action: onUnarchive) {
Label("Unarchive", systemImage: "tray.and.arrow.up")
.font(.subheadline)
.frame(maxWidth: .infinity)
}
.buttonStyle(.bordered)
.tint(.blue)
}
} else {
if let onArchive = onArchive {
Button(action: onArchive) {
Label("Archive", systemImage: "archivebox")
.font(.subheadline)
.frame(maxWidth: .infinity)
}
.buttonStyle(.bordered)
.tint(.gray)
}
}
}
}
.padding(16)
@@ -162,7 +186,9 @@ struct TaskCard: View {
onCancel: {},
onUncancel: nil,
onMarkInProgress: {},
onComplete: {}
onComplete: {},
onArchive: {},
onUnarchive: {}
)
}
.padding()

View File

@@ -8,6 +8,8 @@ struct TasksSection: View {
let onUncancelTask: (TaskDetail) -> Void
let onMarkInProgress: (TaskDetail) -> Void
let onCompleteTask: (TaskDetail) -> Void
let onArchiveTask: (TaskDetail) -> Void
let onUnarchiveTask: (TaskDetail) -> Void
var body: some View {
VStack(alignment: .leading, spacing: 12) {
@@ -32,7 +34,9 @@ struct TasksSection: View {
onCancelTask: onCancelTask,
onUncancelTask: onUncancelTask,
onMarkInProgress: onMarkInProgress,
onCompleteTask: onCompleteTask
onCompleteTask: onCompleteTask,
onArchiveTask: onArchiveTask,
onUnarchiveTask: onUnarchiveTask
)
.frame(width: geometry.size.width - 48)
@@ -47,7 +51,9 @@ struct TasksSection: View {
onCancelTask: onCancelTask,
onUncancelTask: onUncancelTask,
onMarkInProgress: nil,
onCompleteTask: onCompleteTask
onCompleteTask: onCompleteTask,
onArchiveTask: onArchiveTask,
onUnarchiveTask: onUnarchiveTask
)
.frame(width: geometry.size.width - 48)
@@ -62,7 +68,9 @@ struct TasksSection: View {
onCancelTask: nil,
onUncancelTask: nil,
onMarkInProgress: nil,
onCompleteTask: nil
onCompleteTask: nil,
onArchiveTask: onArchiveTask,
onUnarchiveTask: onUnarchiveTask
)
.frame(width: geometry.size.width - 48)
@@ -77,7 +85,9 @@ struct TasksSection: View {
onCancelTask: nil,
onUncancelTask: nil,
onMarkInProgress: nil,
onCompleteTask: nil
onCompleteTask: nil,
onArchiveTask: nil,
onUnarchiveTask: onUnarchiveTask
)
.frame(width: geometry.size.width - 48)
}
@@ -100,7 +110,8 @@ struct TasksSection: View {
summary: CategorizedTaskSummary(
upcoming: 3,
inProgress: 1,
done: 2
done: 2,
archived: 0
),
upcomingTasks: [
TaskDetail(
@@ -154,6 +165,8 @@ struct TasksSection: View {
onUncancelTask: { _ in },
onMarkInProgress: { _ in },
onCompleteTask: { _ in }
, onArchiveTask: { _ in }
, onUnarchiveTask: { _ in }
)
.padding()
}

View File

@@ -113,7 +113,13 @@ struct AllTasksView: View {
},
onCompleteTask: { task in
selectedTaskForComplete = task
}
},
onArchiveTask: { task in
taskViewModel.archiveTask(id: task.id) { _ in
loadAllTasks()
}
},
onUnarchiveTask: nil
)
.frame(width: geometry.size.width - 48)
@@ -142,10 +148,16 @@ struct AllTasksView: View {
onMarkInProgress: nil,
onCompleteTask: { task in
selectedTaskForComplete = task
}
},
onArchiveTask: { task in
taskViewModel.archiveTask(id: task.id) { _ in
loadAllTasks()
}
},
onUnarchiveTask: nil
)
.frame(width: geometry.size.width - 48)
// Done Column
TaskColumnView(
title: "Done",
@@ -160,10 +172,16 @@ struct AllTasksView: View {
onCancelTask: nil,
onUncancelTask: nil,
onMarkInProgress: nil,
onCompleteTask: nil
onCompleteTask: nil,
onArchiveTask: { task in
taskViewModel.archiveTask(id: task.id) { _ in
loadAllTasks()
}
},
onUnarchiveTask: nil
)
.frame(width: geometry.size.width - 48)
// Archived Column
TaskColumnView(
title: "Archived",
@@ -178,7 +196,13 @@ struct AllTasksView: View {
onCancelTask: nil,
onUncancelTask: nil,
onMarkInProgress: nil,
onCompleteTask: nil
onCompleteTask: nil,
onArchiveTask: nil,
onUnarchiveTask: { task in
taskViewModel.unarchiveTask(id: task.id) { _ in
loadAllTasks()
}
}
)
.frame(width: geometry.size.width - 48)
}
@@ -269,7 +293,9 @@ struct TaskColumnView: View {
let onUncancelTask: ((TaskDetail) -> Void)?
let onMarkInProgress: ((TaskDetail) -> Void)?
let onCompleteTask: ((TaskDetail) -> Void)?
let onArchiveTask: ((TaskDetail) -> Void)?
let onUnarchiveTask: ((TaskDetail) -> Void)?
var body: some View {
VStack(spacing: 0) {
// Tasks List
@@ -316,7 +342,9 @@ struct TaskColumnView: View {
onCancel: onCancelTask != nil ? { onCancelTask?(task) } : nil,
onUncancel: onUncancelTask != nil ? { onUncancelTask?(task) } : nil,
onMarkInProgress: onMarkInProgress != nil ? { onMarkInProgress?(task) } : nil,
onComplete: onCompleteTask != nil ? { onCompleteTask?(task) } : nil
onComplete: onCompleteTask != nil ? { onCompleteTask?(task) } : nil,
onArchive: onArchiveTask != nil ? { onArchiveTask?(task) } : nil,
onUnarchive: onUnarchiveTask != nil ? { onUnarchiveTask?(task) } : nil
)
}
}

View File

@@ -12,6 +12,8 @@ class TaskViewModel: ObservableObject {
@Published var taskCancelled: Bool = false
@Published var taskUncancelled: Bool = false
@Published var taskMarkedInProgress: Bool = false
@Published var taskArchived: Bool = false
@Published var taskUnarchived: Bool = false
// MARK: - Private Properties
private let taskApi: TaskApi
@@ -168,6 +170,62 @@ class TaskViewModel: ObservableObject {
}
}
func archiveTask(id: Int32, completion: @escaping (Bool) -> Void) {
guard let token = tokenStorage.getToken() else {
errorMessage = "Not authenticated"
completion(false)
return
}
isLoading = true
errorMessage = nil
taskArchived = false
taskApi.archiveTask(token: token, id: id) { result, error in
if result is ApiResultSuccess<TaskCancelResponse> {
self.isLoading = false
self.taskArchived = true
completion(true)
} else if let errorResult = result as? ApiResultError {
self.errorMessage = errorResult.message
self.isLoading = false
completion(false)
} else if let error = error {
self.errorMessage = error.localizedDescription
self.isLoading = false
completion(false)
}
}
}
func unarchiveTask(id: Int32, completion: @escaping (Bool) -> Void) {
guard let token = tokenStorage.getToken() else {
errorMessage = "Not authenticated"
completion(false)
return
}
isLoading = true
errorMessage = nil
taskUnarchived = false
taskApi.unarchiveTask(token: token, id: id) { result, error in
if result is ApiResultSuccess<TaskCancelResponse> {
self.isLoading = false
self.taskUnarchived = true
completion(true)
} else if let errorResult = result as? ApiResultError {
self.errorMessage = errorResult.message
self.isLoading = false
completion(false)
} else if let error = error {
self.errorMessage = error.localizedDescription
self.isLoading = false
completion(false)
}
}
}
func completeTask(taskId: Int32, completion: @escaping (Bool) -> Void) {
guard let token = tokenStorage.getToken() else {
errorMessage = "Not authenticated"
@@ -215,6 +273,8 @@ class TaskViewModel: ObservableObject {
taskCancelled = false
taskUncancelled = false
taskMarkedInProgress = false
taskArchived = false
taskUnarchived = false
errorMessage = nil
}
}