diff --git a/src/api/search.nim b/src/api/search.nim
index 7f4e02f..a9283c8 100644
--- a/src/api/search.nim
+++ b/src/api/search.nim
@@ -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
diff --git a/src/api/timeline.nim b/src/api/timeline.nim
index f54a68c..8687bdf 100644
--- a/src/api/timeline.nim
+++ b/src/api/timeline.nim
@@ -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),
diff --git a/src/routes/search.nim b/src/routes/search.nim
index 54d43a4..8e90184 100644
--- a/src/routes/search.nim
+++ b/src/routes/search.nim
@@ -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)
diff --git a/src/views/general.nim b/src/views/general.nim
index fbbd17e..058e64c 100644
--- a/src/views/general.nim
+++ b/src/views/general.nim
@@ -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"
diff --git a/src/views/renderutils.nim b/src/views/renderutils.nim
index 8298d6d..0273555 100644
--- a/src/views/renderutils.nim
+++ b/src/views/renderutils.nim
@@ -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 &""
+ verbatim &""
proc genSelect*(pref, label, state: string; options: seq[string]): VNode =
buildHtml(tdiv(class="pref-group")):
diff --git a/src/views/search.nim b/src/views/search.nim
index 18c9ed4..082db7e 100644
--- a/src/views/search.nim
+++ b/src/views/search.nim
@@ -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"):