Pass BaseQuery as url.Values in patches.
This makes changing query parameters easier.

Signed-off-by: Franciszek Stachura <[email protected]>
---
 pkg/web/patches.go    |  6 +-----
 pkg/web/patches.templ |  5 +++--
 pkg/web/web.go        | 20 +++++++++-----------
 3 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/pkg/web/patches.go b/pkg/web/patches.go
index 3b3f840..fbc711c 100644
--- a/pkg/web/patches.go
+++ b/pkg/web/patches.go
@@ -126,10 +126,6 @@ func (h *webHandler) PatchList(w http.ResponseWriter, r 
*http.Request) {
                        qp[k] = v
                }
        }
-       bq := ""
-       if len(qp) > 0 {
-               bq = "?" + qp.Encode()
-       }
 
        states, err := q.ListStates()
        if err != nil {
@@ -162,7 +158,7 @@ func (h *webHandler) PatchList(w http.ResponseWriter, r 
*http.Request) {
                PerPage:     perPage,
                Total:       int(total),
                TotalPages:  totalPages,
-               BaseQuery:   bq,
+               BaseQuery:   qp,
                SeriesNames: seriesNames,
                TagAbbrevs:  tagAbbrevs,
                Bundles:     bundles,
diff --git a/pkg/web/patches.templ b/pkg/web/patches.templ
index 6c2515f..9b3d9cb 100644
--- a/pkg/web/patches.templ
+++ b/pkg/web/patches.templ
@@ -7,6 +7,7 @@ package web
 
 import (
        "fmt"
+       "net/url"
        "strings"
 
        "github.com/getpatchwork/patchwork/pkg/db"
@@ -22,7 +23,7 @@ type patchListData struct {
        PerPage     int
        Total       int
        TotalPages  int
-       BaseQuery   string
+       BaseQuery   url.Values
        SeriesNames map[int]string
        TagAbbrevs  []string
        Bundles     []db.Bundle
@@ -368,7 +369,7 @@ templ sortHeader(label string, field string, class string, 
d patchListData) {
        </th>
 }
 
-templ pagination(page int, totalPages int, baseQuery string) {
+templ pagination(page int, totalPages int, baseQuery url.Values) {
        <nav>
                if page > 1 {
                        <a href={ templ.SafeURL(pageURL(baseQuery, page-1)) 
}>&laquo; Prev</a>
diff --git a/pkg/web/web.go b/pkg/web/web.go
index 99c80cf..1b6aa82 100644
--- a/pkg/web/web.go
+++ b/pkg/web/web.go
@@ -164,19 +164,17 @@ func coverURL(linkname, msgid string) string {
 }
 
 func sortURL(d patchListData, newSort string) string {
-       return fmt.Sprintf("/project/%s/list?order=%s%s",
-               d.Project.Linkname, newSort, d.BaseQuery)
+       // TODO replace with Clone in go 1.27
+       bq, _ := url.ParseQuery(d.BaseQuery.Encode())
+       bq.Set("order", newSort)
+       return fmt.Sprintf("/project/%s/list?%s", d.Project.Linkname, 
bq.Encode())
 }
 
-func pageURL(baseQuery string, page int) string {
-       if strings.Contains(baseQuery, "page=") {
-               return baseQuery
-       }
-       sep := "&"
-       if baseQuery == "" {
-               sep = "?"
-       }
-       return fmt.Sprintf("%s%spage=%d", baseQuery, sep, page)
+func pageURL(baseQuery url.Values, page int) string {
+       // TODO replace with Clone in go 1.27
+       bq, _ := url.ParseQuery(baseQuery.Encode())
+       bq.Set("page", strconv.Itoa(page))
+       return "?" + bq.Encode()
 }
 
 func highlightDiff(diff string) string {
-- 
2.56.0

_______________________________________________
Patchwork mailing list
[email protected]
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to