nitter/src/views/status.nim

50 lines
1.8 KiB
Nim
Raw Normal View History

import strutils, strformat
import karax/[karaxdsl, vdom]
import ../types
import tweet, renderutils
proc renderMoreReplies(thread: Thread): VNode =
let num = if thread.more != -1: $thread.more & " " else: ""
let reply = if thread.more == 1: "reply" else: "replies"
buildHtml(tdiv(class="status-el more-replies")):
a(class="more-replies-text", title="Not implemented yet"):
text $num & "more " & reply
2019-08-13 19:44:29 +02:00
proc renderReplyThread(thread: Thread; prefs: Prefs): VNode =
buildHtml(tdiv(class="reply thread thread-line")):
2019-08-23 02:15:25 +02:00
for i, tweet in thread.content:
let last = (i == thread.content.high and thread.more == 0)
2019-08-13 19:44:29 +02:00
renderTweet(tweet, prefs, index=i, last=last)
if thread.more != 0:
renderMoreReplies(thread)
2019-08-13 19:44:29 +02:00
proc renderConversation*(conversation: Conversation; prefs: Prefs): VNode =
let hasAfter = conversation.after != nil
buildHtml(tdiv(class="conversation", id="posts")):
tdiv(class="main-thread"):
if conversation.before != nil:
tdiv(class="before-tweet thread-line"):
2019-08-23 02:15:25 +02:00
for i, tweet in conversation.before.content:
2019-08-13 19:44:29 +02:00
renderTweet(tweet, prefs, index=i)
tdiv(class="main-tweet"):
let afterClass = if hasAfter: "thread thread-line" else: ""
2019-08-13 19:44:29 +02:00
renderTweet(conversation.tweet, prefs, class=afterClass)
if hasAfter:
tdiv(class="after-tweet thread-line"):
2019-08-23 02:15:25 +02:00
let total = conversation.after.content.high
let more = conversation.after.more
2019-08-23 02:15:25 +02:00
for i, tweet in conversation.after.content:
renderTweet(tweet, prefs, index=i, last=(i == total and more == 0))
if more != 0:
renderMoreReplies(conversation.after)
if conversation.replies.len > 0:
tdiv(class="replies"):
for thread in conversation.replies:
2019-08-13 19:44:29 +02:00
renderReplyThread(thread, prefs)