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

@@ -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
}
}