mirror of
https://github.com/zedeus/nitter.git
synced 2024-11-05 00:10:09 +00:00
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)
|
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)
|
result = getResult[T](json, query, after)
|
||||||
if not json.hasKey("items_html"): return
|
if not json.hasKey("items_html"): return
|
||||||
|
|
|
@ -5,7 +5,7 @@ import ".."/[types, parser, parserutils, formatters, query]
|
||||||
import utils, consts, media
|
import utils, consts, media
|
||||||
|
|
||||||
proc finishTimeline*(json: JsonNode; query: Query; after, agent: string): Future[Timeline] {.async.} =
|
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(
|
result = Timeline(
|
||||||
hasMore: json["has_more_items"].to(bool),
|
hasMore: json["has_more_items"].to(bool),
|
||||||
|
|
|
@ -14,6 +14,7 @@ proc createSearchRouter*(cfg: Config) =
|
||||||
if @"text".len > 200:
|
if @"text".len > 200:
|
||||||
resp Http400, showError("Search input too long.", cfg.title)
|
resp Http400, showError("Search input too long.", cfg.title)
|
||||||
|
|
||||||
|
let prefs = Prefs()
|
||||||
let query = initQuery(params(request))
|
let query = initQuery(params(request))
|
||||||
|
|
||||||
case query.kind
|
case query.kind
|
||||||
|
@ -21,9 +22,9 @@ proc createSearchRouter*(cfg: Config) =
|
||||||
if "," in @"text":
|
if "," in @"text":
|
||||||
redirect("/" & @"text")
|
redirect("/" & @"text")
|
||||||
let users = await getSearch[Profile](query, @"after", getAgent())
|
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:
|
of custom:
|
||||||
let tweets = await getSearch[Tweet](query, @"after", getAgent())
|
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:
|
else:
|
||||||
resp Http404, showError("Invalid search.", cfg.title)
|
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")
|
a(href="/"): img(class="site-logo", src="/logo.png")
|
||||||
|
|
||||||
tdiv(class="nav-item right"):
|
tdiv(class="nav-item right"):
|
||||||
|
icon "search", title="Search", href="/search"
|
||||||
if rss.len > 0:
|
if rss.len > 0:
|
||||||
icon "rss", title="RSS Feed", href=rss
|
icon "rss", title="RSS Feed", href=rss
|
||||||
icon "info-circled", title="About", href="/about"
|
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")
|
else: input(name=pref, `type`="checkbox")
|
||||||
span(class="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 s = xmltree.escape(state)
|
||||||
let p = xmltree.escape(placeholder)
|
let p = xmltree.escape(placeholder)
|
||||||
|
let a = if autofocus: "autofocus" else: ""
|
||||||
buildHtml(tdiv(class=("pref-group pref-input " & class))):
|
buildHtml(tdiv(class=("pref-group pref-input " & class))):
|
||||||
if label.len > 0:
|
if label.len > 0:
|
||||||
label(`for`=pref): text label
|
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 =
|
proc genSelect*(pref, label, state: string; options: seq[string]): VNode =
|
||||||
buildHtml(tdiv(class="pref-group")):
|
buildHtml(tdiv(class="pref-group")):
|
||||||
|
|
|
@ -60,7 +60,8 @@ proc renderSearchPanel*(query: Query): VNode =
|
||||||
let action = if user.len > 0: &"/{user}/search" else: "/search"
|
let action = if user.len > 0: &"/{user}/search" else: "/search"
|
||||||
buildHtml(form(`method`="get", action=action, class="search-field")):
|
buildHtml(form(`method`="get", action=action, class="search-field")):
|
||||||
hiddenField("kind", "custom")
|
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"
|
button(`type`="submit"): icon "search"
|
||||||
input(id="search-panel-toggle", `type`="checkbox")
|
input(id="search-panel-toggle", `type`="checkbox")
|
||||||
label(`for`="search-panel-toggle"):
|
label(`for`="search-panel-toggle"):
|
||||||
|
|
Loading…
Reference in a new issue