From 2dfe0a48ea4af476f694831cdb71a384d8638700 Mon Sep 17 00:00:00 2001 From: Victor Broman Date: Sat, 7 Feb 2026 10:19:32 +0100 Subject: [PATCH] fix(pagination): update URL on pagination and search This commit addresses two issues with pagination and search: 1. **Pagination URL Update**: Added `hx-push-url` to pagination buttons in the customer, order, and invoice list templates. This ensures the browser URL and history are updated when navigating pages via HTMX. The query parameters for `status` and `search` are now conditionally included, preventing empty parameters (e.g., `&status=`) in the URL. 2. **Search URL Reset**: Updated the `CustomerList` handler to send the `HX-Push-Url` header when performing a search via HTMX. This ensures that when a search is executed (or cleared), the URL correctly reflects the new state (reseting the page to 1), fixing a mismatch where the URL could show page 4 while the content was reset to page 1. --- internal/handlers/customers.go | 8 ++++++++ templates/customers/list.html | 6 ++++-- templates/invoices/list.html | 6 ++++-- templates/orders/list.html | 6 ++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/internal/handlers/customers.go b/internal/handlers/customers.go index 15ccf50..98e890a 100644 --- a/internal/handlers/customers.go +++ b/internal/handlers/customers.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "net/http" "strconv" @@ -39,6 +40,13 @@ func (h *Handler) CustomerList(w http.ResponseWriter, r *http.Request) { // HTMX partial for search if r.Header.Get("HX-Request") == "true" && r.URL.Query().Get("partial") == "true" { + // Construct clean URL for history + u := fmt.Sprintf("/customers?page=%d", page) + if search != "" { + u += "&search=" + search + } + w.Header().Set("HX-Push-Url", u) + h.renderPartial(w, "customers/list.html", "customer-table", data) return } diff --git a/templates/customers/list.html b/templates/customers/list.html index 13268d1..d32403a 100644 --- a/templates/customers/list.html +++ b/templates/customers/list.html @@ -72,7 +72,8 @@