From e0fc3b6d8337de4a60c1a5140b5a058fe74f9a4e Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Fri, 22 Nov 2024 16:18:11 -0600 Subject: [PATCH] maintain sort settings better --- src/components/package.nim | 8 +++----- src/components/search.nim | 9 --------- src/lib.nim | 21 +++++++++++++++++++++ src/pages/search.nim | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/components/package.nim b/src/components/package.nim index 121ca37..6cdb013 100644 --- a/src/components/package.nim +++ b/src/components/package.nim @@ -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() diff --git a/src/components/search.nim b/src/components/search.nim index 50ef017..7fbdd79 100644 --- a/src/components/search.nim +++ b/src/components/search.nim @@ -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", diff --git a/src/lib.nim b/src/lib.nim index bad6047..fb1c383 100644 --- a/src/lib.nim +++ b/src/lib.nim @@ -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)() + + + diff --git a/src/pages/search.nim b/src/pages/search.nim index df25f3c..e28922d 100644 --- a/src/pages/search.nim +++ b/src/pages/search.nim @@ -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"):