From 8dbb6f43577b8a86e94ef7aaee196f9743356643 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Sun, 18 Jan 2026 15:24:58 -1000 Subject: 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 --- internal/handlers/handlers.go | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'internal/handlers/handlers.go') 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) +} -- cgit v1.2.3