From 2fb1ed729fbd61d70b38a11903fb35eabb2bdca1 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Tue, 13 Jan 2026 13:33:43 -1000 Subject: Fix tab state persistence with URL query parameters (Bug 002) - Extract tab query param in HandleDashboard, default to "tasks" - Wrap DashboardData with ActiveTab field for template access - Update index.html with conditional tab-button-active class - Add hx-push-url="?tab=..." to each tab button for URL persistence - Update content div to load active tab from server state - Update app.js to read currentTab from URL query parameters - Add comprehensive tab_state_test.go test suite - Tab selection now persists through page reloads - All tests passing Co-Authored-By: Claude Sonnet 4.5 --- internal/handlers/handlers.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'internal/handlers/handlers.go') diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index f31fc56..ed100fc 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -55,8 +55,14 @@ func New(store *store.Store, todoist api.TodoistAPI, trello api.TrelloAPI, obsid func (h *Handler) HandleDashboard(w http.ResponseWriter, r *http.Request) { ctx := r.Context() + // Extract tab query parameter for state persistence + tab := r.URL.Query().Get("tab") + if tab == "" { + tab = "tasks" + } + // Aggregate data from all sources - data, err := h.aggregateData(ctx, false) + dashboardData, err := h.aggregateData(ctx, false) if err != nil { http.Error(w, "Failed to load dashboard data", http.StatusInternalServerError) log.Printf("Error aggregating data: %v", err) @@ -69,6 +75,15 @@ func (h *Handler) HandleDashboard(w http.ResponseWriter, r *http.Request) { return } + // Wrap dashboard data with active tab for template + data := struct { + *models.DashboardData + ActiveTab string + }{ + DashboardData: dashboardData, + ActiveTab: tab, + } + if err := h.templates.ExecuteTemplate(w, "index.html", data); err != nil { http.Error(w, "Failed to render template", http.StatusInternalServerError) log.Printf("Error rendering template: %v", err) -- cgit v1.2.3