gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita97c0295a97c0295tracker#4: show page /shows/:slug (header, seasons, episodes, watch checks) + tools/relink-episode-seasons.hlmrea97c0295/components/show.hl

9.8 KB

  1. // components/show.hl — `/shows/:slug` (tracker.worldapi.org#4): a show's own page. Creator's words:
  2. // "the poster on the left, right of it the title of the show, the genre pills, below the plot summary,
  3. // below that the artists just as normal links, separated with comma color red, genres are blue" (the
  4. // header) — "then all seasons in reverse order, latest on top, below them collapsable their episodes,
  5. // episodes first the round check icon, if the episode was watched by the user looking its solid, if
  6. // not its regular, then the episode number, then the title. the last season is not collapsed. click on
  7. // the check adds a watch. the season also has a check, if the season is checked or unchecked all its
  8. // episodes get checked or unchecked. artists link to /person/<artist-slug> the genre to /genre/<genre-slug>."
  9. //
  10. // THE ROWS ARE ONE FLAT LIST, not a nested for-loop over seasons > episodes: the vendored build may
  11. // still lack the fix for hybriel#86 (a nested for over a reassigned outer list keeps stale inner
  12. // cells) — a single-level `for (row of rows)` with a `kind` field, reassigned whole on every click,
  13. // is the same proven-safe shape components/main.hl's own header and ident's inbox.hl already use.
  14. // `rows` is rebuilt from scratch (seasons/episodes refetched by id, watch rows refetched) on every
  15. // toggle — cheap: a show has at most a few dozen episodes per season.
  16. parent './main.hl'
  17. import { appTitle } from '../project.hl'
  18. import { userIdOfSession } from '../users.hl'
  19. import { showBySlug, genreById, personById, seasonsOfShow, episodesOfSeason, seasonById, posterName } from '../shows.hl'
  20. import { watchesOfUser, isWatched, setWatched, setSeasonWatched } from '../watches.hl'
  21. // ---- pure helpers ----------------------------------------------------------------------------
  22. // `static`, like calendar.hl's `soonOf` — a PLAIN instance member function that calls an
  23. // hl:mpackdb-backed import (seasonsOfShow, episodesOfSeason, watchesOfUser, …) comes back null
  24. // when called from an `on server` face (confirmed by running the gate: "'buildRows' is not
  25. // callable — it holds null" at the face's call site, even though the SAME call works fine as a
  26. // member's own initializer at the top of this file). `static` is the proven-safe shape (calendar's
  27. // `soonOf`, called from `calLoad`/`calSettingsLoad`, an mpackdb-backed helper exactly like this one).
  28. static initialCollapsed = (seasons) => {
  29. let m = {}
  30. let i = 0
  31. while (i < seasons.length) {
  32. if (i > 0) { m[seasons[i].id] = true }
  33. i = i + 1
  34. }
  35. return m
  36. }
  37. static genreRowsOf = (show) => {
  38. let out = []
  39. for (gid of show.genres) {
  40. let g = genreById(gid)
  41. if (g != null) { out.push({ id = g.id name = g.name href = '/genre/' + g.urlSegment }) }
  42. }
  43. return out
  44. }
  45. static castRowsOf = (show) => {
  46. let out = []
  47. for (c of show.cast) {
  48. let p = personById(c.person)
  49. if (p != null) { out.push({ name = c.actor href = '/person/' + p.urlSegment }) }
  50. }
  51. return out
  52. }
  53. // a View attribute must be a literal, a member or a field path — never an inline expression — so
  54. // every ternary (watched -> icon class, collapsed -> row class) is resolved HERE, once, into a
  55. // plain field the View just reads (row.watchClass, row.rowClass)
  56. static watchClassOf = (watched) => { return watched ? 'checkicon solid' : 'checkicon regular' }
  57. static buildRows = (show, watchRows, collapsed) => {
  58. let out = []
  59. for (s of seasonsOfShow(show)) {
  60. let isCollapsed = collapsed[s.id] == true
  61. let label = s.title != null && s.title != '' ? s.title : 'Season ' + s.seasonNumber
  62. let seasonWatched = isWatched(watchRows, 'season', s.id)
  63. out.push({ kind = 'season' isSeason = true isEpisode = false id = s.id label = label episodeCountText = s.episodes.length + ' episodes' watched = seasonWatched watchClass = watchClassOf(seasonWatched) collapsed = isCollapsed rowClass = isCollapsed ? 'collapsed' : 'expanded' })
  64. if (!isCollapsed) {
  65. for (e of episodesOfSeason(s)) {
  66. let epWatched = isWatched(watchRows, 'episode', e.id)
  67. out.push({ kind = 'episode' isSeason = false isEpisode = true id = e.id seasonId = s.id episodeNumber = e.episodeNumber title = e.title != null ? e.title : '' watched = epWatched watchClass = watchClassOf(epWatched) })
  68. }
  69. }
  70. }
  71. return out
  72. }
  73. // ---- reactive members -----------------------------------------------------------------------
  74. slug = null
  75. session = null
  76. userId = userIdOfSession(session)
  77. signedIn = userId != null
  78. showRow = showBySlug(slug)
  79. found = showRow != null
  80. notFound = showRow == null
  81. title = found ? showRow.title : ''
  82. summary = found && showRow.summary != null ? showRow.summary : ''
  83. poster = found ? posterName(showRow) : null
  84. hasPoster = poster != null
  85. posterUrl = hasPoster ? '/posters/' + poster : ''
  86. genreRows = found ? genreRowsOf(showRow) : []
  87. hasGenres = genreRows.length > 0
  88. castRows = found ? castRowsOf(showRow) : []
  89. hasCast = castRows.length > 0
  90. collapsed = found ? initialCollapsed(seasonsOfShow(showRow)) : {}
  91. watchRows = found && signedIn ? watchesOfUser(userId) : []
  92. rows = found ? buildRows(showRow, watchRows, collapsed) : []
  93. hasRows = rows.length > 0
  94. __title = found ? title + ' — ' + appTitle : appTitle
  95. View {
  96. showPage {
  97. if (notFound) {
  98. article { class = "main"
  99. h1 { "Not found" }
  100. p { "This show doesn't exist." }
  101. }
  102. }
  103. if (found) {
  104. showHeader {
  105. showPoster { if (hasPoster) { img { src = posterUrl alt = title } } }
  106. showMeta {
  107. h1 { title }
  108. if (hasGenres) {
  109. showGenres {
  110. for (g of genreRows) { a { class = "genre-pill" href = g.href g.name } }
  111. }
  112. }
  113. showSummary { summary }
  114. if (hasCast) {
  115. showCast {
  116. for (c of castRows) { a { class = "artist-link" href = c.href c.name } }
  117. }
  118. }
  119. }
  120. }
  121. if (hasRows) {
  122. showSeasons {
  123. for (row of rows) {
  124. if (row.isSeason) {
  125. seasonRow { class = row.rowClass
  126. if (signedIn) {
  127. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark season watched"
  128. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  129. circle { cx = "12" cy = "12" r = "10" }
  130. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  131. }
  132. on click(e) { emit toggleSeason(row.id) }
  133. }
  134. }
  135. button { type = "button" class = "season-toggle" value = row.id
  136. seasonLabel { row.label }
  137. seasonCount { row.episodeCountText }
  138. on click(e) { emit toggleCollapse(row.id) }
  139. }
  140. }
  141. }
  142. if (row.isEpisode) {
  143. episodeRow {
  144. if (signedIn) {
  145. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark episode watched"
  146. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  147. circle { cx = "12" cy = "12" r = "10" }
  148. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  149. }
  150. on click(e) { emit toggleEpisode(row.id) }
  151. }
  152. }
  153. episodeNumber { row.episodeNumber }
  154. episodeTitle { row.title }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. // Every rebuild of `rows` happens SERVER-SIDE, never by calling `buildRows` from a client handler:
  164. // a member function whose body reaches an hl:mpackdb-backed import (seasonsOfShow, episodesOfSeason,
  165. // watchesOfUser, …) compiles to nothing on the client (no case ever assigns it — a genuine Hybriel
  166. // gap, filed under `issues`) even though the client bundle still calls it, so `this.buildRows(...)`
  167. // throws "not a function" in the browser. The client here only ever ASSIGNS the `rows` the server
  168. // already built (`rows = r.rows`) — never calls a tainted local helper itself. `slug` goes along so
  169. // the face can refetch the show without depending on implicit access to a sibling member.
  170. on toggleCollapse(seasonId) {
  171. let r = emit server showRows(slug, seasonId, collapsed)
  172. if (r == null || r.error != null) { return null }
  173. collapsed = r.collapsed
  174. rows = r.rows
  175. }
  176. on toggleEpisode(episodeId) {
  177. if (!signedIn) { return null }
  178. let r = emit server showToggleEpisode(slug, '' + episodeId, collapsed)
  179. if (r == null || r.error != null) { return null }
  180. rows = r.rows
  181. }
  182. on toggleSeason(seasonId) {
  183. if (!signedIn) { return null }
  184. let r = emit server showToggleSeason(slug, '' + seasonId, collapsed)
  185. if (r == null || r.error != null) { return null }
  186. rows = r.rows
  187. }
  188. // ---- the faces (the trailing `session` is always the server's: hybriel#16) ----
  189. on server showRows(slug, seasonId, collapsed, session) {
  190. let show = showBySlug(slug)
  191. if (show == null) { return { error = 'no such show' } }
  192. let m = collapsed
  193. m[seasonId] = collapsed[seasonId] == true ? false : true
  194. let uid = userIdOfSession(session)
  195. let wr = uid != null ? watchesOfUser(uid) : []
  196. return { ok = true collapsed = m rows = buildRows(show, wr, m) }
  197. }
  198. on server showToggleEpisode(slug, episodeId, collapsed, session) {
  199. let show = showBySlug(slug)
  200. if (show == null) { return { error = 'no such show' } }
  201. let uid = userIdOfSession(session)
  202. if (uid == null) { return { error = 'you are not signed in' } }
  203. let rows = watchesOfUser(uid)
  204. let watched = isWatched(rows, 'episode', episodeId) == false
  205. let ok = setWatched(uid, 'episode', episodeId, rows, watched)
  206. if (!ok) { return { error = 'could not save the watch' } }
  207. return { ok = true rows = buildRows(show, watchesOfUser(uid), collapsed) }
  208. }
  209. on server showToggleSeason(slug, seasonId, collapsed, session) {
  210. let show = showBySlug(slug)
  211. if (show == null) { return { error = 'no such show' } }
  212. let uid = userIdOfSession(session)
  213. if (uid == null) { return { error = 'you are not signed in' } }
  214. let season = seasonById(seasonId)
  215. if (season == null) { return { error = 'no such season' } }
  216. let rows = watchesOfUser(uid)
  217. let watched = isWatched(rows, 'season', seasonId) == false
  218. let ok = setSeasonWatched(uid, seasonId, season.episodes, rows, watched)
  219. if (!ok) { return { error = 'could not save the watch' } }
  220. return { ok = true rows = buildRows(show, watchesOfUser(uid), collapsed) }
  221. }

Branches

Latest commits

  • a97c0295tracker#4: show page /shows/:slug (header, seasons, episodes, watch checks) + tools/relink-episode-seasons.hlmre
  • 05f407c5tracker: no border on any button except inverted ones (Log out, ident status and identities too); header brand weight 100mre
  • 17375427tracker#2: tools/migrate.hl + tools/verify.hl — old MongoDB data into mpackdb with new idsmre
  • 31aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre
  • 2ad9d29ctracker#1: login exactly like calendar (identity selector in the header, empty homepage)mre
  • 3691e176tracker#1: empty tracker with the ident login (state of 2026-09-27)mre