diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-01-18 15:24:58 -1000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-01-18 15:24:58 -1000 |
| commit | 8dbb6f43577b8a86e94ef7aaee196f9743356643 (patch) | |
| tree | 8713bf776f0c01c3d0fc94d906667e2e839e79f3 /internal/handlers/handlers.go | |
| parent | 143166ce759ce2cb0133b7438db36b844a9db1a7 (diff) | |
Implement unified task completion with cache sync (Phase 3 Step 7)
Add checkbox UI to Tasks tab for completing Todoist tasks and archiving
Trello cards. Fix cache synchronization so completed items stay gone
after page reload by deleting them from SQLite cache after API success.
- Add HandleCompleteAtom handler routing to Todoist/Trello APIs
- Add DeleteTask/DeleteCard store methods for cache removal
- Add htmx.process() calls after innerHTML updates in app.js
- Add comprehensive tests for completion and cache behavior
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/handlers/handlers.go')
| -rw-r--r-- | internal/handlers/handlers.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 9ba6351..b3bc8e4 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -672,3 +672,58 @@ func (h *Handler) HandleCompleteTask(w http.ResponseWriter, r *http.Request) { // Return empty response (task will be removed from DOM) w.WriteHeader(http.StatusOK) } + +// HandleCompleteAtom handles completion of a unified task (Atom) +func (h *Handler) HandleCompleteAtom(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + if err := r.ParseForm(); err != nil { + http.Error(w, "Failed to parse form", http.StatusBadRequest) + log.Printf("Error parsing form: %v", err) + return + } + + id := r.FormValue("id") + source := r.FormValue("source") + + if id == "" || source == "" { + http.Error(w, "Missing id or source", http.StatusBadRequest) + return + } + + var err error + switch source { + case "todoist": + err = h.todoistClient.CompleteTask(ctx, id) + case "trello": + // Archive the card (closed = true) + updates := map[string]interface{}{ + "closed": true, + } + err = h.trelloClient.UpdateCard(ctx, id, updates) + default: + http.Error(w, "Unknown source: "+source, http.StatusBadRequest) + return + } + + if err != nil { + http.Error(w, "Failed to complete task", http.StatusInternalServerError) + log.Printf("Error completing atom (source=%s, id=%s): %v", source, id, err) + return + } + + // Remove from local cache + switch source { + case "todoist": + if err := h.store.DeleteTask(id); err != nil { + log.Printf("Warning: failed to delete task from cache: %v", err) + } + case "trello": + if err := h.store.DeleteCard(id); err != nil { + log.Printf("Warning: failed to delete card from cache: %v", err) + } + } + + // Return 200 OK with empty body to remove the element from DOM + w.WriteHeader(http.StatusOK) +} |
