Files
nitter/src/views/search.nim

85 lines
2.8 KiB
Nim

# SPDX-License-Identifier: AGPL-3.0-only
import strutils, options
import karax/[karaxdsl, vdom]
import renderutils, timeline
import ".."/[types, query]
proc renderSearch*(): VNode =
buildHtml(tdiv(class="panel-container")):
discard
proc renderProfileTabs*(query: Query; username: string): VNode =
let link = "/" & username
buildHtml(ul(class="tab")):
li(class=query.getTabClass(posts)):
a(href=link): text "Tweets"
li(class=(query.getTabClass(replies) & " wide")):
a(href=(link & "/with_replies")): text "Tweets & Replies"
li(class=query.getTabClass(media)):
a(href=(link & "/media")): text "Media"
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(tweets)):
q.kind = tweets
a(href=("?" & genQueryUrl(q))): text "Tweets"
li(class=query.getTabClass(users)):
q.kind = users
a(href=("?" & genQueryUrl(q))): text "Users"
proc renderTweetSearch*(results: Timeline; prefs: Prefs; path: string;
pinned=none(Tweet)): 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:
renderProfileTabs(query, query.fromUser.join(","))
if query.fromUser.len == 0 or query.kind == tweets:
discard
if query.fromUser.len == 0:
renderSearchTabs(query)
renderTimelineTweets(results, prefs, path, pinned)
proc renderHomepageTabs*(query: Query): VNode =
buildHtml(ul(class="tab")):
li(class=if query.kind == tweets: "tab-item active" else: "tab-item"):
a(href="/?f=tweets"): text "Tweets"
li(class=if query.kind == replies: "tab-item active" else: "tab-item"):
a(href="/?f=replies"): text "Tweets & Replies"
proc renderHomepageTimeline*(results: Timeline; prefs: Prefs; path: string): VNode =
let query = results.query
buildHtml(tdiv(class="timeline-container")):
renderHomepageTabs(query)
renderTimelineTweets(results, prefs, path)
proc renderDefaultTimeline*(results: Timeline; prefs: Prefs; path: string): VNode =
let query = results.query
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header timeline-default"):
h2(class="timeline-default-message"):
text "Follow people to populate your "
strong: text "own"
text " feed"
renderHomepageTabs(query)
renderTimelineTweets(results, prefs, path)
proc renderUserSearch*(results: Result[User]; prefs: Prefs; path: string): VNode =
buildHtml(tdiv(class="timeline-container")):
renderSearchTabs(results.query)
renderTimelineUsers(results, prefs, path)