nitter/src/views/status.nim

62 lines
2.3 KiB
Nim
Raw Normal View History

import karax/[karaxdsl, vdom]
import ".."/[types, formatters]
import tweet, timeline
proc renderMoreReplies(thread: Chain): VNode =
let num = if thread.more != -1: $thread.more & " " else: ""
let reply = if thread.more == 1: "reply" else: "replies"
2019-09-24 14:34:50 +00:00
let link = getLink(thread.content[^1])
2019-09-13 17:57:27 +00:00
buildHtml(tdiv(class="timeline-item more-replies")):
if link.len > 0:
2019-09-24 14:34:50 +00:00
a(class="more-replies-text", href=link):
text $num & "more " & reply
else:
a(class="more-replies-text"):
text $num & "more " & reply
proc renderReplyThread(thread: Chain; prefs: Prefs; path: string): VNode =
buildHtml(tdiv(class="reply thread thread-line")):
2019-08-23 00:15:25 +00:00
for i, tweet in thread.content:
let last = (i == thread.content.high and thread.more == 0)
renderTweet(tweet, prefs, path, index=i, last=last)
if thread.more != 0:
renderMoreReplies(thread)
proc renderConversation*(conversation: Conversation; prefs: Prefs; path: string): VNode =
let hasAfter = conversation.after != nil
2019-09-13 17:52:05 +00:00
buildHtml(tdiv(class="conversation")):
tdiv(class="main-thread"):
if conversation.before != nil:
tdiv(class="before-tweet thread-line"):
2019-08-23 00:15:25 +00:00
for i, tweet in conversation.before.content:
renderTweet(tweet, prefs, path, index=i)
2019-10-22 07:17:58 +00:00
tdiv(class="main-tweet", id="m"):
let afterClass = if hasAfter: "thread thread-line" else: ""
renderTweet(conversation.tweet, prefs, path, class=afterClass,
mainTweet=true)
if hasAfter:
tdiv(class="after-tweet thread-line"):
2019-08-23 00:15:25 +00:00
let total = conversation.after.content.high
let more = conversation.after.more
2019-08-23 00:15:25 +00:00
for i, tweet in conversation.after.content:
renderTweet(tweet, prefs, path, index=i, last=(i == total and more == 0))
if more != 0:
renderMoreReplies(conversation.after)
if not conversation.replies.beginning:
renderNewer(Query(), getLink(conversation.tweet))
if conversation.replies.content.len > 0:
2019-10-22 07:18:18 +00:00
tdiv(class="replies", id="r"):
for thread in conversation.replies.content:
if thread == nil: continue
renderReplyThread(thread, prefs, path)
if conversation.replies.hasMore:
2019-10-22 07:18:18 +00:00
renderMore(Query(), conversation.replies.minId, focus="#r")