Search progress

This commit is contained in:
Zed
2019-09-17 21:01:44 +02:00
parent f707826241
commit 4c748b61a5
9 changed files with 227 additions and 47 deletions

View File

@@ -1,34 +1,9 @@
import tables, macros, strformat, strutils, xmltree
import tables, macros, strutils
import karax/[karaxdsl, vdom, vstyles]
import renderutils
import ../types, ../prefs_impl
proc genCheckbox(pref, label: string; state: bool): VNode =
buildHtml(tdiv(class="pref-group")):
label(class="checkbox-container"):
text label
if state: input(name=pref, `type`="checkbox", checked="")
else: input(name=pref, `type`="checkbox")
span(class="checkbox")
proc genSelect(pref, label, state: string; options: seq[string]): VNode =
buildHtml(tdiv(class="pref-group")):
label(`for`=pref): text label
select(name=pref):
for opt in options:
if opt == state:
option(value=opt, selected=""): text opt
else:
option(value=opt): text opt
proc genInput(pref, label, state, placeholder: string): VNode =
let s = xmltree.escape(state)
let p = xmltree.escape(placeholder)
buildHtml(tdiv(class="pref-group pref-input")):
label(`for`=pref): text label
verbatim &"<input name={pref} type=\"text\" placeholder=\"{p}\" value=\"{s}\"/>"
macro renderPrefs*(): untyped =
result = nnkCall.newTree(
ident("buildHtml"), ident("tdiv"), nnkStmtList.newTree())

View File

@@ -1,4 +1,4 @@
import strutils
import strutils, strformat, xmltree
import karax/[karaxdsl, vdom]
import ../types, ../utils
@@ -39,9 +39,12 @@ proc linkText*(text: string; class=""): VNode =
buildHtml():
a(href=url, class=class): text text
proc refererField*(path: string): VNode =
proc hiddenField*(name, value: string): VNode =
buildHtml():
verbatim "<input name=\"referer\" style=\"display: none\" value=\"$1\"/>" % path
verbatim "<input name=\"$1\" style=\"display: none\" value=\"$2\"/>" % [name, value]
proc refererField*(path: string): VNode =
hiddenField("referer", path)
proc iconReferer*(icon, action, path: string, title=""): VNode =
buildHtml(form(`method`="get", action=action, class="icon-button")):
@@ -54,3 +57,30 @@ proc buttonReferer*(action, text, path: string; class=""; `method`="post"): VNod
refererField path
button(`type`="submit"):
text text
proc genCheckbox*(pref, label: string; state: bool): VNode =
buildHtml(tdiv(class="pref-group")):
label(class="checkbox-container"):
text label
if state: input(name=pref, `type`="checkbox", checked="")
else: input(name=pref, `type`="checkbox")
span(class="checkbox")
proc genInput*(pref, label, state, placeholder: string; class=""): VNode =
let s = xmltree.escape(state)
let p = xmltree.escape(placeholder)
buildHtml(tdiv(class=("pref-group pref-input " & class))):
if label.len > 0:
label(`for`=pref): text label
verbatim &"<input name={pref} type=\"text\" placeholder=\"{p}\" value=\"{s}\"/>"
proc genSelect*(pref, label, state: string; options: seq[string]): VNode =
buildHtml(tdiv(class="pref-group")):
label(`for`=pref): text label
select(name=pref):
for opt in options:
if opt == state:
option(value=opt, selected=""): text opt
else:
option(value=opt): text opt

View File

@@ -1,4 +1,4 @@
import strutils, strformat
import strutils, strformat, unicode
import karax/[karaxdsl, vdom, vstyles]
import renderutils, timeline
@@ -6,13 +6,13 @@ import ".."/[types, formatters, query]
proc renderSearch*(): VNode =
buildHtml(tdiv(class="panel-container")):
tdiv(class="search-panel"):
tdiv(class="search-bar"):
form(`method`="get", action="/search"):
verbatim "<input name=\"kind\" style=\"display: none\" value=\"users\"/>"
hiddenField("kind", "users")
input(`type`="text", name="text", autofocus="", placeholder="Enter username...")
button(`type`="submit"): icon "search"
proc renderTweetSearch*(timeline: Timeline; prefs: Prefs; path: string): VNode =
proc renderTimelineSearch*(timeline: Timeline; prefs: Prefs; path: string): VNode =
let users =
if timeline.query.isSome: get(timeline.query).fromUser
else: @[]
@@ -24,6 +24,45 @@ proc renderTweetSearch*(timeline: Timeline; prefs: Prefs; path: string): VNode =
renderProfileTabs(timeline.query, users.join(","))
renderTimelineTweets(timeline, prefs, path)
proc renderTweetSearch*(tweets: Result[Tweet]; prefs: Prefs; path: string): VNode =
let query = if tweets.query.isSome: get(tweets.query) else: Query(kind: custom)
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header"):
form(`method`="get", action="/search", class="search-field"):
hiddenField("kind", "custom")
genInput("text", "", query.text, "Enter search...", class="pref-inline")
button(`type`="submit"): icon "search"
input(id="panel-toggle", `type`="checkbox")
label(`for`="panel-toggle", class="panel-label"):
icon "down"
tdiv(class="search-panel"):
tdiv:
span(class="search-title"): text "Include: "
genCheckbox("retweets", "Retweets", "nativeretweets" in query.includes)
genCheckbox("replies", "Replies", "replies" in query.includes)
for f in @["filter", "exclude"]:
tdiv:
span(class="search-title"): text capitalize(f) & ":"
for i in commonFilters:
let state =
if f == "filter": i in query.filters
else: i in query.excludes
genCheckbox(&"{f[0]}-{i}", capitalize(i), state)
input(id=(&"{f}-toggle"), `type`="checkbox")
label(`for`=(&"{f}-toggle"), class=(&"{f}-label")):
icon "down"
tdiv(class=(&"{f}-extras")):
for i in advancedFilters:
let state =
if f == "filter": i in query.filters
else: i in query.excludes
genCheckbox(&"{f[0]}-{i}", i, state)
renderSearchTabs(tweets.query)
renderTimelineTweets(tweets, prefs, path)
proc renderUserSearch*(users: Result[Profile]; prefs: Prefs): VNode =
let searchText =
if users.query.isSome: get(users.query).text
@@ -31,11 +70,13 @@ proc renderUserSearch*(users: Result[Profile]; prefs: Prefs): VNode =
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header"):
form(`method`="get", action="/search"):
verbatim "<input name=\"kind\" style=\"display: none\" value=\"users\"/>"
verbatim "<input type=\"text\" name=\"text\" value=\"$1\"/>" % searchText
form(`method`="get", action="/search", class="search-field"):
hiddenField("kind", "users")
genInput("text", "", searchText, "Enter username...", class="pref-inline")
button(`type`="submit"): icon "search"
input(id="panel-toggle", `type`="checkbox")
label(`for`="panel-toggle", class="panel-label"):
icon "down"
renderSearchTabs(users.query)
renderTimelineUsers(users, prefs)

View File

@@ -37,6 +37,9 @@ proc renderSearchTabs*(query: Option[Query]): VNode =
var q = if query.isSome: get(query) else: Query()
buildHtml(ul(class="tab")):
li(class=query.getTabClass("custom")):
q.kind = custom
a(href=genQueryUrl(q)): text "Tweets"
li(class=query.getTabClass("users")):
q.kind = users
a(href=genQueryUrl(q)): text "Users"