mirror of
https://github.com/daylinmorgan/nimpkgs.git
synced 2024-12-22 02:50:44 -06:00
Compare commits
3 commits
3509478921
...
e0fc3b6d83
Author | SHA1 | Date | |
---|---|---|---|
e0fc3b6d83 | |||
f8b3c959bd | |||
520b3b0461 |
11 changed files with 115 additions and 72 deletions
|
@ -2,7 +2,7 @@ import std/strutils
|
||||||
import karax/[karax, karaxdsl, vdom]
|
import karax/[karax, karaxdsl, vdom]
|
||||||
import components/[header, button, footer]
|
import components/[header, button, footer]
|
||||||
import pages/pages
|
import pages/pages
|
||||||
import context, utils
|
import context, lib
|
||||||
|
|
||||||
proc render(data: RouterData): VNode =
|
proc render(data: RouterData): VNode =
|
||||||
when defined(debug): console.log ctx
|
when defined(debug): console.log ctx
|
||||||
|
|
|
@ -3,8 +3,8 @@ 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 ../utils
|
import ../lib
|
||||||
|
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
|
@ -42,20 +42,23 @@ proc card*(pkg: NimPackage): VNode =
|
||||||
h2(class = (textStyle & "font-black md:text-2xl text-lg font-casual").kstring):
|
h2(class = (textStyle & "font-black md:text-2xl text-lg font-casual").kstring):
|
||||||
text pkg.name
|
text pkg.name
|
||||||
if not pkg.isAlias:
|
if not pkg.isAlias:
|
||||||
|
tdiv(class="flex flex-col md:items-end items-start"):
|
||||||
pkg.projectUrl
|
pkg.projectUrl
|
||||||
|
if not pkg.deleted:
|
||||||
|
span(class="md:text-sm text-xs text-nowrap text-ctp-subtextzero"):
|
||||||
|
text "last commit: " & pkg.lastCommitTime.format("MMM d, YYYY")
|
||||||
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:
|
||||||
span(class = "md:text-xl my-2"): text pkg.description
|
span(class = "md:text-xl my-2 "): text pkg.description
|
||||||
tdiv(class = "flex flex-col text-xs md:text-lg overflow-x-auto"):
|
tdiv(class = "flex flex-wrap text-xs md:text-md overflow-x-auto"):
|
||||||
tdiv(class = "flex flex-wrap"):
|
|
||||||
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
|
||||||
|
|
||||||
|
@ -75,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()
|
||||||
|
|
|
@ -3,8 +3,7 @@ import std/[strutils, uri]
|
||||||
import karax/[kbase, karax, karaxdsl, vdom, jstrutils]
|
import karax/[kbase, karax, karaxdsl, vdom, jstrutils]
|
||||||
|
|
||||||
import ../[packages, style, context]
|
import ../[packages, style, context]
|
||||||
# import ../components/package
|
import ../lib
|
||||||
import ../utils
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Query* = object
|
Query* = object
|
||||||
|
@ -55,16 +54,13 @@ proc searchPackages*(q: Query): seq[NimPackage] =
|
||||||
if q ~= pkg: pkg
|
if q ~= pkg: pkg
|
||||||
|
|
||||||
proc getSearchFromUri*(): kstring =
|
proc getSearchFromUri*(): kstring =
|
||||||
|
result = ""
|
||||||
var url = currentUri()
|
var url = currentUri()
|
||||||
if url.query == "": return ""
|
if url.query == "": return
|
||||||
for k, v in decodeQuery(url.query):
|
for k, v in decodeQuery(url.query):
|
||||||
if k == "query":
|
if k == "query":
|
||||||
return v.kstring
|
return v.kstring
|
||||||
|
|
||||||
proc getSearchInput*() =
|
|
||||||
let searchInput = getVNodeById("search").getInputText
|
|
||||||
setSearchUrl(searchInput)()
|
|
||||||
|
|
||||||
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",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import std/[uri, tables, random]
|
import std/[uri, tables, random]
|
||||||
import karax/[kbase, karaxdsl, vdom, jstrutils]
|
import karax/[kbase, karaxdsl, vdom, jstrutils]
|
||||||
|
|
||||||
import ../[packages, style, context, utils]
|
import ../[packages, style, context, lib]
|
||||||
|
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import std/[
|
||||||
asyncjs, jsconsole, jsfetch, sequtils, sugar, tables
|
asyncjs, jsconsole, jsfetch, sequtils, sugar, tables
|
||||||
]
|
]
|
||||||
import karax/[kbase, karax], jsony
|
import karax/[kbase, karax], jsony
|
||||||
import packages, utils
|
import packages, lib
|
||||||
|
|
||||||
export tables
|
export tables
|
||||||
|
|
||||||
|
|
64
src/lib.nim
Normal file
64
src/lib.nim
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import std/[strutils, uri]
|
||||||
|
import std/jsffi except `&`
|
||||||
|
import jsconsole
|
||||||
|
export jsconsole
|
||||||
|
|
||||||
|
import karax/[kbase, karax, vdom, kdom]
|
||||||
|
|
||||||
|
proc jss*[T](arg: T): kstring = ($arg).kstring
|
||||||
|
proc jss*(arg: kstring): kstring = arg
|
||||||
|
|
||||||
|
proc noProtocol*(s: kstring): kstring =
|
||||||
|
($s)
|
||||||
|
.replace("http://", "")
|
||||||
|
.replace("https://", "")
|
||||||
|
.jss
|
||||||
|
|
||||||
|
proc currentUri*(): Uri {.inline.} =
|
||||||
|
parseUri($window.location.href)
|
||||||
|
|
||||||
|
func replace*(c: kstring, sub: string, by = " "): kstring =
|
||||||
|
($c).replace(sub, by).jss
|
||||||
|
|
||||||
|
type
|
||||||
|
SortMethod* = enum
|
||||||
|
smAlphabetical = "smAlphabetical", smCommitAge = "commit", smVersionAge = "version"
|
||||||
|
|
||||||
|
proc setSearchUrl*(searchQuery: kstring, sortMethod = smAlphabetical): proc() =
|
||||||
|
proc() =
|
||||||
|
var
|
||||||
|
url = currentUri()
|
||||||
|
params: seq[(string, string)]
|
||||||
|
if searchQuery != "":
|
||||||
|
params.add ("query", $searchQuery)
|
||||||
|
if sortMethod != smAlphabetical:
|
||||||
|
params.add ("sort", $sortMethod)
|
||||||
|
url.anchor = "/search"
|
||||||
|
url = url ? params
|
||||||
|
window.history.pushState(js{}, "".jss, url.jss)
|
||||||
|
let d = getVNodeById("search")
|
||||||
|
let node = d.dom
|
||||||
|
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)()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import std/[
|
||||||
import karax/[kbase]
|
import karax/[kbase]
|
||||||
import jsony
|
import jsony
|
||||||
|
|
||||||
import ./utils
|
import ./lib
|
||||||
export algorithm, tables, times, asyncjs, sugar
|
export algorithm, tables, times, asyncjs, sugar
|
||||||
|
|
||||||
proc parseHook*(s: string, i: var int, v: var kstring) =
|
proc parseHook*(s: string, i: var int, v: var kstring) =
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import std/[algorithm, sequtils, tables, uri, strutils, times]
|
import std/[algorithm, sequtils, tables, uri, strutils, times]
|
||||||
import karax/[kbase, karaxdsl, vdom, jstrutils]
|
import karax/[kbase, karaxdsl, vdom, jstrutils]
|
||||||
|
|
||||||
import ../[context, packages, style, utils]
|
import ../[context, packages, style, lib]
|
||||||
|
|
||||||
type
|
type
|
||||||
Metrics = object
|
Metrics = object
|
||||||
|
|
|
@ -3,7 +3,7 @@ import karax/[kbase, karax, karaxdsl, kdom, vdom, jstrutils, ]
|
||||||
|
|
||||||
import ../[context, packages, style]
|
import ../[context, packages, style]
|
||||||
import ../components/[tag, package]
|
import ../components/[tag, package]
|
||||||
import ../utils
|
import ../lib
|
||||||
import notfound
|
import notfound
|
||||||
|
|
||||||
proc openLink(link: kstring): proc() =
|
proc openLink(link: kstring): proc() =
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import std/[algorithm, strutils, sequtils, dom]
|
import std/[algorithm, strutils, sequtils, dom, uri]
|
||||||
|
|
||||||
import karax/[kbase, karax, karaxdsl, vdom, jstrutils, kdom]
|
import karax/[kbase, karax, karaxdsl, vdom, jstrutils, kdom]
|
||||||
|
|
||||||
import ../[packages, context]
|
import ../[packages, context]
|
||||||
import ../components/[package, search]
|
import ../components/[package, search]
|
||||||
import ../utils
|
import ../lib
|
||||||
|
|
||||||
type
|
type
|
||||||
SortMethod = enum
|
# SortMethod = enum
|
||||||
smAlphabetical, smCommitAge, smVersionAge
|
# smAlphabetical, smCommitAge, smVersionAge
|
||||||
|
#
|
||||||
PageContext = object
|
PageContext = object
|
||||||
sortMethod: SortMethod = smAlphabetical
|
sortMethod: SortMethod = smAlphabetical
|
||||||
filteredPackages: seq[NimPackage]
|
filteredPackages: seq[NimPackage]
|
||||||
|
@ -52,15 +53,15 @@ proc alphabeticalPackageList(pkgs: seq[NimPackage]): VNode =
|
||||||
for pkg in packages:
|
for pkg in packages:
|
||||||
pkg.card
|
pkg.card
|
||||||
|
|
||||||
proc selectSortMethod() =
|
|
||||||
let v = getVNodeById("sort-select").getInputText
|
|
||||||
pgCtx.sortMethod = SortMethod(parseInt(v))
|
|
||||||
|
|
||||||
proc sortSelector(): VNode =
|
proc sortSelector(): VNode =
|
||||||
buildHtml(tdiv(class = "flex items-center")):
|
buildHtml(tdiv(class = "flex items-center")):
|
||||||
label(`for` = "sort-select"): text "sort:"
|
label(`for` = "sort-select"): text "sort:"
|
||||||
select(class = "bg-ctp-crust rounded p-3", name = "sort",
|
select(
|
||||||
`id` = "sort-select", onChange = selectSortMethod):
|
class = "bg-ctp-crust rounded p-3",
|
||||||
|
name = "sort",
|
||||||
|
`id` = "sort-select",
|
||||||
|
onChange = getSearchInput
|
||||||
|
):
|
||||||
for i, msg in ["alphabetical", "recent commit", "recent version"]:
|
for i, msg in ["alphabetical", "recent commit", "recent version"]:
|
||||||
if i == ord(pgCtx.sortMethod):
|
if i == ord(pgCtx.sortMethod):
|
||||||
option(value = ($i).cstring, selected = ""): text msg
|
option(value = ($i).cstring, selected = ""): text msg
|
||||||
|
@ -89,8 +90,22 @@ proc filteredPackagesDom(): VNode =
|
||||||
for pkg in pgCtx.filteredPackages:
|
for pkg in pgCtx.filteredPackages:
|
||||||
pkg.card
|
pkg.card
|
||||||
|
|
||||||
|
# TODO: combine with 'getSearchFromUri'
|
||||||
|
proc getSortMethodFromUri*(): SortMethod =
|
||||||
|
result = smAlphabetical
|
||||||
|
var url = currentUri()
|
||||||
|
for k, v in decodeQuery(url.query):
|
||||||
|
if k == "sort":
|
||||||
|
case v
|
||||||
|
of "commit":
|
||||||
|
result = smCommitAge
|
||||||
|
of "version":
|
||||||
|
result = smVersionAge
|
||||||
|
else: discard
|
||||||
|
|
||||||
proc update(pgCtx: var PageContext) =
|
proc update(pgCtx: var PageContext) =
|
||||||
pgCtx.filteredPackages = nimpkgsList()
|
pgCtx.filteredPackages = nimpkgsList()
|
||||||
|
pgCtx.sortMethod = getSortMethodFromUri()
|
||||||
pgCtx.search = getSearchFromUri()
|
pgCtx.search = getSearchFromUri()
|
||||||
pgCtx.filteredPackages = searchPackages(parseQuery(pgCtx.search))
|
pgCtx.filteredPackages = searchPackages(parseQuery(pgCtx.search))
|
||||||
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
import std/[strutils, uri]
|
|
||||||
import std/jsffi except `&`
|
|
||||||
import jsconsole
|
|
||||||
export jsconsole
|
|
||||||
|
|
||||||
import karax/[kbase, karax, vdom, kdom]
|
|
||||||
|
|
||||||
proc jss*[T](arg: T): kstring = ($arg).kstring
|
|
||||||
proc jss*(arg: kstring): kstring = arg
|
|
||||||
|
|
||||||
proc noProtocol*(s: kstring): kstring =
|
|
||||||
($s)
|
|
||||||
.replace("http://", "")
|
|
||||||
.replace("https://", "")
|
|
||||||
.jss
|
|
||||||
|
|
||||||
proc currentUri*(): Uri {.inline.} =
|
|
||||||
parseUri($window.location.href)
|
|
||||||
|
|
||||||
func replace*(c: kstring, sub: string, by = " "): kstring =
|
|
||||||
($c).replace(sub, by).jss
|
|
||||||
|
|
||||||
proc setSearchUrl*(searchQuery: kstring): proc() =
|
|
||||||
proc() =
|
|
||||||
var url = currentUri()
|
|
||||||
url.anchor = "/search"
|
|
||||||
url = url ? {"query": $searchQuery}
|
|
||||||
window.history.pushState(js{}, "".jss, url.jss)
|
|
||||||
let d = getVNodeById("search")
|
|
||||||
let node = d.dom
|
|
||||||
scrollIntoView(node)
|
|
||||||
redraw()
|
|
||||||
|
|
Loading…
Reference in a new issue