2019-09-19 21:47:05 +00:00
|
|
|
import strutils, strformat, sequtils, unicode, tables
|
2020-06-01 00:22:22 +00:00
|
|
|
import karax/[karaxdsl, vdom]
|
2019-09-13 20:24:58 +00:00
|
|
|
|
|
|
|
import renderutils, timeline
|
2020-06-01 00:22:22 +00:00
|
|
|
import ".."/[types, query]
|
2019-09-13 20:24:58 +00:00
|
|
|
|
2020-06-22 01:50:16 +00:00
|
|
|
const toggles = {
|
2019-09-18 23:01:47 +00:00
|
|
|
"nativeretweets": "Retweets",
|
|
|
|
"media": "Media",
|
|
|
|
"videos": "Videos",
|
|
|
|
"news": "News",
|
|
|
|
"verified": "Verified",
|
|
|
|
"native_video": "Native videos",
|
|
|
|
"replies": "Replies",
|
|
|
|
"links": "Links",
|
|
|
|
"images": "Images",
|
|
|
|
"safe": "Safe",
|
|
|
|
"quote": "Quotes",
|
|
|
|
"pro_video": "Pro videos"
|
|
|
|
}.toOrderedTable
|
|
|
|
|
2019-09-13 20:24:58 +00:00
|
|
|
proc renderSearch*(): VNode =
|
|
|
|
buildHtml(tdiv(class="panel-container")):
|
2019-09-17 19:01:44 +00:00
|
|
|
tdiv(class="search-bar"):
|
2019-09-13 20:24:58 +00:00
|
|
|
form(`method`="get", action="/search"):
|
2019-10-08 11:45:47 +00:00
|
|
|
hiddenField("f", "users")
|
2019-09-30 20:24:01 +00:00
|
|
|
input(`type`="text", name="q", autofocus="", placeholder="Enter username...")
|
2019-09-13 20:24:58 +00:00
|
|
|
button(`type`="submit"): icon "search"
|
|
|
|
|
2019-09-19 00:23:22 +00:00
|
|
|
proc renderProfileTabs*(query: Query; username: string): VNode =
|
2019-09-18 23:01:47 +00:00
|
|
|
let link = "/" & username
|
|
|
|
buildHtml(ul(class="tab")):
|
2019-09-19 00:23:22 +00:00
|
|
|
li(class=query.getTabClass(posts)):
|
2019-09-18 23:01:47 +00:00
|
|
|
a(href=link): text "Tweets"
|
2019-09-20 13:48:14 +00:00
|
|
|
li(class=(query.getTabClass(replies) & " wide")):
|
2019-10-07 15:46:16 +00:00
|
|
|
a(href=(link & "/with_replies")): text "Tweets & Replies"
|
2019-09-19 00:23:22 +00:00
|
|
|
li(class=query.getTabClass(media)):
|
2019-09-18 23:01:47 +00:00
|
|
|
a(href=(link & "/media")): text "Media"
|
2019-10-08 11:54:20 +00:00
|
|
|
li(class=query.getTabClass(tweets)):
|
2019-09-20 01:36:05 +00:00
|
|
|
a(href=(link & "/search")): text "Search"
|
2019-09-18 23:01:47 +00:00
|
|
|
|
2019-09-19 00:23:22 +00:00
|
|
|
proc renderSearchTabs*(query: Query): VNode =
|
|
|
|
var q = query
|
2019-09-18 23:01:47 +00:00
|
|
|
buildHtml(ul(class="tab")):
|
2019-10-08 11:54:20 +00:00
|
|
|
li(class=query.getTabClass(tweets)):
|
|
|
|
q.kind = tweets
|
2019-09-20 20:56:27 +00:00
|
|
|
a(href=("?" & genQueryUrl(q))): text "Tweets"
|
2019-10-08 11:45:47 +00:00
|
|
|
li(class=query.getTabClass(users)):
|
|
|
|
q.kind = users
|
2019-09-20 20:56:27 +00:00
|
|
|
a(href=("?" & genQueryUrl(q))): text "Users"
|
2019-09-13 20:24:58 +00:00
|
|
|
|
2019-09-19 21:47:05 +00:00
|
|
|
proc isPanelOpen(q: Query): bool =
|
2019-09-20 02:04:12 +00:00
|
|
|
q.fromUser.len == 0 and (q.filters.len > 0 or q.excludes.len > 0 or
|
|
|
|
@[q.near, q.until, q.since].anyIt(it.len > 0))
|
2019-09-19 21:47:05 +00:00
|
|
|
|
2019-09-18 23:01:47 +00:00
|
|
|
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")):
|
2019-10-08 11:54:20 +00:00
|
|
|
hiddenField("f", "tweets")
|
2019-11-14 06:32:11 +00:00
|
|
|
genInput("q", "", query.text, "Enter search...", class="pref-inline")
|
2019-09-18 23:01:47 +00:00
|
|
|
button(`type`="submit"): icon "search"
|
2019-09-19 21:47:05 +00:00
|
|
|
if isPanelOpen(query):
|
|
|
|
input(id="search-panel-toggle", `type`="checkbox", checked="")
|
|
|
|
else:
|
|
|
|
input(id="search-panel-toggle", `type`="checkbox")
|
2019-09-18 23:01:47 +00:00
|
|
|
label(`for`="search-panel-toggle"):
|
|
|
|
icon "down"
|
|
|
|
tdiv(class="search-panel"):
|
|
|
|
for f in @["filter", "exclude"]:
|
|
|
|
span(class="search-title"): text capitalize(f)
|
|
|
|
tdiv(class="search-toggles"):
|
|
|
|
for k, v in toggles:
|
|
|
|
let state =
|
|
|
|
if f == "filter": k in query.filters
|
|
|
|
else: k in query.excludes
|
|
|
|
genCheckbox(&"{f[0]}-{k}", v, state)
|
2019-09-13 20:24:58 +00:00
|
|
|
|
2019-09-19 21:36:21 +00:00
|
|
|
tdiv(class="search-row"):
|
|
|
|
tdiv:
|
|
|
|
span(class="search-title"): text "Time range"
|
|
|
|
tdiv(class="date-range"):
|
|
|
|
genDate("since", query.since)
|
|
|
|
span(class="search-title"): text "-"
|
|
|
|
genDate("until", query.until)
|
|
|
|
tdiv:
|
|
|
|
span(class="search-title"): text "Near"
|
|
|
|
genInput("near", "", query.near, placeholder="Location...")
|
2019-09-19 20:11:38 +00:00
|
|
|
|
2019-10-08 11:54:20 +00:00
|
|
|
proc renderTweetSearch*(results: Result[Tweet]; prefs: Prefs; path: string): VNode =
|
|
|
|
let query = results.query
|
2019-09-17 19:01:44 +00:00
|
|
|
buildHtml(tdiv(class="timeline-container")):
|
2019-09-18 23:01:47 +00:00
|
|
|
if query.fromUser.len > 1:
|
|
|
|
tdiv(class="timeline-header"):
|
|
|
|
text query.fromUser.join(" | ")
|
2020-06-01 00:22:22 +00:00
|
|
|
|
|
|
|
if query.fromUser.len > 0:
|
|
|
|
renderProfileTabs(query, query.fromUser.join(","))
|
|
|
|
|
2019-10-08 11:54:20 +00:00
|
|
|
if query.fromUser.len == 0 or query.kind == tweets:
|
2019-09-18 23:01:47 +00:00
|
|
|
tdiv(class="timeline-header"):
|
|
|
|
renderSearchPanel(query)
|
|
|
|
|
2020-06-01 00:22:22 +00:00
|
|
|
if query.fromUser.len == 0:
|
2019-09-19 00:23:22 +00:00
|
|
|
renderSearchTabs(query)
|
2019-09-18 23:01:47 +00:00
|
|
|
|
2019-10-08 11:54:20 +00:00
|
|
|
renderTimelineTweets(results, prefs, path)
|
2019-09-17 19:01:44 +00:00
|
|
|
|
2019-10-08 11:54:20 +00:00
|
|
|
proc renderUserSearch*(results: Result[Profile]; prefs: Prefs): VNode =
|
2019-09-13 20:24:58 +00:00
|
|
|
buildHtml(tdiv(class="timeline-container")):
|
|
|
|
tdiv(class="timeline-header"):
|
2019-09-17 19:01:44 +00:00
|
|
|
form(`method`="get", action="/search", class="search-field"):
|
2019-10-08 11:45:47 +00:00
|
|
|
hiddenField("f", "users")
|
2019-11-14 06:32:11 +00:00
|
|
|
genInput("q", "", results.query.text, "Enter username...", class="pref-inline")
|
2019-09-13 20:24:58 +00:00
|
|
|
button(`type`="submit"): icon "search"
|
|
|
|
|
2019-10-08 11:54:20 +00:00
|
|
|
renderSearchTabs(results.query)
|
|
|
|
renderTimelineUsers(results, prefs)
|