maintain sort settings better

This commit is contained in:
Daylin Morgan 2024-11-22 16:18:11 -06:00
parent f8b3c959bd
commit e0fc3b6d83
Signed by: daylin
GPG key ID: 950D13E9719334AD
4 changed files with 25 additions and 15 deletions

View file

@ -3,7 +3,7 @@ import std/[strutils, sequtils, uri, random]
import karax/[kbase, karax, karaxdsl, vdom, jstrutils, ] import karax/[kbase, karax, karaxdsl, vdom, jstrutils, ]
import ../[packages, style, context] import ../[packages, style, context]
import ../components/tag import ../components/[tag, search]
import ../lib import ../lib
randomize() randomize()
@ -50,7 +50,7 @@ proc card*(pkg: NimPackage): VNode =
if pkg.isAlias: if pkg.isAlias:
tdiv: tdiv:
text "alias for: " text "alias for: "
span(onClick = setSearchUrl("name:" & pkg.alias), span(onClick = setSearchInput("name:" & pkg.alias),
class = "link"): class = "link"):
text pkg.alias text pkg.alias
else: else:
@ -58,7 +58,7 @@ proc card*(pkg: NimPackage): VNode =
tdiv(class = "flex flex-wrap text-xs md:text-md overflow-x-auto"): tdiv(class = "flex flex-wrap text-xs md:text-md overflow-x-auto"):
for t in pkg.tags: for t in pkg.tags:
tdiv( tdiv(
onClick = setSearchUrl("tag:" & t.replace(" ", "-")), onClick = setSearchInput("tag:" & t.replace(" ", "-")),
class = "link"): class = "link"):
t.renderTag t.renderTag
@ -78,8 +78,6 @@ proc recentPackageVersionsList*(): VNode =
href = "/#/pkg/" & pkg.name): href = "/#/pkg/" & pkg.name):
span(class = textStyle & "group-hover:text-ctp-mauve font-bold font-mono-casual"): text pkg.name span(class = textStyle & "group-hover:text-ctp-mauve font-bold font-mono-casual"): text pkg.name
span(class = "group-hover:text-ctp-mauve"): text pkg.versions[0].tag span(class = "group-hover:text-ctp-mauve"): text pkg.versions[0].tag
# span:
# text " (" & (getTime() - pkg.versions[0].time).inDays.jss & " days ago)"
proc randomPackage*(ctx: Context): VNode = proc randomPackage*(ctx: Context): VNode =
let pkgName = ctx.nimpkgs.packages.keys().toSeq().sample() let pkgName = ctx.nimpkgs.packages.keys().toSeq().sample()

View file

@ -61,15 +61,6 @@ proc getSearchFromUri*(): kstring =
if k == "query": if k == "query":
return v.kstring return v.kstring
proc getSearchInput*() =
let searchInput = getVNodeById("search").getInputText
let sortNode = getVNodeById("sort-select")
let sortMethod = SortMethod(
if sortNode != nil: parseInt(sortNode.getInputText)
else: 0
)
setSearchUrl(searchInput, sortMethod)()
proc searchBar*(value = jss""): Vnode = proc searchBar*(value = jss""): Vnode =
buildHtml(tdiv(class = "flex flex-row my-2 grow")): buildHtml(tdiv(class = "flex flex-row my-2 grow")):
input(`type` = "text", class = "bg-ctp-crust md:mx-3 mx-1 p-2 grow".kstring & borderStyle, `id` = "search", input(`type` = "text", class = "bg-ctp-crust md:mx-3 mx-1 p-2 grow".kstring & borderStyle, `id` = "search",

View file

@ -41,3 +41,24 @@ proc setSearchUrl*(searchQuery: kstring, sortMethod = smAlphabetical): proc() =
scrollIntoView(node) scrollIntoView(node)
redraw() redraw()
proc getSearchInput*() =
let searchInput = getVNodeById("search").getInputText
let sortNode = getVNodeById("sort-select")
let sortMethod = SortMethod(
if sortNode != nil: parseInt($sortNode.getInputText)
else: 0
)
setSearchUrl(searchInput, sortMethod)()
proc setSearchInput*(q: kstring): proc() =
result = proc() =
let sortNode = getVNodeById("sort-select")
let sortMethod = SortMethod(
if sortNode != nil: parseInt($sortNode.getInputText)
else: 0
)
setSearchUrl(q, sortMethod)()