Use "tweets" instead of "custom" for search query

This commit is contained in:
Zed 2019-10-08 13:54:20 +02:00
parent 1c9c6a2947
commit e090dde1ea
6 changed files with 18 additions and 19 deletions

View File

@ -24,7 +24,7 @@ template `@`(param: string): untyped =
proc initQuery*(pms: Table[string, string]; name=""): Query =
result = Query(
kind: parseEnum[QueryKind](@"f", custom),
kind: parseEnum[QueryKind](@"f", tweets),
text: @"q",
filters: validFilters.filterIt("f-" & it in pms),
excludes: validFilters.filterIt("e-" & it in pms),
@ -84,7 +84,7 @@ proc genQueryParam*(query: Query): string =
result &= " " & query.text
proc genQueryUrl*(query: Query): string =
if query.kind notin {custom, users}: return
if query.kind notin {tweets, users}: return
var params = @[&"f={query.kind}"]
if query.text.len > 0:

View File

@ -25,7 +25,7 @@ proc createRssRouter*(cfg: Config) =
resp Http400, showError("Search input too long.", cfg.title)
let query = initQuery(params(request))
if query.kind != custom:
if query.kind != tweets:
resp Http400, showError("Only Tweet searches are allowed for RSS feeds.", cfg.title)
let tweets = await getSearch[Tweet](query, "", getAgent())

View File

@ -23,7 +23,7 @@ proc createSearchRouter*(cfg: Config) =
redirect("/" & @"q")
let users = await getSearch[Profile](query, @"after", getAgent())
resp renderMain(renderUserSearch(users, prefs), request, cfg.title)
of custom:
of tweets:
let tweets = await getSearch[Tweet](query, @"after", getAgent())
let rss = "/search/rss?" & genQueryUrl(query)
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request,

View File

@ -57,7 +57,7 @@ dbFromTypes("cache.db", "", "", "", [Profile, Video])
type
QueryKind* = enum
posts, replies, media, users, custom, userList
posts, replies, media, users, tweets, userList
Query* = object
kind*: QueryKind

View File

@ -23,7 +23,6 @@ proc renderNavbar*(title, rss: string; req: Request): VNode =
icon "search", title="Search", href="/search"
if rss.len > 0:
icon "rss-feed", title="RSS Feed", href=rss
if "/search" notin path:
icon "bird", title="Open in Twitter", href=twitPath
icon "info-circled", title="About", href="/about"
iconReferer "cog", "/settings", path, title="Preferences"

View File

@ -36,14 +36,14 @@ proc renderProfileTabs*(query: Query; username: string): VNode =
a(href=(link & "/with_replies")): text "Tweets & Replies"
li(class=query.getTabClass(media)):
a(href=(link & "/media")): text "Media"
li(class=query.getTabClass(custom)):
li(class=query.getTabClass(tweets)):
a(href=(link & "/search")): text "Search"
proc renderSearchTabs*(query: Query): VNode =
var q = query
buildHtml(ul(class="tab")):
li(class=query.getTabClass(custom)):
q.kind = custom
li(class=query.getTabClass(tweets)):
q.kind = tweets
a(href=("?" & genQueryUrl(q))): text "Tweets"
li(class=query.getTabClass(users)):
q.kind = users
@ -57,7 +57,7 @@ proc renderSearchPanel*(query: Query): VNode =
let user = query.fromUser.join(",")
let action = if user.len > 0: &"/{user}/search" else: "/search"
buildHtml(form(`method`="get", action=action, class="search-field")):
hiddenField("f", "custom")
hiddenField("f", "tweets")
genInput("q", "", query.text, "Enter search...",
class="pref-inline", autofocus=true)
button(`type`="submit"): icon "search"
@ -88,13 +88,13 @@ proc renderSearchPanel*(query: Query): VNode =
span(class="search-title"): text "Near"
genInput("near", "", query.near, placeholder="Location...")
proc renderTweetSearch*(tweets: Result[Tweet]; prefs: Prefs; path: string): VNode =
let query = tweets.query
proc renderTweetSearch*(results: Result[Tweet]; prefs: Prefs; path: string): VNode =
let query = results.query
buildHtml(tdiv(class="timeline-container")):
if query.fromUser.len > 1:
tdiv(class="timeline-header"):
text query.fromUser.join(" | ")
if query.fromUser.len == 0 or query.kind == custom:
if query.fromUser.len == 0 or query.kind == tweets:
tdiv(class="timeline-header"):
renderSearchPanel(query)
@ -103,16 +103,16 @@ proc renderTweetSearch*(tweets: Result[Tweet]; prefs: Prefs; path: string): VNod
else:
renderSearchTabs(query)
renderTimelineTweets(tweets, prefs, path)
renderTimelineTweets(results, prefs, path)
proc renderUserSearch*(users: Result[Profile]; prefs: Prefs): VNode =
proc renderUserSearch*(results: Result[Profile]; prefs: Prefs): VNode =
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header"):
form(`method`="get", action="/search", class="search-field"):
hiddenField("f", "users")
genInput("q", "", users.query.text, "Enter username...",
genInput("q", "", results.query.text, "Enter username...",
class="pref-inline", autofocus=true)
button(`type`="submit"): icon "search"
renderSearchTabs(users.query)
renderTimelineUsers(users, prefs)
renderSearchTabs(results.query)
renderTimelineUsers(results, prefs)