Use "tweets" instead of "custom" for search query
This commit is contained in:
parent
1c9c6a2947
commit
e090dde1ea
|
@ -24,7 +24,7 @@ template `@`(param: string): untyped =
|
||||||
|
|
||||||
proc initQuery*(pms: Table[string, string]; name=""): Query =
|
proc initQuery*(pms: Table[string, string]; name=""): Query =
|
||||||
result = Query(
|
result = Query(
|
||||||
kind: parseEnum[QueryKind](@"f", custom),
|
kind: parseEnum[QueryKind](@"f", tweets),
|
||||||
text: @"q",
|
text: @"q",
|
||||||
filters: validFilters.filterIt("f-" & it in pms),
|
filters: validFilters.filterIt("f-" & it in pms),
|
||||||
excludes: validFilters.filterIt("e-" & it in pms),
|
excludes: validFilters.filterIt("e-" & it in pms),
|
||||||
|
@ -84,7 +84,7 @@ proc genQueryParam*(query: Query): string =
|
||||||
result &= " " & query.text
|
result &= " " & query.text
|
||||||
|
|
||||||
proc genQueryUrl*(query: Query): string =
|
proc genQueryUrl*(query: Query): string =
|
||||||
if query.kind notin {custom, users}: return
|
if query.kind notin {tweets, users}: return
|
||||||
|
|
||||||
var params = @[&"f={query.kind}"]
|
var params = @[&"f={query.kind}"]
|
||||||
if query.text.len > 0:
|
if query.text.len > 0:
|
||||||
|
|
|
@ -25,7 +25,7 @@ proc createRssRouter*(cfg: Config) =
|
||||||
resp Http400, showError("Search input too long.", cfg.title)
|
resp Http400, showError("Search input too long.", cfg.title)
|
||||||
|
|
||||||
let query = initQuery(params(request))
|
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)
|
resp Http400, showError("Only Tweet searches are allowed for RSS feeds.", cfg.title)
|
||||||
|
|
||||||
let tweets = await getSearch[Tweet](query, "", getAgent())
|
let tweets = await getSearch[Tweet](query, "", getAgent())
|
||||||
|
|
|
@ -23,7 +23,7 @@ proc createSearchRouter*(cfg: Config) =
|
||||||
redirect("/" & @"q")
|
redirect("/" & @"q")
|
||||||
let users = await getSearch[Profile](query, @"after", getAgent())
|
let users = await getSearch[Profile](query, @"after", getAgent())
|
||||||
resp renderMain(renderUserSearch(users, prefs), request, cfg.title)
|
resp renderMain(renderUserSearch(users, prefs), request, cfg.title)
|
||||||
of custom:
|
of tweets:
|
||||||
let tweets = await getSearch[Tweet](query, @"after", getAgent())
|
let tweets = await getSearch[Tweet](query, @"after", getAgent())
|
||||||
let rss = "/search/rss?" & genQueryUrl(query)
|
let rss = "/search/rss?" & genQueryUrl(query)
|
||||||
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request,
|
resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request,
|
||||||
|
|
|
@ -57,7 +57,7 @@ dbFromTypes("cache.db", "", "", "", [Profile, Video])
|
||||||
|
|
||||||
type
|
type
|
||||||
QueryKind* = enum
|
QueryKind* = enum
|
||||||
posts, replies, media, users, custom, userList
|
posts, replies, media, users, tweets, userList
|
||||||
|
|
||||||
Query* = object
|
Query* = object
|
||||||
kind*: QueryKind
|
kind*: QueryKind
|
||||||
|
|
|
@ -23,8 +23,7 @@ proc renderNavbar*(title, rss: string; req: Request): VNode =
|
||||||
icon "search", title="Search", href="/search"
|
icon "search", title="Search", href="/search"
|
||||||
if rss.len > 0:
|
if rss.len > 0:
|
||||||
icon "rss-feed", title="RSS Feed", href=rss
|
icon "rss-feed", title="RSS Feed", href=rss
|
||||||
if "/search" notin path:
|
icon "bird", title="Open in Twitter", href=twitPath
|
||||||
icon "bird", title="Open in Twitter", href=twitPath
|
|
||||||
icon "info-circled", title="About", href="/about"
|
icon "info-circled", title="About", href="/about"
|
||||||
iconReferer "cog", "/settings", path, title="Preferences"
|
iconReferer "cog", "/settings", path, title="Preferences"
|
||||||
|
|
||||||
|
|
|
@ -36,14 +36,14 @@ proc renderProfileTabs*(query: Query; username: string): VNode =
|
||||||
a(href=(link & "/with_replies")): text "Tweets & Replies"
|
a(href=(link & "/with_replies")): text "Tweets & Replies"
|
||||||
li(class=query.getTabClass(media)):
|
li(class=query.getTabClass(media)):
|
||||||
a(href=(link & "/media")): text "Media"
|
a(href=(link & "/media")): text "Media"
|
||||||
li(class=query.getTabClass(custom)):
|
li(class=query.getTabClass(tweets)):
|
||||||
a(href=(link & "/search")): text "Search"
|
a(href=(link & "/search")): text "Search"
|
||||||
|
|
||||||
proc renderSearchTabs*(query: Query): VNode =
|
proc renderSearchTabs*(query: Query): VNode =
|
||||||
var q = query
|
var q = query
|
||||||
buildHtml(ul(class="tab")):
|
buildHtml(ul(class="tab")):
|
||||||
li(class=query.getTabClass(custom)):
|
li(class=query.getTabClass(tweets)):
|
||||||
q.kind = custom
|
q.kind = tweets
|
||||||
a(href=("?" & genQueryUrl(q))): text "Tweets"
|
a(href=("?" & genQueryUrl(q))): text "Tweets"
|
||||||
li(class=query.getTabClass(users)):
|
li(class=query.getTabClass(users)):
|
||||||
q.kind = users
|
q.kind = users
|
||||||
|
@ -57,7 +57,7 @@ proc renderSearchPanel*(query: Query): VNode =
|
||||||
let user = query.fromUser.join(",")
|
let user = query.fromUser.join(",")
|
||||||
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("f", "custom")
|
hiddenField("f", "tweets")
|
||||||
genInput("q", "", query.text, "Enter search...",
|
genInput("q", "", query.text, "Enter search...",
|
||||||
class="pref-inline", autofocus=true)
|
class="pref-inline", autofocus=true)
|
||||||
button(`type`="submit"): icon "search"
|
button(`type`="submit"): icon "search"
|
||||||
|
@ -88,13 +88,13 @@ proc renderSearchPanel*(query: Query): VNode =
|
||||||
span(class="search-title"): text "Near"
|
span(class="search-title"): text "Near"
|
||||||
genInput("near", "", query.near, placeholder="Location...")
|
genInput("near", "", query.near, placeholder="Location...")
|
||||||
|
|
||||||
proc renderTweetSearch*(tweets: Result[Tweet]; prefs: Prefs; path: string): VNode =
|
proc renderTweetSearch*(results: Result[Tweet]; prefs: Prefs; path: string): VNode =
|
||||||
let query = tweets.query
|
let query = results.query
|
||||||
buildHtml(tdiv(class="timeline-container")):
|
buildHtml(tdiv(class="timeline-container")):
|
||||||
if query.fromUser.len > 1:
|
if query.fromUser.len > 1:
|
||||||
tdiv(class="timeline-header"):
|
tdiv(class="timeline-header"):
|
||||||
text query.fromUser.join(" | ")
|
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"):
|
tdiv(class="timeline-header"):
|
||||||
renderSearchPanel(query)
|
renderSearchPanel(query)
|
||||||
|
|
||||||
|
@ -103,16 +103,16 @@ proc renderTweetSearch*(tweets: Result[Tweet]; prefs: Prefs; path: string): VNod
|
||||||
else:
|
else:
|
||||||
renderSearchTabs(query)
|
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")):
|
buildHtml(tdiv(class="timeline-container")):
|
||||||
tdiv(class="timeline-header"):
|
tdiv(class="timeline-header"):
|
||||||
form(`method`="get", action="/search", class="search-field"):
|
form(`method`="get", action="/search", class="search-field"):
|
||||||
hiddenField("f", "users")
|
hiddenField("f", "users")
|
||||||
genInput("q", "", users.query.text, "Enter username...",
|
genInput("q", "", results.query.text, "Enter username...",
|
||||||
class="pref-inline", autofocus=true)
|
class="pref-inline", autofocus=true)
|
||||||
button(`type`="submit"): icon "search"
|
button(`type`="submit"): icon "search"
|
||||||
|
|
||||||
renderSearchTabs(users.query)
|
renderSearchTabs(results.query)
|
||||||
renderTimelineUsers(users, prefs)
|
renderTimelineUsers(results, prefs)
|
||||||
|
|
Loading…
Reference in New Issue