From 4f37a135197c17121d6f9051d7ded8d0c345c254 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 1 Mar 2026 21:10:05 -0500 Subject: [PATCH] feat(dashboard): add HTMX form data binding and redirect to RestoreSystemCollection Update RestoreSystemCollection handler to support form-encoded requests from HTMX: - Add 'form' struct tags to CollectionName and ResetType fields to enable binding from both JSON payloads and form submissions (required for HTMX compatibility) - Add conditional HTMX redirect handling that sets HX-Redirect header when the request originates from HTMX, directing users to /collections after successful restoration This change enables the system collection restore functionality to work seamlessly with HTMX-based modal forms, improving the user experience by providing proper navigation after the restore operation completes without requiring JavaScript redirect logic. --- internal/handlers/dashboard.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/handlers/dashboard.go b/internal/handlers/dashboard.go index 50838cf..895e321 100644 --- a/internal/handlers/dashboard.go +++ b/internal/handlers/dashboard.go @@ -111,8 +111,8 @@ func (h *DashboardHandler) RestoreSystemCollection(c echo.Context) error { userUUID := uuid.UUID(user.ID.Bytes) var req struct { - CollectionName string `json:"collection_name"` - ResetType string `json:"reset_type"` // "full" or "keep_books" + CollectionName string `form:"collection_name" json:"collection_name"` + ResetType string `form:"reset_type" json:"reset_type"` } if err := c.Bind(&req); err != nil { @@ -146,6 +146,11 @@ func (h *DashboardHandler) RestoreSystemCollection(c echo.Context) error { return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to restore system collection"}) } + // Add redirect header for HTMX requests + if c.Request().Header.Get("HX-Request") == "true" { + c.Response().Header().Set("HX-Redirect", "/collections") + } + return c.JSON(http.StatusOK, map[string]string{"message": "System collection restored to defaults"}) }