Add search button and fix unset timeline beginning
This commit is contained in:
parent
19659de410
commit
70c42dd05a
6 changed files with 11 additions and 7 deletions
|
@ -42,7 +42,7 @@ proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.asyn
|
|||
}
|
||||
|
||||
let json = await fetchJson(base / searchUrl ? params, headers)
|
||||
if json == nil: return Result[T](query: query)
|
||||
if json == nil: return Result[T](query: query, beginning: true)
|
||||
|
||||
result = getResult[T](json, query, after)
|
||||
if not json.hasKey("items_html"): return
|
||||
|
|
|
@ -5,7 +5,7 @@ import ".."/[types, parser, parserutils, formatters, query]
|
|||
import utils, consts, media
|
||||
|
||||
proc finishTimeline*(json: JsonNode; query: Query; after, agent: string): Future[Timeline] {.async.} =
|
||||
if json == nil: return Timeline()
|
||||
if json == nil: return Timeline(beginning: true, query: query)
|
||||
|
||||
result = Timeline(
|
||||
hasMore: json["has_more_items"].to(bool),
|
||||
|
|
|
@ -14,6 +14,7 @@ proc createSearchRouter*(cfg: Config) =
|
|||
if @"text".len > 200:
|
||||
resp Http400, showError("Search input too long.", cfg.title)
|
||||
|
||||
let prefs = Prefs()
|
||||
let query = initQuery(params(request))
|
||||
|
||||
case query.kind
|
||||
|
@ -21,9 +22,9 @@ proc createSearchRouter*(cfg: Config) =
|
|||
if "," in @"text":
|
||||
redirect("/" & @"text")
|
||||
let users = await getSearch[Profile](query, @"after", getAgent())
|
||||
resp renderMain(renderUserSearch(users, Prefs()), Prefs(), path=getPath())
|
||||
resp renderMain(renderUserSearch(users, prefs), prefs, cfg.title, path=getPath())
|
||||
of custom:
|
||||
let tweets = await getSearch[Tweet](query, @"after", getAgent())
|
||||
resp renderMain(renderTweetSearch(tweets, Prefs(), getPath()), Prefs(), path=getPath())
|
||||
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), prefs, cfg.title, path=getPath())
|
||||
else:
|
||||
resp Http404, showError("Invalid search.", cfg.title)
|
||||
|
|
|
@ -14,6 +14,7 @@ proc renderNavbar*(title, path, rss: string): VNode =
|
|||
a(href="/"): img(class="site-logo", src="/logo.png")
|
||||
|
||||
tdiv(class="nav-item right"):
|
||||
icon "search", title="Search", href="/search"
|
||||
if rss.len > 0:
|
||||
icon "rss", title="RSS Feed", href=rss
|
||||
icon "info-circled", title="About", href="/about"
|
||||
|
|
|
@ -65,13 +65,14 @@ proc genCheckbox*(pref, label: string; state: bool): VNode =
|
|||
else: input(name=pref, `type`="checkbox")
|
||||
span(class="checkbox")
|
||||
|
||||
proc genInput*(pref, label, state, placeholder: string; class=""): VNode =
|
||||
proc genInput*(pref, label, state, placeholder: string; class=""; autofocus=false): VNode =
|
||||
let s = xmltree.escape(state)
|
||||
let p = xmltree.escape(placeholder)
|
||||
let a = if autofocus: "autofocus" else: ""
|
||||
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}\"/>"
|
||||
verbatim &"<input name={pref} type=\"text\" placeholder=\"{p}\" value=\"{s}\" {a}/>"
|
||||
|
||||
proc genSelect*(pref, label, state: string; options: seq[string]): VNode =
|
||||
buildHtml(tdiv(class="pref-group")):
|
||||
|
|
|
@ -60,7 +60,8 @@ proc renderSearchPanel*(query: Query): VNode =
|
|||
let action = if user.len > 0: &"/{user}/search" else: "/search"
|
||||
buildHtml(form(`method`="get", action=action, class="search-field")):
|
||||
hiddenField("kind", "custom")
|
||||
genInput("text", "", query.text, "Enter search...", class="pref-inline")
|
||||
genInput("text", "", query.text, "Enter search...",
|
||||
class="pref-inline", autofocus=true)
|
||||
button(`type`="submit"): icon "search"
|
||||
input(id="search-panel-toggle", `type`="checkbox")
|
||||
label(`for`="search-panel-toggle"):
|
||||
|
|
Loading…
Reference in a new issue