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 ../[packages, style, context]
import ../components/tag
import ../components/[tag, search]
import ../lib
randomize()
@ -50,7 +50,7 @@ proc card*(pkg: NimPackage): VNode =
if pkg.isAlias:
tdiv:
text "alias for: "
span(onClick = setSearchUrl("name:" & pkg.alias),
span(onClick = setSearchInput("name:" & pkg.alias),
class = "link"):
text pkg.alias
else:
@ -58,7 +58,7 @@ proc card*(pkg: NimPackage): VNode =
tdiv(class = "flex flex-wrap text-xs md:text-md overflow-x-auto"):
for t in pkg.tags:
tdiv(
onClick = setSearchUrl("tag:" & t.replace(" ", "-")),
onClick = setSearchInput("tag:" & t.replace(" ", "-")),
class = "link"):
t.renderTag
@ -78,8 +78,6 @@ proc recentPackageVersionsList*(): VNode =
href = "/#/pkg/" & 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:
# text " (" & (getTime() - pkg.versions[0].time).inDays.jss & " days ago)"
proc randomPackage*(ctx: Context): VNode =
let pkgName = ctx.nimpkgs.packages.keys().toSeq().sample()

View file

@ -61,15 +61,6 @@ proc getSearchFromUri*(): kstring =
if k == "query":
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 =
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",

View file

@ -41,3 +41,24 @@ proc setSearchUrl*(searchQuery: kstring, sortMethod = smAlphabetical): proc() =
scrollIntoView(node)
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)()

View file

@ -24,7 +24,7 @@ proc scrollToAnchor(a: string): proc() =
proc letterlink(activeLinks: seq[char]): VNode = buildHtml:
tdiv(
class = "flex flex-wrap md:text-xl text-lg capitalize w-full justify-evenly gap-x-2 md:gap-x-auto"
class = "flex flex-wrap md:text-xl text-lg capitalize w-full justify-evenly gap-x-2 md:gap-x-auto"
):
for l in LowercaseLetters:
tdiv(class = "w-5"):