gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf2fe3e36f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmref2fe3e36/components/show.hl

14.9 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. //
  17. // Mission 047 (the creator, 2026-10-01): a caret at the season header's right edge (down = open, right = collapsed); episode
  18. // rows not indented; on a phone the title first, then the poster at full width, then genres/plot/cast; a Follow toggle
  19. // next to the title. SIGNED OUT the checks and Follow are visible too: a click opens the "sign in" modal (modal.hl, copied
  20. // from components.hybriel) and writes nothing.
  21. //
  22. // tracker.worldapi.org#12: link icons under the title — the show on TMDB, IMDb, TheTVDB, TVmaze (a movie: TMDB + IMDb),
  23. // only for the ids it has (shows.hl externalLinksOf), each in a new tab.
  24. parent './main.hl'
  25. import Modal from './modal.hl'
  26. import { appTitle } from '../project.hl'
  27. import { userIdOfSession, loginHref } from '../users.hl'
  28. import { isFollowing, setFollowed } from '../follows.hl'
  29. import { showBySlug, genreById, personById, seasonsOfShow, episodesOfSeason, seasonById, posterName, externalLinksOf } from '../shows.hl'
  30. import { watchesOfUser, isWatched, watchedSet, setWatched, setSeasonWatched, watchClassOf } from '../watches.hl'
  31. // ---- pure helpers ----------------------------------------------------------------------------
  32. // `static`, like calendar.hl's `soonOf` — a PLAIN instance member function that calls an
  33. // hl:mpackdb-backed import (seasonsOfShow, episodesOfSeason, watchesOfUser, …) comes back null
  34. // when called from an `on server` face (confirmed by running the gate: "'buildRows' is not
  35. // callable — it holds null" at the face's call site, even though the SAME call works fine as a
  36. // member's own initializer at the top of this file). `static` is the proven-safe shape (calendar's
  37. // `soonOf`, called from `calLoad`/`calSettingsLoad`, an mpackdb-backed helper exactly like this one).
  38. static initialCollapsed = (seasons) => {
  39. let m = {}
  40. let i = 0
  41. while (i < seasons.length) {
  42. if (i > 0) { m[seasons[i].id] = true }
  43. i = i + 1
  44. }
  45. return m
  46. }
  47. static genreRowsOf = (show) => {
  48. let out = []
  49. for (gid of show.genres) {
  50. let g = genreById(gid)
  51. if (g != null) { out.push({ id = g.id name = g.name href = '/genre/' + g.urlSegment }) }
  52. }
  53. return out
  54. }
  55. static castRowsOf = (show) => {
  56. let out = []
  57. for (c of show.cast) {
  58. let p = personById(c.person)
  59. if (p != null) { out.push({ name = c.actor href = '/person/' + p.urlSegment }) }
  60. }
  61. return out
  62. }
  63. // a View attribute must be a literal, a member or a field path — never an inline expression — so
  64. // every ternary (watched -> icon class, collapsed -> row class) is resolved HERE, once, into a
  65. // plain field the View just reads (row.watchClass, row.rowClass); `watchClassOf` itself lives in
  66. // watches.hl (shared with /unwatched and /schedule, "reuse, don't copy")
  67. static buildRows = (show, uid, collapsed) => {
  68. let watched = watchedSet(uid != null ? watchesOfUser(uid) : [])
  69. let out = []
  70. for (s of seasonsOfShow(show)) {
  71. let isCollapsed = collapsed[s.id] == true
  72. let label = s.title != null && s.title != '' ? s.title : 'Season ' + s.seasonNumber
  73. let seasonWatched = watched['season:' + s.id] == true
  74. out.push({ kind = 'season' isSeason = true isEpisode = false id = s.id label = label episodeCountText = s.episodes.length == 1 ? '1 episode' : s.episodes.length + ' episodes' watched = seasonWatched watchClass = watchClassOf(seasonWatched) collapsed = isCollapsed rowClass = isCollapsed ? 'collapsed' : 'expanded' })
  75. if (!isCollapsed) {
  76. for (e of episodesOfSeason(s)) {
  77. let epWatched = watched['episode:' + e.id] == true
  78. 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) })
  79. }
  80. }
  81. }
  82. return out
  83. }
  84. // a LOCAL static like buildRows (an imported mpackdb helper called straight from a member's initializer came back false
  85. // after a client-side navigation to the page — the gate's follow check)
  86. static followingOf = (show, uid) => { return uid != null && isFollowing(uid, show.id) }
  87. // mission 056: an ADULT title's page (TMDB's flag `adult == true`, mission 054) is "Not found" for everyone who does not
  88. // follow it (signed out too); a follower sees it as before. Unknown (`null`) is not hidden here — only in the lists.
  89. // With hybriel ≥ 73267707 (#121/#122) `showRow`/`found` are server sites re-derived after every session face with the page's
  90. // slug, so an Unfollow on the page hides it at once (the gate proves it; the old build left the page up until a reload).
  91. // Mission 054's try (`found = … && !adultHiddenFor(showRow, me)`, `collapsed`/`rows` from `found`) broke the checks.
  92. static adultHiddenFor = (show, uid) => { return show.adult == true && !followingOf(show, uid) }
  93. // the page's show — null when there is none OR it is hidden for this user: every member is shipped to the browser, so the
  94. // row of a hidden title must never be one
  95. static visibleShow = (slug, uid) => {
  96. let s = showBySlug(slug)
  97. return s != null && adultHiddenFor(s, uid) ? null : s
  98. }
  99. // the initial open/closed seasons from the SLUG alone (not from `showRow`, which reads the session — see `collapsed`)
  100. static initialCollapsedOf = (slug) => {
  101. let s = showBySlug(slug)
  102. return s != null ? initialCollapsed(seasonsOfShow(s)) : {}
  103. }
  104. // ---- reactive members -----------------------------------------------------------------------
  105. slug = null
  106. session = null
  107. userId = userIdOfSession(session)
  108. signedIn = userId != null
  109. // SESSION SYNC (mission 047; since hybriel #121/#122, mission 056): a face taking `session` answers with a `sync` of every
  110. // member derived from session that reaches an import (here `showRow`, `found`, `following`, `rows`, …), re-derived on the
  111. // server with the page's route params but the MOUNT's other state — so client state (`collapsed`) must never derive from
  112. // them. `me` stays the plain copy mission 047 introduced.
  113. me = userId
  114. showRow = visibleShow(slug, me)
  115. found = showRow != null
  116. notFound = showRow == null
  117. // the Follow toggle: "Follow" = the inverted button (accent border), "Following" = the filled one
  118. following = found ? followingOf(showRow, me) : false
  119. followClass = following ? 'follow' : 'follow inverted'
  120. followText = following ? 'Following' : 'Follow'
  121. signInHref = loginHref
  122. title = found ? showRow.title : ''
  123. summary = found && showRow.summary != null ? showRow.summary : ''
  124. poster = found ? posterName(showRow) : null
  125. hasPoster = poster != null
  126. posterUrl = hasPoster ? '/posters/' + poster : ''
  127. genreRows = found ? genreRowsOf(showRow) : []
  128. hasGenres = genreRows.length > 0
  129. castRows = found ? castRowsOf(showRow) : []
  130. hasCast = castRows.length > 0
  131. linkRows = found ? externalLinksOf(showRow) : []
  132. hasLinks = linkRows.length > 0
  133. // NOT from `showRow`/`found`: they read the session (via `me`), so a member derived from them is re-derived on the server
  134. // after every session face with the MOUNT's state — `collapsed` (client state) would snap back to the initial seasons (mission
  135. // 056: the 2nd episode click in a re-opened season did nothing). The season ids of a hidden page are no secret.
  136. collapsed = initialCollapsedOf(slug)
  137. rows = found ? buildRows(showRow, me, collapsed) : []
  138. hasRows = rows.length > 0
  139. __title = found ? title + ' — ' + appTitle : appTitle
  140. View {
  141. showPage {
  142. if (notFound) {
  143. article { class = "main"
  144. h1 { "Not found" }
  145. p { "This show doesn't exist." }
  146. }
  147. }
  148. if (found) {
  149. showHeader {
  150. showPoster { if (hasPoster) { img { src = posterUrl alt = title } } }
  151. showMeta {
  152. showTitle {
  153. h1 { title }
  154. button { id = "follow" type = "button" class = followClass followText on click(e) { emit toggleFollow(e) } }
  155. }
  156. if (hasLinks) {
  157. showLinks {
  158. for (l of linkRows) { a { class = "extlink" href = l.href target = "_blank" rel = "noopener" title = l.title "aria-label" = l.title "data-site" = l.site l.label } }
  159. }
  160. }
  161. if (hasGenres) {
  162. showGenres {
  163. for (g of genreRows) { a { class = "genre-pill" href = g.href g.name } }
  164. }
  165. }
  166. showSummary { summary }
  167. if (hasCast) {
  168. showCast {
  169. for (c of castRows) { a { class = "artist-link" href = c.href c.name } }
  170. }
  171. }
  172. }
  173. }
  174. if (hasRows) {
  175. showSeasons {
  176. for (row of rows) {
  177. if (row.isSeason) {
  178. seasonRow { class = row.rowClass
  179. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark season watched"
  180. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  181. circle { cx = "12" cy = "12" r = "10" }
  182. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  183. }
  184. on click(e) { emit toggleSeason(row.id) }
  185. }
  186. button { type = "button" class = "season-toggle" value = row.id
  187. seasonLabel { row.label }
  188. seasonCount { row.episodeCountText }
  189. seasonCaret { "aria-hidden" = "true"
  190. svg { viewBox = "0 0 24 24" width = "20" height = "20"
  191. path { d = "M6 9 L12 15 L18 9" }
  192. }
  193. }
  194. on click(e) { emit toggleCollapse(row.id) }
  195. }
  196. }
  197. }
  198. if (row.isEpisode) {
  199. episodeRow {
  200. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark episode watched"
  201. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  202. circle { cx = "12" cy = "12" r = "10" }
  203. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  204. }
  205. on click(e) { emit toggleEpisode(row.id) }
  206. }
  207. episodeNumber { row.episodeNumber }
  208. episodeTitle { row.title }
  209. }
  210. }
  211. }
  212. }
  213. }
  214. Modal { id = "signin" title = "Sign in"
  215. p { "You need to sign in to follow shows and mark episodes." }
  216. footer {
  217. button { type = "button" value = "close" "Close" }
  218. a { id = "signin-link" class = "button" href = signInHref "Sign in with ident" }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. // Every rebuild of `rows` happens SERVER-SIDE, never by calling `buildRows` from a client handler:
  225. // a member function whose body reaches an hl:mpackdb-backed import (seasonsOfShow, episodesOfSeason,
  226. // watchesOfUser, …) compiles to nothing on the client (no case ever assigns it — a genuine Hybriel
  227. // gap, filed under `issues`) even though the client bundle still calls it, so `this.buildRows(...)`
  228. // throws "not a function" in the browser. The client here only ever ASSIGNS the `rows` the server
  229. // already built (`rows = r.rows`) — never calls a tainted local helper itself. `slug` goes along so
  230. // the face can refetch the show without depending on implicit access to a sibling member.
  231. on toggleCollapse(seasonId) {
  232. let r = emit server showRows(slug, seasonId, collapsed)
  233. if (r == null || r.error != null) { return null }
  234. collapsed = r.collapsed
  235. rows = r.rows
  236. }
  237. // signed out: the modal, nothing is sent
  238. on toggleEpisode(episodeId) {
  239. if (!signedIn) { document.getElementById('signin').showModal() return null }
  240. let r = emit server showToggleEpisode(slug, '' + episodeId, collapsed)
  241. if (r == null || r.error != null) { return null }
  242. rows = r.rows
  243. }
  244. on toggleSeason(seasonId) {
  245. if (!signedIn) { document.getElementById('signin').showModal() return null }
  246. let r = emit server showToggleSeason(slug, '' + seasonId, collapsed)
  247. if (r == null || r.error != null) { return null }
  248. rows = r.rows
  249. }
  250. on toggleFollow(e) {
  251. if (!signedIn) { document.getElementById('signin').showModal() return null }
  252. let r = emit server showToggleFollow(slug)
  253. if (r == null || r.error != null) { return null }
  254. following = r.following
  255. followClass = r.following ? 'follow' : 'follow inverted'
  256. followText = r.following ? 'Following' : 'Follow'
  257. }
  258. // ---- the faces (the trailing `session` is always the server's: hybriel#16) ----
  259. on server showRows(slug, seasonId, collapsed, session) {
  260. let show = showBySlug(slug)
  261. let uid = userIdOfSession(session)
  262. if (show == null || adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  263. let m = collapsed
  264. m[seasonId] = collapsed[seasonId] == true ? false : true
  265. return { ok = true collapsed = m rows = buildRows(show, uid, m) }
  266. }
  267. on server showToggleEpisode(slug, episodeId, collapsed, session) {
  268. let show = showBySlug(slug)
  269. if (show == null) { return { error = 'no such show' } }
  270. let uid = userIdOfSession(session)
  271. if (uid == null) { return { error = 'you are not signed in' } }
  272. if (adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  273. let rows = watchesOfUser(uid)
  274. let watched = isWatched(rows, 'episode', episodeId) == false
  275. let ok = setWatched(uid, 'episode', episodeId, rows, watched)
  276. if (!ok) { return { error = 'could not save the watch' } }
  277. return { ok = true rows = buildRows(show, uid, collapsed) }
  278. }
  279. on server showToggleSeason(slug, seasonId, collapsed, session) {
  280. let show = showBySlug(slug)
  281. if (show == null) { return { error = 'no such show' } }
  282. let uid = userIdOfSession(session)
  283. if (uid == null) { return { error = 'you are not signed in' } }
  284. if (adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  285. let season = seasonById(seasonId)
  286. if (season == null) { return { error = 'no such season' } }
  287. let rows = watchesOfUser(uid)
  288. let watched = isWatched(rows, 'season', seasonId) == false
  289. let ok = setSeasonWatched(uid, seasonId, season.episodes, rows, watched)
  290. if (!ok) { return { error = 'could not save the watch' } }
  291. return { ok = true rows = buildRows(show, uid, collapsed) }
  292. }
  293. on server showToggleFollow(slug, session) {
  294. let show = showBySlug(slug)
  295. if (show == null) { return { error = 'no such show' } }
  296. let uid = userIdOfSession(session)
  297. if (uid == null) { return { error = 'you are not signed in' } }
  298. let follow = isFollowing(uid, show.id) == false
  299. if (!setFollowed(uid, show.id, follow)) { return { error = 'could not save the follow' } }
  300. return { ok = true following = follow }
  301. }

Branches

Latest commits

  • f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
  • f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
  • 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
  • 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
  • c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
  • 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
  • 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
  • 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
  • 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre
  • cbdc4ea7tracker#12: link icons TMDB/IMDb/TVDB/TVmaze; sync fills missing ids (TVmaze lookup); movies fetched via /movie/mre
  • b105bcd8tracker#11: Hybriel master ff51cf46 (checks no longer vanish), mobile-first styles, carets, follow button, sign-in modal, inverted check, orange castmre
  • 31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre
  • 2fa9d997tracker#9: TMDB sync (followed shows: seasons, episodes, posters), tools/sync-tmdb.hl + daily run 04:00 UTC, fake TMDB in gatemre
  • 49e1f61edeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre