~netlandish/links

8d2e62f6687f5ca507bc9b18f97d06b50313a1bb — Yader Velasquez 9 months ago 77136fa
Fix bug in AddQueryElement func.
Avoid appending new query params to previous url.Values.

References: https://todo.code.netlandish.com/~netlandish/links/47
4 files changed, 13 insertions(+), 7 deletions(-)

M core/routes.go
M helpers.go
M list/routes.go
M short/routes.go
M core/routes.go => core/routes.go +2 -1
@@ 4,6 4,7 @@ import (
	"database/sql"
	"errors"
	"fmt"
	"html/template"
	"links"
	"links/analytics"
	"links/domain"


@@ 1443,7 1444,7 @@ func (s *Service) OrgLinksList(c echo.Context) error {
		"hasStarredFilter": hasStarredFilter,
		"hasAllFilter":     hasAllFilter,
		"currURL":          currURL,
		"queries":          queries,
		"queries":          template.URL(queries.Encode()),
	}

	if search != "" {

M helpers.go => helpers.go +8 -4
@@ 757,15 757,19 @@ func (t TagQuery) GetSubQuery(inputTag, inputExcludeTag *string) (string, []inte
	return subQ.ToSql()
}

func AddQueryElement(q url.Values, param, val string) template.URL {
	curVal := q.Get(param)
func AddQueryElement(q template.URL, param, val string) template.URL {
	query, err := url.ParseQuery(string(q))
	if err != nil {
		return ""
	}
	curVal := query.Get(param)
	if curVal == "" {
		curVal = val
	} else {
		curVal += fmt.Sprintf(",%s", val)
	}
	q.Set(param, curVal)
	return template.URL(q.Encode())
	query.Set(param, curVal)
	return template.URL(query.Encode())
}

// GetLinksDomain will simply return the config value for `links:links-service-domain`

M list/routes.go => list/routes.go +1 -1
@@ 1068,7 1068,7 @@ func (s *Service) ListingList(c echo.Context) error {
		"tagFilter":        strings.Replace(tag, ",", ", ", -1),
		"excludeTagFilter": strings.Replace(excludeTag, ",", ", ", -1),
		"advancedSearch":   true,
		"queries":          queries,
		"queries":          template.URL(queries.Encode()),
	}
	if result.Listings.PageInfo.HasPrevPage {
		gmap["prevURL"] = links.GetPaginationParams("prev", tag, "", result.Listings.PageInfo.Cursor)

M short/routes.go => short/routes.go +2 -1
@@ 3,6 3,7 @@ package short
import (
	"errors"
	"fmt"
	"html/template"
	"links"
	"links/analytics"
	"links/domain"


@@ 175,7 176,7 @@ func (s *Service) LinkShortList(c echo.Context) error {
		"tagFilter":        strings.Replace(tag, ",", ", ", -1),
		"excludeTagFilter": strings.Replace(excludeTag, ",", ", ", -1),
		"advancedSearch":   true,
		"queries":          queries,
		"queries":          template.URL(queries.Encode()),
	}

	if result.LinkShorts.PageInfo.HasPrevPage {