Update task completion to use local kanban state update

- Add updatedTask field to TaskCompletionResponse model from API
- Modify CompleteTaskView callback to pass back the updated task
- Add updateTaskInKanban() function to AllTasksView and ResidenceDetailView
- Move completed tasks to correct kanban column without additional API call
- Remove debug print statements from ResidenceDetailView

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-02 20:50:25 -06:00
parent 0ddd542080
commit 00e303c3be
9 changed files with 163 additions and 53 deletions

View File

@@ -49,9 +49,11 @@ struct AllTasksView: View {
}
}
.sheet(item: $selectedTaskForComplete) { task in
CompleteTaskView(task: task) {
CompleteTaskView(task: task) { updatedTask in
if let updatedTask = updatedTask {
updateTaskInKanban(updatedTask)
}
selectedTaskForComplete = nil
loadAllTasks()
}
}
.sheet(isPresented: $showingUpgradePrompt) {
@@ -271,6 +273,43 @@ struct AllTasksView: View {
}
}
private func updateTaskInKanban(_ updatedTask: TaskResponse) {
guard let currentResponse = tasksResponse else { return }
let targetColumn = updatedTask.kanbanColumn ?? "completed_tasks"
var newColumns: [TaskColumn] = []
for column in currentResponse.columns {
// Remove task from this column if it exists
var filteredTasks = column.tasks.filter { $0.id != updatedTask.id }
// Add task to target column
if column.name == targetColumn {
filteredTasks.append(updatedTask)
}
// Create new column with updated tasks and count
let newColumn = TaskColumn(
name: column.name,
displayName: column.displayName,
buttonTypes: column.buttonTypes,
icons: column.icons,
color: column.color,
tasks: filteredTasks,
count: Int32(filteredTasks.count)
)
newColumns.append(newColumn)
}
// Update the response
tasksResponse = TaskColumnsResponse(
columns: newColumns,
daysThreshold: currentResponse.daysThreshold,
residenceId: currentResponse.residenceId
)
}
private func loadAllTasks(forceRefresh: Bool = false) {
guard TokenStorage.shared.getToken() != nil else { return }