profile.nim 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import strutils, strformat
  2. import karax/[karaxdsl, vdom, vstyles]
  3. import ../types, ../utils, ../formatters
  4. import tweet, timeline, renderutils
  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"): text num
  10. proc renderProfileCard*(profile: Profile): VNode =
  11. buildHtml(tdiv(class="profile-card")):
  12. a(class="profile-card-avatar", href=profile.getUserPic().getSigUrl("pic")):
  13. genImg(profile.getUserpic("_200x200"))
  14. tdiv(class="profile-card-tabs"):
  15. tdiv(class="profile-card-tabs-name"):
  16. linkUser(profile, class="profile-card-fullname")
  17. linkUser(profile, class="profile-card-username")
  18. tdiv(class="profile-card-extra"):
  19. if profile.bio.len > 0:
  20. tdiv(class="profile-bio"):
  21. p: verbatim linkifyText(profile.bio)
  22. tdiv(class="profile-card-extra-links"):
  23. ul(class="profile-statlist"):
  24. renderStat(profile.tweets, "posts", text="Tweets")
  25. renderStat(profile.followers, "followers")
  26. renderStat(profile.following, "following")
  27. proc renderPhotoRail(username: string; photoRail: seq[GalleryPhoto]): VNode =
  28. buildHtml(tdiv(class="photo-rail-card")):
  29. tdiv(class="photo-rail-header"):
  30. a(href=(&"/{username}/media")):
  31. text "🖼 Photos and videos"
  32. tdiv(class="photo-rail-grid"):
  33. for i, photo in photoRail:
  34. if i == 16: break
  35. a(href=(&"/{username}/status/{photo.tweetId}"),
  36. style={backgroundColor: photo.color}):
  37. genImg(photo.url & ":thumb")
  38. proc renderBanner(profile: Profile): VNode =
  39. buildHtml():
  40. if "#" in profile.banner:
  41. tdiv(class="profile-banner-color", style={backgroundColor: profile.banner})
  42. else:
  43. a(href=getSigUrl(profile.banner, "pic")):
  44. genImg(profile.banner)
  45. proc renderProfile*(profile: Profile; timeline: Timeline;
  46. photoRail: seq[GalleryPhoto]): VNode =
  47. buildHtml(tdiv(class="profile-tabs")):
  48. tdiv(class="profile-banner"):
  49. renderBanner(profile)
  50. tdiv(class="profile-tab"):
  51. renderProfileCard(profile)
  52. if photoRail.len > 0:
  53. renderPhotoRail(profile.username, photoRail)
  54. tdiv(class="timeline-tab"):
  55. renderTimeline(timeline, profile)