nitter/src/views/search.nim

83 lines
3.2 KiB
Nim
Raw Normal View History

2019-09-17 19:01:44 +00:00
import strutils, strformat, unicode
2019-09-13 20:24:58 +00:00
import karax/[karaxdsl, vdom, vstyles]
import renderutils, timeline
import ".."/[types, formatters, query]
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-09-17 19:01:44 +00:00
hiddenField("kind", "users")
2019-09-13 20:24:58 +00:00
input(`type`="text", name="text", autofocus="", placeholder="Enter username...")
button(`type`="submit"): icon "search"
2019-09-17 19:01:44 +00:00
proc renderTimelineSearch*(timeline: Timeline; prefs: Prefs; path: string): VNode =
2019-09-13 21:19:31 +00:00
let users =
if timeline.query.isSome: get(timeline.query).fromUser
else: @[]
2019-09-13 20:24:58 +00:00
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header"):
text users.join(" | ")
renderProfileTabs(timeline.query, users.join(","))
renderTimelineTweets(timeline, prefs, path)
2019-09-17 19:01:44 +00:00
proc renderTweetSearch*(tweets: Result[Tweet]; prefs: Prefs; path: string): VNode =
let query = if tweets.query.isSome: get(tweets.query) else: Query(kind: custom)
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header"):
form(`method`="get", action="/search", class="search-field"):
hiddenField("kind", "custom")
genInput("text", "", query.text, "Enter search...", class="pref-inline")
button(`type`="submit"): icon "search"
input(id="panel-toggle", `type`="checkbox")
label(`for`="panel-toggle", class="panel-label"):
icon "down"
tdiv(class="search-panel"):
tdiv:
span(class="search-title"): text "Include: "
genCheckbox("retweets", "Retweets", "nativeretweets" in query.includes)
genCheckbox("replies", "Replies", "replies" in query.includes)
for f in @["filter", "exclude"]:
tdiv:
span(class="search-title"): text capitalize(f) & ":"
for i in commonFilters:
let state =
if f == "filter": i in query.filters
else: i in query.excludes
genCheckbox(&"{f[0]}-{i}", capitalize(i), state)
input(id=(&"{f}-toggle"), `type`="checkbox")
label(`for`=(&"{f}-toggle"), class=(&"{f}-label")):
icon "down"
tdiv(class=(&"{f}-extras")):
for i in advancedFilters:
let state =
if f == "filter": i in query.filters
else: i in query.excludes
genCheckbox(&"{f[0]}-{i}", i, state)
renderSearchTabs(tweets.query)
renderTimelineTweets(tweets, prefs, path)
2019-09-13 20:24:58 +00:00
proc renderUserSearch*(users: Result[Profile]; prefs: Prefs): VNode =
let searchText =
if users.query.isSome: get(users.query).text
else: ""
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"):
hiddenField("kind", "users")
genInput("text", "", searchText, "Enter username...", class="pref-inline")
2019-09-13 20:24:58 +00:00
button(`type`="submit"): icon "search"
2019-09-17 19:01:44 +00:00
input(id="panel-toggle", `type`="checkbox")
label(`for`="panel-toggle", class="panel-label"):
icon "down"
2019-09-13 20:24:58 +00:00
renderSearchTabs(users.query)
renderTimelineUsers(users, prefs)