From 6fc54231668563a36123d8b54792d125d8b74f43 Mon Sep 17 00:00:00 2001 From: SpamNeko Date: Thu, 18 May 2017 00:03:11 +0100 Subject: [PATCH] Fix default sorting UI state (#598) --- router/templateFunctions.go | 39 +++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/router/templateFunctions.go b/router/templateFunctions.go index 1a1ff749..155c8b29 100644 --- a/router/templateFunctions.go +++ b/router/templateFunctions.go @@ -45,15 +45,22 @@ var FuncMap = template.FuncMap{ }, "genSearchWithOrdering": func(currentUrl url.URL, sortBy string) template.URL { values := currentUrl.Query() - order := false + order := false //Default is DESC + sort := "2" //Default is Date (Actually ID, but Date is the same thing) + if _, ok := values["order"]; ok { order, _ = strconv.ParseBool(values["order"][0]) - if values["sort"][0] == sortBy { - order = !order //Flip order by repeat-clicking - } else { - order = false //Default to descending when sorting by something new - } } + if _, ok := values["sort"]; ok { + sort = values["sort"][0] + } + + if sort == sortBy { + order = !order //Flip order by repeat-clicking + } else { + order = false //Default to descending when sorting by something new + } + values.Set("sort", sortBy) values.Set("order", strconv.FormatBool(order)) @@ -67,13 +74,21 @@ var FuncMap = template.FuncMap{ leftclass := "sortarrowdim" rightclass := "sortarrowdim" + order := false + sort := "2" + if _, ok := values["order"]; ok { - if values["sort"][0] == sortBy { - if values["order"][0] == "true" { - rightclass = "" - } else { - leftclass = "" - } + order, _ = strconv.ParseBool(values["order"][0]) + } + if _, ok := values["sort"]; ok { + sort = values["sort"][0] + } + + if sort == sortBy { + if order { + rightclass = "" + } else { + leftclass = "" } }