nitter/src/views/profile.nim

120 lines
4.0 KiB
Nim
Raw Normal View History

2021-12-27 02:37:38 +01:00
# SPDX-License-Identifier: AGPL-3.0-only
import strutils, strformat
import karax/[karaxdsl, vdom, vstyles]
import renderutils, search
2019-09-06 02:42:35 +02:00
import ".."/[types, utils, formatters]
proc renderStat(num: int; class: string; text=""): VNode =
2019-08-06 15:57:47 +02: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 23:30:33 +02:00
span(class="profile-stat-num"):
text insertSep($num, ',')
proc renderUserCard*(user: User; prefs: Prefs): VNode =
buildHtml(tdiv(class="profile-card")):
2019-09-08 00:55:12 +02:00
tdiv(class="profile-card-info"):
2022-01-06 03:57:14 +01:00
let
url = getPicUrl(user.getUserPic())
2022-01-06 03:57:14 +01:00
size =
if prefs.autoplayGifs and user.userPic.endsWith("gif"): ""
2022-01-06 03:57:14 +01:00
else: "_400x400"
a(class="profile-card-avatar", href=url, target="_blank"):
genImg(user.getUserPic(size))
2019-09-08 00:55:12 +02: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-18 00:54:22 +02: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 05:44:58 +01:00
if url.len > 1:
a(href=url): text place
2020-03-09 01:03:24 +01:00
elif "://" in place:
a(href=place): text place
else:
2019-12-21 05:44:58 +01: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 02:22:22 +02: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 02:22:22 +02:00
icon "picture", count & " Photos and videos"
icon "down"
2019-09-08 00:55:12 +02:00
tdiv(class="photo-rail-grid"):
for i, photo in profile.photoRail:
if i == 16: break
2022-05-13 20:31:42 +02: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 20:31:42 +02: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 19:57:27 +02:00
proc renderProtected(username: string): VNode =
buildHtml(tdiv(class="timeline-container")):
2019-09-19 02:29:24 +02: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 19:57:27 +02: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 21:25:29 +02:00
if not prefs.hideBanner:
tdiv(class="profile-banner"):
renderBanner(profile.user.banner)
2022-01-06 15:21:42 +01: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)