profile.nim 3.8 KB

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