From 45dc131b2cb51fa7769c1aa8c92873cd7e3f2313 Mon Sep 17 00:00:00 2001 From: Yader Velasquez Date: Wed, 14 Feb 2024 12:11:50 -0600 Subject: [PATCH] Fix broken advanced search form after changes in lists. References: https://todo.code.netlandish.com/~netlandish/links/47 --- list/routes.go | 8 ++++++-- static/js/advancedsearch.js | 17 ++++++++++++----- templates/listing_list.html | 18 +++++++++--------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/list/routes.go b/list/routes.go index c486522..175392b 100644 --- a/list/routes.go +++ b/list/routes.go @@ -1034,14 +1034,17 @@ func (s *Service) ListingList(c echo.Context) error { op.Var("orgSlug", org.Slug) var tag, excludeTag string + queries := make(url.Values) if c.QueryParam("tag") != "" { tag = c.QueryParam("tag") op.Var("tag", tag) + queries.Add("tag", tag) } if c.QueryParam("exclude") != "" { excludeTag = c.QueryParam("exclude") op.Var("excludeTag", excludeTag) + queries.Add("exclude", excludeTag) } if c.QueryParam("next") != "" { @@ -1062,9 +1065,10 @@ func (s *Service) ListingList(c echo.Context) error { "org": org, "navFlag": "listing", "lists": result.Listings.Result, - "tagFilter": tag, - "excludeTagFilter": excludeTag, + "tagFilter": strings.Replace(tag, ",", ", ", -1), + "excludeTagFilter": strings.Replace(excludeTag, ",", ", ", -1), "advancedSearch": true, + "queries": queries, } if result.Listings.PageInfo.HasPrevPage { gmap["prevURL"] = links.GetPaginationParams("prev", tag, "", result.Listings.PageInfo.Cursor) diff --git a/static/js/advancedsearch.js b/static/js/advancedsearch.js index 226aa90..a5bac3f 100644 --- a/static/js/advancedsearch.js +++ b/static/js/advancedsearch.js @@ -73,7 +73,12 @@ form.addEventListener("submit", function(e) { e.preventDefault(); var tagValue = form.elements.tag.value; var excludeValue = form.elements.exclude.value; - var qValue = form.elements.q.value; + var qValue = ""; + var hasQ = false; + if (form.elements["q"] !== undefined) { + qValue = form.elements.q.value; + hasQ = true; + } var qURL = new URLSearchParams(); if (tagValue === "") { @@ -98,10 +103,12 @@ form.addEventListener("submit", function(e) { qURL.set("exclude", excludeValue); } - if (qValue === "") { - form.elements.q.disabled = true; - } else { - qURL.set("q", qValue); + if (hasQ) { + if (qValue === "") { + form.elements.q.disabled = true; + } else { + qURL.set("q", qValue); + } } url = this.getAttribute("action"); diff --git a/templates/listing_list.html b/templates/listing_list.html index 36222aa..4d97505 100644 --- a/templates/listing_list.html +++ b/templates/listing_list.html @@ -3,12 +3,10 @@

{{.org.Name}} {{.pd.Title}}

{{.pd.Data.add}} - -
- {{if .advancedSearch}} -

{{.pd.Data.advanced_search}}

-
-
+{{ if not .hideNav }}

{{.pd.Data.advanced_search}}

{{ end }} +{{if and (not .hideNav) (.advancedSearch)}} +
+
@@ -29,8 +27,10 @@
- - {{end}} +
+{{end}} + +
@@ -58,7 +58,7 @@ #{{.Name}} {{else}} #{{.Name}} + href="{{if $.queries}}?{{addQueryElement $.queries "tag" .Slug}}{{else}}?tag={{.Slug}}{{end}}">#{{.Name}} {{end}} {{end}} {{end}} -- 2.45.2