2019-07-10 22:42:31 +00:00
|
|
|
import karax/[karaxdsl, vdom]
|
|
|
|
|
|
|
|
import ../types
|
2019-09-06 01:37:12 +00:00
|
|
|
import tweet
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-08-22 23:20:00 +00:00
|
|
|
proc renderMoreReplies(thread: Thread): VNode =
|
|
|
|
let num = if thread.more != -1: $thread.more & " " else: ""
|
|
|
|
let reply = if thread.more == 1: "reply" else: "replies"
|
2019-09-13 17:57:27 +00:00
|
|
|
buildHtml(tdiv(class="timeline-item more-replies")):
|
2019-08-22 23:20:00 +00:00
|
|
|
a(class="more-replies-text", title="Not implemented yet"):
|
|
|
|
text $num & "more " & reply
|
|
|
|
|
2019-09-05 20:40:36 +00:00
|
|
|
proc renderReplyThread(thread: Thread; prefs: Prefs; path: string): VNode =
|
2019-07-10 22:42:31 +00:00
|
|
|
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)
|
2019-09-05 20:40:36 +00:00
|
|
|
renderTweet(tweet, prefs, path, index=i, last=last)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
if thread.more != 0:
|
2019-08-22 23:20:00 +00:00
|
|
|
renderMoreReplies(thread)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-09-05 20:40:36 +00:00
|
|
|
proc renderConversation*(conversation: Conversation; prefs: Prefs; path: string): VNode =
|
2019-07-10 22:42:31 +00:00
|
|
|
let hasAfter = conversation.after != nil
|
2019-09-13 17:52:05 +00:00
|
|
|
buildHtml(tdiv(class="conversation")):
|
2019-07-10 22:42:31 +00:00
|
|
|
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:
|
2019-09-05 20:40:36 +00:00
|
|
|
renderTweet(tweet, prefs, path, index=i)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
tdiv(class="main-tweet"):
|
|
|
|
let afterClass = if hasAfter: "thread thread-line" else: ""
|
2019-09-05 20:40:36 +00:00
|
|
|
renderTweet(conversation.tweet, prefs, path, class=afterClass)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
if hasAfter:
|
|
|
|
tdiv(class="after-tweet thread-line"):
|
2019-08-23 00:15:25 +00:00
|
|
|
let total = conversation.after.content.high
|
2019-08-22 23:20:00 +00:00
|
|
|
let more = conversation.after.more
|
2019-08-23 00:15:25 +00:00
|
|
|
for i, tweet in conversation.after.content:
|
2019-09-05 20:40:36 +00:00
|
|
|
renderTweet(tweet, prefs, path, index=i, last=(i == total and more == 0))
|
2019-08-22 23:20:00 +00:00
|
|
|
|
|
|
|
if more != 0:
|
|
|
|
renderMoreReplies(conversation.after)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
|
|
|
if conversation.replies.len > 0:
|
|
|
|
tdiv(class="replies"):
|
|
|
|
for thread in conversation.replies:
|
2019-09-05 20:40:36 +00:00
|
|
|
if thread == nil: continue
|
|
|
|
renderReplyThread(thread, prefs, path)
|