nitter/src/views/profile.nim

120 lines
4 KiB
Nim
Raw Normal View History

2021-12-27 01:37:38 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
import strutils, strformat
import karax/[karaxdsl, vdom, vstyles]
import renderutils, search
2019-09-06 00:42:35 +00:00
import ".."/[types, utils, formatters]
proc renderStat(num: int; class: string; text=""): VNode =
2019-08-06 13:57:47 +00:00
let t = if text.len > 0: text else: class
buildHtml(li(class=class)):
span(class="profile-stat-header"): text capitalizeAscii(t)
2019-08-11 21:30:33 +00:00
span(class="profile-stat-num"):
text insertSep($num, ',')
proc renderUserCard*(user: User; prefs: Prefs): VNode =
buildHtml(tdiv(class="profile-card")):
2019-09-07 22:55:12 +00:00
tdiv(class="profile-card-info"):
2022-01-06 02:57:14 +00:00
let
url = getPicUrl(user.getUserPic())
2022-01-06 02:57:14 +00:00
size =
if prefs.autoplayGifs and user.userPic.endsWith("gif"): ""
2022-01-06 02:57:14 +00:00
else: "_400x400"
a(class="profile-card-avatar", href=url, target="_blank"):
genImg(user.getUserPic(size))
2019-09-07 22:55:12 +00:00
tdiv(class="profile-card-tabs-name"):
linkUser(user, class="profile-card-fullname")
linkUser(user, class="profile-card-username")
tdiv(class="profile-card-extra"):
if user.bio.len > 0:
tdiv(class="profile-bio"):
2019-10-17 22:54:22 +00:00
p(dir="auto"):
verbatim replaceUrls(user.bio, prefs)
if user.location.len > 0:
tdiv(class="profile-location"):
span: icon "location"
let (place, url) = getLocation(user)
2019-12-21 04:44:58 +00:00
if url.len > 1:
a(href=url): text place
2020-03-09 00:03:24 +00:00
elif "://" in place:
a(href=place): text place
else:
2019-12-21 04:44:58 +00:00
span: text place
if user.website.len > 0:
tdiv(class="profile-website"):
span:
let url = replaceUrls(user.website, prefs)
icon "link"
a(href=url): text url.shortLink
tdiv(class="profile-joindate"):
span(title=getJoinDateFull(user)):
icon "calendar", getJoinDate(user)
tdiv(class="profile-card-extra-links"):
ul(class="profile-statlist"):
renderStat(user.tweets, "posts", text="Tweets")
renderStat(user.following, "following")
renderStat(user.followers, "followers")
renderStat(user.likes, "likes")
proc renderPhotoRail(profile: Profile): VNode =
let count = insertSep($profile.user.media, ',')
buildHtml(tdiv(class="photo-rail-card")):
tdiv(class="photo-rail-header"):
a(href=(&"/{profile.user.username}/media")):
2020-06-01 00:22:22 +00:00
icon "picture", count & " Photos and videos"
input(id="photo-rail-grid-toggle", `type`="checkbox")
label(`for`="photo-rail-grid-toggle", class="photo-rail-header-mobile"):
2020-06-01 00:22:22 +00:00
icon "picture", count & " Photos and videos"
icon "down"
2019-09-07 22:55:12 +00:00
tdiv(class="photo-rail-grid"):
for i, photo in profile.photoRail:
if i == 16: break
2022-05-13 18:31:42 +00:00
let photoSuffix =
if "format" in photo.url or "placeholder" in photo.url: ""
else: ":thumb"
a(href=(&"/{profile.user.username}/status/{photo.tweetId}#m")):
2022-05-13 18:31:42 +00:00
genImg(photo.url & photoSuffix)
proc renderBanner(banner: string): VNode =
buildHtml():
if banner.len == 0:
a()
elif banner.startsWith('#'):
a(style={backgroundColor: banner})
else:
a(href=getPicUrl(banner), target="_blank"): genImg(banner)
2019-09-13 17:57:27 +00:00
proc renderProtected(username: string): VNode =
buildHtml(tdiv(class="timeline-container")):
2019-09-19 00:29:24 +00:00
tdiv(class="timeline-header timeline-protected"):
h2: text "This account's tweets are protected."
p: text &"Only confirmed followers have access to @{username}'s tweets."
2019-09-13 17:57:27 +00:00
proc renderProfile*(profile: var Profile; prefs: Prefs; path: string): VNode =
profile.tweets.query.fromUser = @[profile.user.username]
buildHtml(tdiv(class="profile-tabs")):
2019-08-13 19:25:29 +00:00
if not prefs.hideBanner:
tdiv(class="profile-banner"):
renderBanner(profile.user.banner)
2022-01-06 14:21:42 +00:00
let sticky = if prefs.stickyProfile: " sticky" else: ""
tdiv(class=("profile-tab" & sticky)):
renderUserCard(profile.user, prefs)
if profile.photoRail.len > 0:
renderPhotoRail(profile)
if profile.user.protected:
renderProtected(profile.user.username)
else:
renderTweetSearch(profile.tweets, prefs, path, profile.pinned)