nitter/src/views/profile.nim

99 lines
3.6 KiB
Nim
Raw Normal View History

import strutils, strformat
import karax/[karaxdsl, vdom, vstyles]
import tweet, timeline, renderutils
2019-09-06 02:42:35 +02:00
import ".."/[types, utils, formatters]
2019-08-06 15:57:47 +02:00
proc renderStat(num, class: string; text=""): VNode =
let t = if text.len > 0: text else: class
buildHtml(li(class=class)):
span(class="profile-stat-header"): text capitalizeAscii(t)
2019-08-11 23:30:33 +02:00
span(class="profile-stat-num"):
text if num.len == 0: "?" else: num
proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode =
buildHtml(tdiv(class="profile-card")):
2019-09-08 00:55:12 +02:00
tdiv(class="profile-card-info"):
let url = getPicUrl(profile.getUserPic())
a(class="profile-card-avatar", href=url, target="_blank"):
2019-09-08 00:55:12 +02:00
genImg(profile.getUserpic("_200x200"))
2019-09-08 00:55:12 +02:00
tdiv(class="profile-card-tabs-name"):
linkUser(profile, class="profile-card-fullname")
linkUser(profile, class="profile-card-username")
tdiv(class="profile-card-extra"):
if profile.bio.len > 0:
tdiv(class="profile-bio"):
p: verbatim linkifyText(profile.bio, prefs)
if profile.location.len > 0:
tdiv(class="profile-location"):
span: icon "location", profile.location
if profile.website.len > 0:
tdiv(class="profile-website"):
span:
icon "link"
2019-08-12 03:32:27 +02:00
linkText(profile.website)
tdiv(class="profile-joindate"):
span(title=getJoinDateFull(profile)):
icon "calendar", getJoinDate(profile)
tdiv(class="profile-card-extra-links"):
ul(class="profile-statlist"):
2019-08-06 15:57:47 +02:00
renderStat(profile.tweets, "posts", text="Tweets")
renderStat(profile.followers, "followers")
renderStat(profile.following, "following")
renderStat(profile.likes, "likes")
2019-08-11 23:24:02 +02:00
proc renderPhotoRail(profile: Profile; photoRail: seq[GalleryPhoto]): VNode =
buildHtml(tdiv(class="photo-rail-card")):
tdiv(class="photo-rail-header"):
2019-08-11 23:24:02 +02:00
a(href=(&"/{profile.username}/media")):
2019-08-19 21:18:18 +02:00
icon "picture", $profile.media & " Photos and videos"
2019-09-08 00:55:12 +02:00
input(id="photo-rail-toggle", `type`="checkbox")
tdiv(class="photo-rail-header-mobile"):
label(`for`="photo-rail-toggle", class="photo-rail-label"):
icon "picture", $profile.media & " Photos and videos"
icon "down"
tdiv(class="photo-rail-grid"):
for i, photo in photoRail:
if i == 16: break
2019-08-11 23:24:02 +02:00
a(href=(&"/{profile.username}/status/{photo.tweetId}"),
style={backgroundColor: photo.color}):
genImg(photo.url & ":thumb")
proc renderBanner(profile: Profile): VNode =
buildHtml():
if "#" in profile.banner:
tdiv(class="profile-banner-color", style={backgroundColor: profile.banner})
else:
a(href=getPicUrl(profile.banner), target="_blank"):
genImg(profile.banner)
proc renderProfile*(profile: Profile; timeline: Timeline;
photoRail: seq[GalleryPhoto]; prefs: Prefs; path: string): VNode =
buildHtml(tdiv(class="profile-tabs")):
2019-08-13 21:25:29 +02:00
if not prefs.hideBanner:
tdiv(class="profile-banner"):
renderBanner(profile)
2019-08-13 21:25:29 +02:00
let sticky = if prefs.stickyProfile: "sticky" else: "unset"
tdiv(class="profile-tab", style={position: sticky}):
renderProfileCard(profile, prefs)
if photoRail.len > 0:
2019-08-11 23:24:02 +02:00
renderPhotoRail(profile, photoRail)
tdiv(class="timeline-tab"):
renderTimeline(timeline, profile.username, profile.protected, prefs, path)
2019-08-06 17:41:06 +02:00
proc renderMulti*(timeline: Timeline; usernames: string;
prefs: Prefs; path: string): VNode =
2019-08-06 17:41:06 +02:00
buildHtml(tdiv(class="multi-timeline")):
tdiv(class="timeline-tab"):
renderTimeline(timeline, usernames, false, prefs, path, multi=true)