Received: from mail.netlandish.com (mail.netlandish.com [174.136.98.166])
	by code.netlandish.com (Postfix) with ESMTP id 68EE5270
	for <~netlandish/links-dev@lists.code.netlandish.com>; Wed, 02 Apr 2025 00:53:40 +0000 (UTC)
Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.221.177; helo=mail-vk1-f177.google.com; envelope-from=peter@netlandish.com; receiver=<UNKNOWN> 
Authentication-Results: mail.netlandish.com;
	dkim=pass (1024-bit key; unprotected) header.d=netlandish.com header.i=@netlandish.com header.b=nnAxK3PP
Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177])
	by mail.netlandish.com (Postfix) with ESMTP id 6FD2C1D642E
	for <~netlandish/links-dev@lists.code.netlandish.com>; Wed, 02 Apr 2025 00:53:44 +0000 (UTC)
Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-51eb1823a8eso3239334e0c.3
        for <~netlandish/links-dev@lists.code.netlandish.com>; Tue, 01 Apr 2025 17:53:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=netlandish.com; s=google; t=1743555223; x=1744160023; darn=lists.code.netlandish.com;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=Dtrs/MRaRlkBkJX8raj3RsgvloQjFqOmoUZpLEIVAOc=;
        b=nnAxK3PPYKGxFw35cxCCQ1LYUtn9KRDcle7FDCI7sV+icHuejli0lDBv5VV8c6hakE
         NmyjdRKQwz85whUPttr5uRO9KKBHsc/fXFJpK5vZAnm5d3GRbWR7EFxLRpLhYvz+dCI+
         2f5mRFOhIkY8v1ZPR/zo8N/dzYnVQaB2ei2Kc=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1743555223; x=1744160023;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=Dtrs/MRaRlkBkJX8raj3RsgvloQjFqOmoUZpLEIVAOc=;
        b=GY11EGCGGXuVV7J9j3ElGwXYxDN47uvxxxaCcPOXa8+/Q+mnd+rYQ9QbC7yVrNvvrs
         GefhO6/2pfTmyU94bYFzYBqfzJAUi0zSX9WQ5Nw7iUK4V1xMDCEHORHugsykpFGO+UX2
         AYKc0+urUJ99DwigAze8EUZxgT6medMUFEcbTMqw04JNdfJSjPYEsuOnz++7ZHJEBqQM
         b8OSxxaWLp09IjG7ZwJCpcff1MXkqzcNXBSR5ZiX+n4SJfkgSVmUCTHG7UgG6HmAmK2Z
         40i29kRn1THi14cG8JPkX2zYKzZMFkJnaB/HCgLlxbztSR3+lEMsOb/7ZOf2bljoCEOA
         LnOA==
X-Gm-Message-State: AOJu0YzIJ9QMbE3gEbg1oSQS7ymbr/64bmF0QYnGZJflFe8ch2/u3Vab
	0PHtO9EYsORAxYSYnTMLPrA4qrcqDBdfpnZdy5ioeG9r/MN0zeOOeKmvSqdTVgu3ROTo/csOvo+
	jwEk=
X-Gm-Gg: ASbGncvaRlP9qKYNheyKLDb19D6K3uQHHstRV//EdiBm1Jtck0tyMztM+OO3a4gC6dz
	JgnxCd6azLhPoozq/hxcMG+TXmzoN4cINmw5U9A9W33ib67f2+W2P1VJqKmvzENJJcNrSKmyDuz
	45QqGNBVREbo8hPZg7P7yQ9fBCwWkC3bXVc2kPf8szTL+z/snoXhdQql4kr2XabTziAxZWv7x6f
	8xX+p75ImzlRC5MeTbHUQbqDu4rC45wIiAJ0hTl6i9IF6z8WRcdRrv0wxM1bJChrmIWfHKRLvyP
	Yq0P5UiqhXFgP1kqQKu42uFl8tGP70JB4koJ6F0r5lLjLw==
X-Google-Smtp-Source: AGHT+IH0NTfgzNfJnBX+yf+SlINkyWGNEABTsYFdxVt3I66YWpiy48CwI7euXRo/i96/UposQPgsNQ==
X-Received: by 2002:a05:6122:218f:b0:520:5a87:66fa with SMTP id 71dfb90a1353d-5261d38803emr11133666e0c.3.1743555223484;
        Tue, 01 Apr 2025 17:53:43 -0700 (PDT)
