profile.nim 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import strutils, strformat
  2. import karax/[karaxdsl, vdom, vstyles]
  3. import renderutils, search
  4. import ".."/[types, utils, formatters]
  5. proc renderStat(num, class: string; text=""): VNode =
  6. let t = if text.len > 0: text else: class
  7. buildHtml(li(class=class)):
  8. span(class="profile-stat-header"): text capitalizeAscii(t)
  9. span(class="profile-stat-num"):
  10. text if num.len == 0: "?" else: insertSep(num, ',')
  11. proc renderProfileCard*(profile: Profile; prefs: Prefs): VNode =
  12. buildHtml(tdiv(class="profile-card")):
  13. tdiv(class="profile-card-info"):
  14. let url = getPicUrl(profile.getUserPic())
  15. a(class="profile-card-avatar", href=url, target="_blank"):
  16. genImg(profile.getUserpic("_200x200"))
  17. tdiv(class="profile-card-tabs-name"):
  18. linkUser(profile, class="profile-card-fullname")
  19. linkUser(profile, class="profile-card-username")
  20. tdiv(class="profile-card-extra"):
  21. if profile.bio.len > 0:
  22. tdiv(class="profile-bio"):
  23. p(dir="auto"):
  24. verbatim replaceUrl(profile.bio, prefs)
  25. if profile.location.len > 0:
  26. tdiv(class="profile-location"):
  27. span: icon "location"
  28. let (place, url) = getLocation(profile)
  29. if url.len > 1:
  30. a(href=url): text place
  31. elif "://" in place:
  32. a(href=place): text place
  33. else:
  34. span: text place
  35. if profile.website.len > 0:
  36. tdiv(class="profile-website"):
  37. span:
  38. let url = replaceUrl(profile.website, prefs)
  39. icon "link"
  40. a(href=url): text shortLink(url)
  41. tdiv(class="profile-joindate"):
  42. span(title=getJoinDateFull(profile)):
  43. icon "calendar", getJoinDate(profile)
  44. tdiv(class="profile-card-extra-links"):
  45. ul(class="profile-statlist"):
  46. renderStat(profile.tweets, "posts", text="Tweets")
  47. renderStat(profile.following, "following")
  48. renderStat(profile.followers, "followers")
  49. renderStat(profile.likes, "likes")
  50. proc renderPhotoRail(profile: Profile; photoRail: PhotoRail): VNode =
  51. buildHtml(tdiv(class="photo-rail-card")):
  52. tdiv(class="photo-rail-header"):
  53. a(href=(&"/{profile.username}/media")):
  54. icon "picture", $profile.media & " Photos and videos"
  55. input(id="photo-rail-grid-toggle", `type`="checkbox")
  56. label(`for`="photo-rail-grid-toggle", class="photo-rail-header-mobile"):
  57. icon "picture", $profile.media & " Photos and videos"
  58. icon "down"
  59. tdiv(class="photo-rail-grid"):
  60. for i, photo in photoRail:
  61. if i == 16: break
  62. a(href=(&"/{profile.username}/status/{photo.tweetId}#m"),
  63. style={backgroundColor: photo.color}):
  64. genImg(photo.url & ":thumb")
  65. proc renderBanner(profile: Profile): VNode =
  66. buildHtml():
  67. if "#" in profile.banner:
  68. tdiv(class="profile-banner-color", style={backgroundColor: profile.banner})
  69. else:
  70. a(href=getPicUrl(profile.banner), target="_blank"):
  71. genImg(profile.banner)
  72. proc renderProtected(username: string): VNode =
  73. buildHtml(tdiv(class="timeline-container")):
  74. tdiv(class="timeline-header timeline-protected"):
  75. h2: text "This account's tweets are protected."
  76. p: text &"Only confirmed followers have access to @{username}'s tweets."
  77. proc renderProfile*(profile: Profile; timeline: Timeline;
  78. photoRail: PhotoRail; prefs: Prefs; path: string): VNode =
  79. timeline.query.fromUser = @[profile.username]
  80. buildHtml(tdiv(class="profile-tabs")):
  81. if not prefs.hideBanner:
  82. tdiv(class="profile-banner"):
  83. renderBanner(profile)
  84. let sticky = if prefs.stickyProfile: "sticky" else: "unset"
  85. tdiv(class="profile-tab", style={position: sticky}):
  86. renderProfileCard(profile, prefs)
  87. if photoRail.len > 0:
  88. renderPhotoRail(profile, photoRail)
  89. if profile.protected:
  90. renderProtected(profile.username)
  91. else:
  92. renderTweetSearch(timeline, prefs, path)