profile.nim 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. var size = "_400x400"
  16. if prefs.autoplayGifs and profile.userpic.endsWith("gif"):
  17. size = ""
  18. a(class="profile-card-avatar", href=url, target="_blank"):
  19. genImg(profile.getUserpic(size))
  20. tdiv(class="profile-card-tabs-name"):
  21. linkUser(profile, class="profile-card-fullname")
  22. linkUser(profile, class="profile-card-username")
  23. tdiv(class="profile-card-extra"):
  24. if profile.bio.len > 0:
  25. tdiv(class="profile-bio"):
  26. p(dir="auto"):
  27. verbatim replaceUrl(profile.bio, prefs)
  28. if profile.location.len > 0:
  29. tdiv(class="profile-location"):
  30. span: icon "location"
  31. let (place, url) = getLocation(profile)
  32. if url.len > 1:
  33. a(href=url): text place
  34. elif "://" in place:
  35. a(href=place): text place
  36. else:
  37. span: text place
  38. if profile.website.len > 0:
  39. tdiv(class="profile-website"):
  40. span:
  41. let url = replaceUrl(profile.website, prefs)
  42. icon "link"
  43. a(href=url): text shortLink(url)
  44. tdiv(class="profile-joindate"):
  45. span(title=getJoinDateFull(profile)):
  46. icon "calendar", getJoinDate(profile)
  47. tdiv(class="profile-card-extra-links"):
  48. ul(class="profile-statlist"):
  49. renderStat(profile.tweets, "posts", text="Tweets")
  50. renderStat(profile.following, "following")
  51. renderStat(profile.followers, "followers")
  52. renderStat(profile.likes, "likes")
  53. proc renderPhotoRail(profile: Profile; photoRail: PhotoRail): VNode =
  54. let count = insertSep($profile.media, ',')
  55. buildHtml(tdiv(class="photo-rail-card")):
  56. tdiv(class="photo-rail-header"):
  57. a(href=(&"/{profile.username}/media")):
  58. icon "picture", count & " Photos and videos"
  59. input(id="photo-rail-grid-toggle", `type`="checkbox")
  60. label(`for`="photo-rail-grid-toggle", class="photo-rail-header-mobile"):
  61. icon "picture", count & " Photos and videos"
  62. icon "down"
  63. tdiv(class="photo-rail-grid"):
  64. for i, photo in photoRail:
  65. if i == 16: break
  66. let col = if photo.color.len > 0: photo.color else: "#161616"
  67. a(href=(&"/{profile.username}/status/{photo.tweetId}#m"),
  68. style={backgroundColor: col}):
  69. genImg(photo.url & (if "format" in photo.url: "" else: ":thumb"))
  70. proc renderBanner(profile: Profile): VNode =
  71. buildHtml():
  72. if "#" in profile.banner:
  73. tdiv(class="profile-banner-color", style={backgroundColor: profile.banner})
  74. else:
  75. a(href=getPicUrl(profile.banner), target="_blank"):
  76. genImg(profile.banner)
  77. proc renderProtected(username: string): VNode =
  78. buildHtml(tdiv(class="timeline-container")):
  79. tdiv(class="timeline-header timeline-protected"):
  80. h2: text "This account's tweets are protected."
  81. p: text &"Only confirmed followers have access to @{username}'s tweets."
  82. proc renderProfile*(profile: Profile; timeline: var Timeline;
  83. photoRail: PhotoRail; prefs: Prefs; path: string): VNode =
  84. timeline.query.fromUser = @[profile.username]
  85. buildHtml(tdiv(class="profile-tabs")):
  86. if not prefs.hideBanner:
  87. tdiv(class="profile-banner"):
  88. renderBanner(profile)
  89. let sticky = if prefs.stickyProfile: "sticky" else: "unset"
  90. tdiv(class="profile-tab", style={position: sticky}):
  91. renderProfileCard(profile, prefs)
  92. if photoRail.len > 0:
  93. renderPhotoRail(profile, photoRail)
  94. if profile.protected:
  95. renderProtected(profile.username)
  96. else:
  97. renderTweetSearch(timeline, prefs, path)