Received: from localhost ([2803:2d60:1118:5ee:dc8b:7d22:4ec1:8139])
        by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5260eab1dafsm2290784e0c.30.2025.04.01.17.53.40
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Tue, 01 Apr 2025 17:53:42 -0700 (PDT)
From: Peter Sanchez <peter@netlandish.com>
To: ~netlandish/links-dev@lists.code.netlandish.com
Cc: Peter Sanchez <peter@netlandish.com>
Subject: [PATCH links] Fixing missing query string options when paginating org links.
Date: Tue,  1 Apr 2025 18:53:31 -0600
Message-ID: <20250402005338.29933-1-peter@netlandish.com>
X-Mailer: git-send-email 2.47.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Fixes: https://todo.code.netlandish.com/~netlandish/links/104
Signed-off-by: Peter Sanchez <peter@netlandish.com>
---
 admin/routes.go   | 12 ++++++------
 billing/routes.go |  4 ++--
 core/routes.go    |  6 +++---
 helpers.go        | 29 ++++++++++++++++-------------
 list/routes.go    | 12 ++++++------
 short/routes.go   |  4 ++--
 6 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/admin/routes.go b/admin/routes.go
index 3184bb8..1e730b1 100644
--- a/admin/routes.go
+++ b/admin/routes.go
@@ -1165,11 +1165,11 @@ func (s *Service) DomainList(c echo.Context) error {
 		return err
 	}
 	if result.Organizations.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", "", query, result.Organizations.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Organizations.PageInfo.Cursor, "next")
 	}
 
 	if result.Organizations.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", "", query, result.Organizations.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Organizations.PageInfo.Cursor, "prev")
 	}
 	gmap["domains"] = result.Organizations.Result
 	return s.Render(c, http.StatusOK, "admin_domains_list.html", gmap)
@@ -1242,11 +1242,11 @@ func (s *Service) OrgList(c echo.Context) error {
 		return err
 	}
 	if result.Organizations.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", "", query, result.Organizations.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Organizations.PageInfo.Cursor, "next")
 	}
 
 	if result.Organizations.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", "", query, result.Organizations.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Organizations.PageInfo.Cursor, "prev")
 	}
 	gmap["orgs"] = result.Organizations.Result
 	return s.Render(c, http.StatusOK, "admin_organization_list.html", gmap)
@@ -1631,11 +1631,11 @@ func (s *Service) UserList(c echo.Context) error {
 		return err
 	}
 	if result.GetUsers.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", "", query, result.GetUsers.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.GetUsers.PageInfo.Cursor, "next")
 	}
 
 	if result.GetUsers.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", "", query, result.GetUsers.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.GetUsers.PageInfo.Cursor, "prev")
 	}
 	gmap["users"] = result.GetUsers.Result
 	return s.Render(c, http.StatusOK, "admin_user_list.html", gmap)
diff --git a/billing/routes.go b/billing/routes.go
index 9699849..5fd4e83 100644
--- a/billing/routes.go
+++ b/billing/routes.go
@@ -281,11 +281,11 @@ func (s *Service) SubscriptionHistory(c echo.Context) error {
 	}
 
 	if result.Payments.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", "", "", result.Payments.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Payments.PageInfo.Cursor, "next")
 	}
 
 	if result.Payments.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", "", "", result.Payments.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Payments.PageInfo.Cursor, "prev")
 	}
 	return s.Render(c, http.StatusOK, "billing_history.html", gmap)
 
diff --git a/core/routes.go b/core/routes.go
index 5d2995b..d6bdf55 100644
--- a/core/routes.go
+++ b/core/routes.go
@@ -2254,11 +2254,11 @@ func (s *Service) OrgLinksList(c echo.Context) error {
 	}
 
 	if result.OrgLinks.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", tag, search, result.OrgLinks.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.OrgLinks.PageInfo.Cursor, "next")
 	}
 
 	if result.OrgLinks.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", tag, search, result.OrgLinks.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.OrgLinks.PageInfo.Cursor, "prev")
 	}
 	if navFlag == "recent" {
 		gmap["title"] = lt.Translate("Recent Links")
@@ -3249,7 +3249,7 @@ func (s *Service) FollowToggle(c echo.Context) error {
 	orgSlug := c.Param("slug")
 	action := c.Param("action")
 	var q string
-	result := make(map[string]interface{})
+	result := make(map[string]any)
 	switch action {
 	case "follow":
 		q = `mutation Follow($orgSlug: String!) {
diff --git a/helpers.go b/helpers.go
index 9f86203..4e944c0 100644
--- a/helpers.go
+++ b/helpers.go
@@ -480,16 +480,19 @@ func ParsePendingBaseURLs(ctx context.Context, userAgent string) error {
 }
 
 // GetPaginationParams returns the params needed for cursor pagination
-func GetPaginationParams(pagination, tag, search, cursor string) template.URL {
-	queryParams := make(url.Values)
-	queryParams.Set(pagination, cursor)
-	if tag != "" {
-		queryParams.Set("tag", tag)
+func GetPaginationParams(c echo.Context, pagvar, cursor string, exclude ...string) template.URL {
+	q := make(url.Values)
+	oldq := c.QueryParams()
+	for k, val := range oldq {
+		if k == pagvar || slices.Contains(exclude, k) {
+			continue
+		}
+		for _, v := range val {
+			q.Add(k, v)
+		}
 	}
-	if search != "" {
-		queryParams.Set("q", search)
-	}
-	return template.URL(queryParams.Encode())
+	q.Set(pagvar, cursor)
+	return template.URL(q.Encode())
 }
 
 // Maps a list of domain by their levels (user, system, domain)
@@ -784,7 +787,7 @@ func NewTagQuery(t, c string) *TagQuery {
 	}
 }
 
-func (t TagQuery) GetSubQuery(inputTag, inputExcludeTag *string) (string, []interface{}, error) {
+func (t TagQuery) GetSubQuery(inputTag, inputExcludeTag *string) (string, []any, error) {
 	var tags = make([]string, 0)
 	if inputTag != nil && *inputTag != "" {
 		tag := strings.Replace(*inputTag, " ", "", -1)
@@ -942,7 +945,7 @@ func IsRegistrationEnabled(c echo.Context) bool {
 
 // Render is just a helper to always include base.html in our template
 // renderings.
-func Render(c echo.Context, code int, name string, data interface{}) error {
+func Render(c echo.Context, code int, name string, data any) error {
 	gctx := c.(*server.Context)
 	tmpl, err := gctx.NewTemplate(
 		TemplateFS,
@@ -1338,11 +1341,11 @@ func FetchAuditLogs(c echo.Context, userID int,
 		"listId":  listID,
 	}
 	if result.AuditLogs.PageInfo.HasPrevPage {
-		gmap["prevURL"] = GetPaginationParams("prev", "", "", result.AuditLogs.PageInfo.Cursor)
+		gmap["prevURL"] = GetPaginationParams(c, "prev", result.AuditLogs.PageInfo.Cursor, "next")
 	}
 
 	if result.AuditLogs.PageInfo.HasNextPage {
-		gmap["nextURL"] = GetPaginationParams("next", "", "", result.AuditLogs.PageInfo.Cursor)
+		gmap["nextURL"] = GetPaginationParams(c, "next", result.AuditLogs.PageInfo.Cursor, "prev")
 	}
 
 	return gmap, nil
diff --git a/list/routes.go b/list/routes.go
index 09af3f9..1271fbf 100644
--- a/list/routes.go
+++ b/list/routes.go
@@ -591,11 +591,11 @@ func (s *Service) ListingLinksManage(c echo.Context) error {
 		"org":          org,
 	}
 	if result.Listing.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", "", "", result.Listing.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Listing.PageInfo.Cursor, "next")
 	}
 
 	if result.Listing.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", "", "", result.Listing.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Listing.PageInfo.Cursor, "prev")
 	}
 	return s.Render(c, http.StatusOK, "listing_link_list.html", gmap)
 }
@@ -1118,11 +1118,11 @@ func (s *Service) ListingList(c echo.Context) error {
 		"autoCompleteOrgID": org.ID,
 	}
 	if result.Listings.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", tag, "", result.Listings.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Listings.PageInfo.Cursor, "next")
 	}
 
 	if result.Listings.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", tag, "", result.Listings.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Listings.PageInfo.Cursor, "prev")
 	}
 	return s.Render(c, http.StatusOK, "listing_list.html", gmap)
 }
@@ -1621,11 +1621,11 @@ func (r *DetailService) ListDetail(c echo.Context) error {
 		"query":        template.URL(query.Encode()),
 	}
 	if result.Listing.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", "", "", result.Listing.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Listing.PageInfo.Cursor, "next")
 	}
 
 	if result.Listing.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", "", "", result.Listing.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Listing.PageInfo.Cursor, "prev")
 	}
 	srv := gctx.Server
 	req := c.Request()
diff --git a/short/routes.go b/short/routes.go
index 5fce7cd..96d1106 100644
--- a/short/routes.go
+++ b/short/routes.go
@@ -180,11 +180,11 @@ func (s *Service) LinkShortList(c echo.Context) error {
 	}
 
 	if result.LinkShorts.PageInfo.HasPrevPage {
-		gmap["prevURL"] = links.GetPaginationParams("prev", tag, "", result.LinkShorts.PageInfo.Cursor)
+		gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.LinkShorts.PageInfo.Cursor, "next")
 	}
 
 	if result.LinkShorts.PageInfo.HasNextPage {
-		gmap["nextURL"] = links.GetPaginationParams("next", tag, "", result.LinkShorts.PageInfo.Cursor)
+		gmap["nextURL"] = links.GetPaginationParams(c, "next", result.LinkShorts.PageInfo.Cursor, "prev")
 	}
 	return s.Render(c, http.StatusOK, "link_short_list.html", gmap)
 }
-- 
2.47.2

