gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit641f3b54641f3b54Tracker: Apollo answermre641f3b54/components/show.hl

42.2 KB

  1. // components/show.hl — a title's own page (tracker.worldapi.org#4): since tracker#21 (mission 068) `/series/:slug`, `/movies/:slug`
  2. // and `/shows/:slug` (the last through project.hl showsRoute: a show is rendered there, a series or movie answers 301 to its
  3. // own address). tracker#20: the heading is "<Type> | <title>" — Series / Show / Movie in the type's colour (styles.hl
  4. // `type-*`), the title white. Creator's words:
  5. // "the poster on the left, right of it the title of the show, the genre pills, below the plot summary,
  6. // below that the artists just as normal links, separated with comma color red, genres are blue" (the
  7. // header) — "then all seasons in reverse order, latest on top, below them collapsable their episodes,
  8. // episodes first the round check icon, if the episode was watched by the user looking its solid, if
  9. // not its regular, then the episode number, then the title. the last season is not collapsed. click on
  10. // the check adds a watch. the season also has a check, if the season is checked or unchecked all its
  11. // episodes get checked or unchecked. artists link to /person/<artist-slug> the genre to /genre/<genre-slug>."
  12. //
  13. // THE ROWS ARE ONE FLAT LIST, not a nested for-loop over seasons > episodes: the vendored build may
  14. // still lack the fix for hybriel#86 (a nested for over a reassigned outer list keeps stale inner
  15. // cells) — a single-level `for (row of rows)` with a `kind` field, reassigned whole on every click,
  16. // is the same proven-safe shape components/main.hl's own header and ident's inbox.hl already use.
  17. // `rows` is rebuilt from scratch (seasons/episodes refetched by id, watch rows refetched) on every
  18. // toggle — cheap: a show has at most a few dozen episodes per season.
  19. //
  20. // Mission 047 (the creator, 2026-10-01): a caret at the season header's right edge (down = open, right = collapsed); episode
  21. // rows not indented; on a phone the title first, then the poster at full width, then genres/plot/cast; a Follow toggle
  22. // next to the title (tracker#34, mission 030: under the poster, as wide as the poster; next to the title the status pill, #35). SIGNED OUT the checks and Follow are visible too: a click opens the "sign in" modal (modal.hl, copied
  23. // from components.hybriel) and writes nothing.
  24. //
  25. // tracker.worldapi.org#17 (mission 057): the caret points DOWN while a season is closed and UP while it is open. Opening a
  26. // season shows SKELETON rows at once (min(episodes, 8), a CSS shimmer, styles.hl) and then its episodes from the face
  27. // `showSeasonEpisodes`, which takes NO session: a face with `session` makes hl:web re-mount the whole page on the server and
  28. // ship every session-derived member back as a `sync` (WebFramework.hl `inbound`) — that, not the episodes, was most of the
  29. // old 250–450 ms (real data). The watched state comes from `watchedEpisodes` (this show's watched episodes per season, rendered
  30. // with the page and re-synced after every watch face). Closing is client-only (no request). An ADULT show (only its
  31. // followers see it) keeps the session face `showRows`: the public face refuses adult seasons.
  32. //
  33. // tracker.worldapi.org#12: link icons under the title — the show on TMDB, IMDb, TheTVDB, TVmaze (a movie: TMDB + IMDb),
  34. // only for the ids it has (shows.hl externalLinksOf), each in a new tab.
  35. //
  36. // mission 058: #22 every episode row shows its air date (`release`, 'YYYY-MM-DD' like /my/unwatched; none → empty). #23 a
  37. // season's check is DERIVED: solid exactly when every one of its episodes is watched (a season without episodes: its own
  38. // season watch) — unchecking one episode turns the season off with the face's answer, checking it again turns it on; the
  39. // season click watches all when not all are watched, else unwatches all. #24 a MOVIE's page has its own watched check
  40. // (watch `targetType = 'movie'`, target = the title's id; face `showToggleMovie`), signed out → the sign-in modal.
  41. //
  42. // tracker.worldapi.org#26: an INCOMPLETE title (one a person page added from a filmography — details.hl `needsDetails`) shows
  43. // what it has plus skeletons (poster, cast line, season rows for a series) and completes itself WITHOUT a reload: the
  44. // invisible `showProbe` (endless short CSS animation — hl:web has no mount hook, the person page's trick) calls the face
  45. // `showComplete` until it is done — one step per call (details.hl completeStep: TMDB details + ids + cast; a series' seasons/
  46. // episodes in parts; poster, TVmaze) — and the last answer's parts replace the skeletons. No session (no page re-mount); adult
  47. // refused.
  48. //
  49. // tracker.worldapi.org#28: the WHOLE cast and the key crew (details.hl stores them: a series' cast of every season, main cast
  50. // first by episode count, then "Guest stars"; crew = Created by / Directed by / Written by / Screenplay / Story / Music). The
  51. // cast shows its first `castShown` (20) and a "Show all (N)" toggle, each crew job its first `crewShown` (6) and one "Show all
  52. // crew (N)" toggle — CLIENT-SIDE (the rows are all rendered, CSS hides the rest; `castClass`/`crewClass`, no request). Names
  53. // link to /person/<slug>; the character in brackets after the name (CSS `attr(data-role)` — one element per name: the SSR's
  54. // line breaks inside a wrapper element put a space before the comma).
  55. parent './main.hl'
  56. import Modal from './modal.hl'
  57. import FranchiseWidget from './franchisewidget.hl'
  58. import { appTitle } from '../project.hl'
  59. import { userIdOfSession, loginHref } from '../lib/users.hl'
  60. import { isFollowing, toggleFollowed } from '../lib/follows.hl'
  61. import { showBySlug, showById, genreById, personLinkOf, seasonsOfShow, episodesOfSeason, seasonById, episodeById, posterName, externalLinksOf, summaryOf, titleKind, statusOf, titlePath } from '../lib/shows.hl'
  62. import { watchesOfUser, isWatched, watchedSet, watchClassOf, seasonAllWatched, toggleWatched, toggleSeasonWatched } from '../lib/watches.hl'
  63. import { needsDetails, completeStep, completeLine, persistDetails } from '../lib/details.hl'
  64. import { widgetsOf } from '../lib/franchises.hl'
  65. import { listOr, textArg } from '../lib/util.hl'
  66. import { dateText } from '../lib/people.hl'
  67. import { warmReady, warmText } from '../lib/warm.hl'
  68. // ---- pure helpers ----------------------------------------------------------------------------
  69. // `static`, like calendar.hl's `soonOf` — a PLAIN instance member function that calls an
  70. // hl:mpackdb-backed import (seasonsOfShow, episodesOfSeason, watchesOfUser, …) comes back null
  71. // when called from an `on server` face (confirmed by running the gate: "'buildRows' is not
  72. // callable — it holds null" at the face's call site, even though the SAME call works fine as a
  73. // member's own initializer at the top of this file). `static` is the proven-safe shape (calendar's
  74. // `soonOf`, called from `calLoad`/`calSettingsLoad`, an mpackdb-backed helper exactly like this one).
  75. static initialCollapsed = (&seasons) => {
  76. m = {}
  77. let i = 0
  78. while (i < seasons.length) {
  79. // mobile audit MK: a season of more than 150 episodes starts closed too (a soap whose 1,175 episodes are ONE season made a 69,000 px page
  80. // of 1,200 tap targets); a tap on its header opens it
  81. if (i > 0 || seasons[i].episodes.length > 150) { m[seasons[i].id] = true }
  82. i = i + 1
  83. }
  84. return m
  85. }
  86. static genreRowsOf = (&show) => {
  87. out = []
  88. for (gid of show.genres) {
  89. let g = genreById(gid)
  90. if (g != null) { out.push({ id = g.id name = g.name href = '/genres/' + g.urlSegment }) }
  91. }
  92. return out
  93. }
  94. // tracker#28: how many names show before "Show all" (cast; per crew job)
  95. static castShown = 20
  96. static crewShown = 6
  97. // the cast as flat rows (no nested for, see THE ROWS above; tracker#42: people by shows.hl personLinkOf, not whole records): `isPerson` rows { name, href, roleText (' (Character)' or ''),
  98. // itemClass } and before the first guest one `isLabel` row "Guest stars". itemClass: `more` = hidden until "Show all", `end` =
  99. // no comma after it (the last of a group), `cut` = the last one shown while collapsed (no comma then)
  100. static castRowsOf = (show) => {
  101. people = []
  102. for (c of listOr(show.cast)) {
  103. let p = c != null && c.person != null ? personLinkOf(c.person) : null
  104. // mission 062: a guest without a person record — the link creates it on the first open (project.hl guestRoute)
  105. if (p != null) { people.push({ name = c.actor != null ? c.actor : p.name href = '/person/' + p.urlSegment role = c.character != null ? c.character : '' guest = c.guest == true }) }
  106. else if (c != null && c.person == null && c.tmdbId != null && c.actor != null) { people.push({ name = c.actor href = '/person/tmdb/' + c.tmdbId + '?show=' + show.id role = c.character != null ? c.character : '' guest = true }) }
  107. }
  108. out = []
  109. let k = 0
  110. let guests = false
  111. while (k < people.length) {
  112. let c = people[k]
  113. if (c.guest && !guests && k > 0) {
  114. guests = true
  115. out.push({ isLabel = true isPerson = false text = 'Guest stars' name = '' href = '' roleText = '' itemClass = k >= castShown ? 'more' : '' })
  116. }
  117. let last = k == people.length - 1 || (people[k + 1].guest && !c.guest)
  118. let cls = (k >= castShown ? ' more' : '') + (last ? ' end' : '') + (k == castShown - 1 ? ' cut' : '')
  119. out.push({ isLabel = false isPerson = true text = '' name = c.name href = c.href roleText = c.role != '' ? ' (' + c.role + ')' : '' itemClass = 'artist-link' + cls })
  120. k = k + 1
  121. }
  122. return out
  123. }
  124. static castCountOf = (&rows) => {
  125. let n = 0
  126. for (r of rows) { if (r.isPerson) { n = n + 1 } }
  127. return n
  128. }
  129. static crewLabels = { creator = 'Created by' director = 'Directed by' writer = 'Written by' screenplay = 'Screenplay' story = 'Story' composer = 'Music' }
  130. // the crew as flat rows: per job (in stored order) an `isLabel` row, then its people (itemClass as for the cast, `more` after
  131. // the first crewShown of a job)
  132. static crewRowsOf = (&show) => {
  133. people = []
  134. for (c of listOr(show.crew)) {
  135. let p = c != null ? personLinkOf(c.person) : null
  136. if (p != null && crewLabels[c.job] != null) { people.push({ name = c.name != null ? c.name : p.name href = '/person/' + p.urlSegment job = c.job }) }
  137. }
  138. out = []
  139. let k = 0
  140. let inJob = 0
  141. while (k < people.length) {
  142. let c = people[k]
  143. if (k == 0 || people[k - 1].job != c.job) {
  144. inJob = 0
  145. out.push({ isLabel = true isPerson = false text = crewLabels[c.job] name = '' href = '' itemClass = '' })
  146. }
  147. let last = k == people.length - 1 || people[k + 1].job != c.job
  148. out.push({ isLabel = false isPerson = true text = '' name = c.name href = c.href itemClass = 'crew-link' + (inJob >= crewShown ? ' more' : '') + (last ? ' end' : '') + (inJob == crewShown - 1 ? ' cut' : '') })
  149. inJob = inJob + 1
  150. k = k + 1
  151. }
  152. return out
  153. }
  154. // how many crew names are hidden while collapsed (0 = no toggle) and how many there are
  155. static crewHiddenOf = (&rows) => {
  156. let n = 0
  157. for (r of rows) { if (r.isPerson && r.itemClass.includes(' more')) { n = n + 1 } }
  158. return n
  159. }
  160. static crewCountOf = (&rows) => {
  161. let n = 0
  162. for (r of rows) { if (r.isPerson) { n = n + 1 } }
  163. return n
  164. }
  165. // a View attribute must be a literal, a member or a field path — never an inline expression — so
  166. // every ternary (watched -> icon class, collapsed -> row class) is resolved HERE, once, into a
  167. // plain field the View just reads (row.watchClass, row.rowClass); `watchClassOf` itself lives in
  168. // watches.hl (shared with /unwatched and /schedule, "reuse, don't copy")
  169. // #22: an episode's air date as the lists show it ('YYYY-MM-DD'), '' when it has none
  170. static airDateOf = (&e) => { return e.release != null && hlTypeName(e.release) == 'String' ? e.release : '' }
  171. static buildRows = (&show, &uid, collapsed) => {
  172. watched = watchedSet(uid != null ? watchesOfUser(uid) : [])
  173. out = []
  174. for (s of seasonsOfShow(show)) {
  175. let isCollapsed = collapsed[s.id] == true
  176. let label = s.title != null && s.title != '' ? s.title : 'Season ' + s.seasonNumber
  177. let seasonWatched = seasonAllWatched(s, watched)
  178. out.push({ kind = 'season' isSeason = true isEpisode = false isSkeleton = false id = s.id skeletonCount = s.episodes.length < 8 ? s.episodes.length : 8 label = label episodeCountText = s.episodes.length == 1 ? '1 episode' : s.episodes.length + ' episodes' watched = seasonWatched watchClass = watchClassOf(seasonWatched) collapsed = isCollapsed rowClass = isCollapsed ? 'collapsed' : 'expanded' })
  179. if (!isCollapsed) {
  180. for (e of episodesOfSeason(s)) {
  181. let epWatched = watched['episode:' + e.id] == true
  182. out.push({ kind = 'episode' isSeason = false isEpisode = true isSkeleton = false id = e.id seasonId = s.id episodeNumber = e.episodeNumber title = e.title != null ? e.title : '' airDate = airDateOf(e) watched = epWatched watchClass = watchClassOf(epWatched) })
  183. }
  184. }
  185. }
  186. return out
  187. }
  188. // what the client marks the rows of a season it opens with (tracker#17) — only this show's, never the user's whole watch
  189. // list (every member is shipped to the browser). Per season with a watched episode: `{ all, except }` — `all` = most of
  190. // it is watched, then `except` holds the UNwatched ids, else the watched ones (a fully watched 142-episode season is
  191. // `{ all = true except = {} }`, not 142 ids). No entry = nothing watched.
  192. static watchedEpisodesOf = (&show, &uid) => {
  193. m = {}
  194. if (uid == null) { return m }
  195. watched = watchedSet(watchesOfUser(uid))
  196. for (s of seasonsOfShow(show)) {
  197. let yes = {}
  198. let no = {}
  199. let n = 0
  200. for (eid of s.episodes) {
  201. if (watched['episode:' + eid] == true) { yes[eid] = true n = n + 1 } else { no[eid] = true }
  202. }
  203. if (n > 0) { m[s.id] = n * 2 > s.episodes.length ? { all = true except = no } : { all = false except = yes } }
  204. }
  205. return m
  206. }
  207. // is this episode watched, by that per-season shape (client-side, pure)
  208. static watchedIn = (&entry, &episodeId) => {
  209. if (entry == null) { return false }
  210. listed = entry.except[episodeId] == true
  211. return entry.all ? !listed : listed
  212. }
  213. // ---- the rows as the CLIENT changes them (tracker#17) — pure: no import is reached, so they run in the browser ----------
  214. // (`watchClassOf` is an import of the mpackdb-backed watches.hl, so `filledRows` writes its two classes itself)
  215. static seasonRowAs = (&row, &isCollapsed) => {
  216. return { kind = 'season' isSeason = true isEpisode = false isSkeleton = false id = row.id skeletonCount = row.skeletonCount label = row.label episodeCountText = row.episodeCountText watched = row.watched watchClass = row.watchClass collapsed = isCollapsed rowClass = isCollapsed ? 'collapsed' : 'expanded' }
  217. }
  218. // the season opened: its caret up at once, `skeletonCount` placeholder rows under it
  219. static openingRows = (&rows, seasonId) => {
  220. out = []
  221. for (row of rows) {
  222. if (row.isSeason && row.id == seasonId) {
  223. out.push(seasonRowAs(row, false))
  224. let i = 0
  225. while (i < row.skeletonCount) {
  226. out.push({ kind = 'skeleton' isSeason = false isEpisode = false isSkeleton = true id = seasonId + '-skeleton-' + i seasonId = seasonId })
  227. i = i + 1
  228. }
  229. } else { out.push(row) }
  230. }
  231. return out
  232. }
  233. // the season closed: its episode (and skeleton) rows gone, caret down
  234. static closedRows = (&rows, &seasonId) => {
  235. out = []
  236. for (row of rows) {
  237. if (row.isSeason && row.id == seasonId) { out.push(seasonRowAs(row, true)) }
  238. else if (!row.isSeason && row.seasonId == seasonId) { }
  239. else { out.push(row) }
  240. }
  241. return out
  242. }
  243. // the episodes arrived: they replace the season's skeleton rows. No skeleton of it left (closed meanwhile, or a watch face
  244. // already rebuilt every row) → the rows stay as they are (no double rows)
  245. static filledRows = (&rows, seasonId, &episodes, watched) => {
  246. out = []
  247. let done = false
  248. for (row of rows) {
  249. if (row.isSkeleton && row.seasonId == seasonId) {
  250. if (!done) {
  251. for (e of episodes) {
  252. let w = watchedIn(watched[seasonId], e.id)
  253. out.push({ kind = 'episode' isSeason = false isEpisode = true isSkeleton = false id = e.id seasonId = seasonId episodeNumber = e.episodeNumber title = e.title airDate = e.airDate watched = w watchClass = w ? 'checkicon solid' : 'checkicon regular' })
  254. }
  255. done = true
  256. }
  257. } else { out.push(row) }
  258. }
  259. return out
  260. }
  261. // a LOCAL static like buildRows (an imported mpackdb helper called straight from a member's initializer came back false
  262. // after a client-side navigation to the page — the gate's follow check)
  263. static followingOf = (&show, &uid) => { return uid != null && isFollowing(uid, show.id) }
  264. // #24: has this user watched this movie (a watch `movie:<title id>`)?
  265. static movieWatchedOf = (&show, &uid) => { return uid != null && isWatched(watchesOfUser(uid), 'movie', show.id) }
  266. // mission 056: an ADULT title's page (TMDB's flag `adult == true`, mission 054) is "Not found" for everyone who does not
  267. // follow it (signed out too); a follower sees it as before. Unknown (`null`) is not hidden here — only in the lists.
  268. // With hybriel ≥ 73267707 (#121/#122) `showRow`/`found` are server sites re-derived after every session face with the page's
  269. // 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).
  270. // Mission 054's try (`found = … && !adultHiddenFor(showRow, me)`, `collapsed`/`rows` from `found`) broke the checks.
  271. static adultHiddenFor = (&show, &uid) => { return show.adult == true && !followingOf(show, uid) }
  272. // 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
  273. // row of a hidden title must never be one
  274. static visibleShow = (&slug, &uid) => {
  275. s = showBySlug(slug)
  276. return s != null && adultHiddenFor(s, uid) ? null : s
  277. }
  278. // tracker.worldapi.org#19 (mission 066): the franchise widget(s), one per timeline the title is in (components/franchisewidget.hl)
  279. static franchiseWidgetsOf = (&show) => { return widgetsOf(show.id) }
  280. // tracker#33 (mission 032): a movie's release date and runtime under its title — "17 September 2026 · 7 min", "… · 2 h 15 min";
  281. // what is missing is left out ('' = no line)
  282. static runtimeText = (&m) => {
  283. if (m == null || hlTypeName(m) != 'Number' || m <= 0) { return '' }
  284. mins = m % 60
  285. hours = (m - mins) / 60
  286. if (hours == 0) { return mins + ' min' }
  287. return mins == 0 ? hours + ' h' : hours + ' h ' + mins + ' min'
  288. }
  289. static movieFactsOf = (&s) => {
  290. if (s.type != 'movie') { return '' }
  291. parts = []
  292. d = dateText(s.release)
  293. if (d != null) { parts.push(d) }
  294. r = runtimeText(s.runtime)
  295. if (r != '') { parts.push(r) }
  296. return parts.join(' · ')
  297. }
  298. // mission 062: what the page shows of the title, as a SMALL object — `showRow` reads the session, so hl:web ships it with the page
  299. // AND re-sends it after every watch/follow click (SESSION SYNC below): the whole record was ~1 MB on The Simpsons (300 cast + crew
  300. // entries). null = not found / hidden.
  301. static pageShowOf = (&slug, &uid) => {
  302. s = visibleShow(slug, uid)
  303. if (s == null) { return null }
  304. movie = s.type == 'movie'
  305. st = statusOf(s)
  306. return { id = s.id title = s.title summary = summaryOf(s) type = s.type adult = s.adult == true shortId = s.shortId != null ? '' + s.shortId : '' statusText = st.text statusTone = st.tone
  307. poster = posterName(s) genreRows = genreRowsOf(s) linkRows = externalLinksOf(s) completing = completingOf(s) following = followingOf(s, uid)
  308. movieWatched = movie ? movieWatchedOf(s, uid) : false facts = movieFactsOf(s) }
  309. }
  310. // the seasons/episodes rows and the per-season watch state by the slug (the record itself stays on the server)
  311. static rowsOfSlug = (&slug, &uid, &collapsed) => {
  312. s = showBySlug(slug)
  313. return s != null ? buildRows(s, uid, collapsed) : []
  314. }
  315. static watchedEpisodesOfSlug = (&slug, &uid) => {
  316. s = showBySlug(slug)
  317. return s != null ? watchedEpisodesOf(s, uid) : {}
  318. }
  319. // the initial open/closed seasons and the title's kind (tracker#20/#21: the heading's type word) from the SLUG alone (not from
  320. // `showRow`, which reads the session — see `collapsed`) — one slug lookup for both
  321. static slugInfoOf = (&slug) => {
  322. s = showBySlug(slug)
  323. return s != null ? { collapsed = initialCollapsed(seasonsOfShow(s)) kind = titleKind(s) canonical = titlePath(s) } : { collapsed = {} kind = 'series' canonical = '' }
  324. }
  325. // mission 062: the cast and crew rows by the SLUG alone (not from `showRow`, which reads the session — see `castRows`). An
  326. // ADULT title (its page only for its followers) shows none: every member is shipped to the browser, and adult titles never get
  327. // credits anyway (details.hl skips them; at most a migrated cast)
  328. static publicShowOf = (&slug) => {
  329. s = showBySlug(slug)
  330. return s != null && s.adult != true ? s : null
  331. }
  332. static castOfSlug = (&slug) => {
  333. s = publicShowOf(slug)
  334. return s != null ? castRowsOf(s) : []
  335. }
  336. static crewOfSlug = (&slug) => {
  337. s = publicShowOf(slug)
  338. return s != null ? crewRowsOf(s) : []
  339. }
  340. // tracker#26: the page loads this title's full details on open
  341. static completingOf = (&show) => { return needsDetails(show) }
  342. // the face's work: ONE step of completing the title (details.hl completeStep — a series takes a few; a second viewer drives the
  343. // same job or finds it complete); when done, every part of the page that changes — the rows without anyone's watch state (a
  344. // title that was incomplete had no episodes to watch)
  345. static completedPageOf = (&slug) => {
  346. let show = showBySlug(slug)
  347. if (show == null || show.adult == true) { return { error = 'no such show' } }
  348. if (needsDetails(show)) {
  349. let r = completeStep(show.id)
  350. if (r.retry || r.adult == true) { return { error = r.error != '' ? r.error : 'no such show' } }
  351. if (!r.done) { return { done = false steps = r.sum.steps } }
  352. if (!r.skipped) {
  353. persistDetails()
  354. console.log('details on open: ' + completeLine(show.title, r.sum))
  355. }
  356. show = showById(show.id)
  357. }
  358. cl = initialCollapsed(seasonsOfShow(show))
  359. pn = posterName(show)
  360. crew = crewRowsOf(show)
  361. cast = castRowsOf(show)
  362. return { done = true title = show.title summary = summaryOf(show) poster = pn genreRows = genreRowsOf(show) castRows = cast
  363. castCount = castCountOf(cast) castMore = castCountOf(cast) > castShown crewRows = crew crewCount = crewCountOf(crew) crewMore = crewHiddenOf(crew) > 0
  364. linkRows = externalLinksOf(show) collapsed = cl rows = buildRows(show, null, cl) }
  365. }
  366. // ---- reactive members -----------------------------------------------------------------------
  367. slug = null
  368. session = null
  369. userId = userIdOfSession(session)
  370. signedIn = userId != null
  371. // SESSION SYNC (mission 047; since hybriel #121/#122, mission 056): a face taking `session` answers with a `sync` of every
  372. // member derived from session that reaches an import (here `showRow`, `found`, `following`, `rows`, …), re-derived on the
  373. // server with the page's route params but the MOUNT's other state — so client state (`collapsed`) must never derive from
  374. // them. `me` stays the plain copy mission 047 introduced.
  375. me = userId
  376. showRow = pageShowOf(slug, me)
  377. found = showRow != null
  378. notFound = showRow == null
  379. // the Follow toggle: "Follow" = the inverted button (accent text on a surface, no border since tracker#32), "Following" = the
  380. // filled one (the theme's `primary`)
  381. following = found ? showRow.following : false
  382. followClass = following ? 'follow primary' : 'follow inverted'
  383. followText = following ? 'Following' : 'Follow'
  384. signInHref = loginHref
  385. // #24: a movie's watched check (same icon/classes as the episodes); the classes written out, not `watchClassOf` (an import of
  386. // the mpackdb-backed watches.hl cannot run in the browser when the member is re-derived there)
  387. isMovie = found && showRow.type == 'movie'
  388. movieWatched = isMovie ? showRow.movieWatched : false
  389. movieWatchClass = movieWatched ? 'checkicon solid' : 'checkicon regular'
  390. movieWatchText = movieWatched ? 'Watched' : 'Not watched'
  391. signInText = isMovie ? 'You need to sign in to follow movies and mark them watched.' : 'You need to sign in to follow shows and mark episodes.'
  392. title = found ? showRow.title : ''
  393. // tracker#35: the status pill next to a series' title — TVmaze's status, else TMDB's (shows.hl statusOf); none on a movie
  394. statusText = found ? showRow.statusText : ''
  395. hasStatus = statusText != ''
  396. // tracker#33: a movie's release date + runtime (movieFactsOf)
  397. factsText = found ? showRow.facts : ''
  398. hasFacts = factsText != ''
  399. statusClass = found ? 'pill ' + (showRow.statusTone == 'running' ? 'success' : (showRow.statusTone == 'pending' ? 'warning' : ((showRow.statusTone == 'canceled' || showRow.statusTone == 'ended') ? 'danger' : 'quiet'))) : 'pill quiet'
  400. // tracker#20: "Series | Reacher" — the kind from the slug (pure strings here: they are re-derived in the browser too)
  401. slugInfo = slugInfoOf(slug)
  402. pageKind = slugInfo.kind
  403. typeText = pageKind == 'movie' ? 'Movie' : (pageKind == 'show' ? 'Show' : 'Series')
  404. typeClass = 'type-word type-' + pageKind
  405. // tracker#18: the creator's own text, else TMDB's, else TVmaze's (pageShowOf → shows.hl summaryOf)
  406. summary = found && showRow.summary != null ? showRow.summary : ''
  407. poster = found ? showRow.poster : null
  408. hasPoster = poster != null
  409. posterUrl = hasPoster ? '/posters/' + poster : ''
  410. // mission 060 (tracker.worldapi.org#27): the short id under the poster (none yet while the backfill has not reached it)
  411. shortId = found ? showRow.shortId : ''
  412. hasShortId = shortId != ''
  413. genreRows = found ? showRow.genreRows : []
  414. hasGenres = genreRows.length > 0
  415. // mission 062: cast + crew from the SLUG (`castOfSlug`, `crewOfSlug`), never from `showRow` — a member derived from the session is
  416. // re-derived and re-SENT after every watch/follow click (SESSION SYNC above): The Simpsons' 300 names took 0.7 s per click
  417. castRows = castOfSlug(slug)
  418. hasCast = castRows.length > 0
  419. // tracker#28: "Show all (N)" — the toggles' state is CLIENT state: literals, never derived from `showRow` (session sync)
  420. castCount = castCountOf(castRows)
  421. castMore = castCount > castShown
  422. castAllText = 'Show all (' + castCount + ')'
  423. castClass = 'collapsed'
  424. crewRows = crewOfSlug(slug)
  425. hasCrew = crewRows.length > 0
  426. crewCount = crewCountOf(crewRows)
  427. crewMore = crewHiddenOf(crewRows) > 0
  428. crewAllText = 'Show all crew (' + crewCount + ')'
  429. crewClass = 'collapsed'
  430. linkRows = found ? showRow.linkRows : []
  431. franchiseWidgets = found ? franchiseWidgetsOf(showRow) : []
  432. hasLinks = linkRows.length > 0
  433. // NOT from `showRow`/`found`: they read the session (via `me`), so a member derived from them is re-derived on the server
  434. // after every session face with the MOUNT's state — `collapsed` (client state) would snap back to the initial seasons (mission
  435. // 056: the 2nd episode click in a re-opened season did nothing). The season ids of a hidden page are no secret.
  436. collapsed = slugInfo.collapsed
  437. // mission 062: has this page opened/closed a season (client state) — then a watch face sends its own rows (toggleEpisode)
  438. collapsedChanged = false
  439. rows = found ? rowsOfSlug(slug, me, collapsed) : []
  440. hasRows = rows.length > 0
  441. watchedEpisodes = found ? watchedEpisodesOfSlug(slug, me) : {}
  442. // an adult page (followers only) opens its seasons through the session face `showRows`
  443. adultShow = found && showRow.adult == true
  444. // tracker#26: incomplete → skeletons + the probe until `showComplete` answered
  445. completing = found ? showRow.completing : false
  446. // tracker#33: a title TMDB has no poster for (The Remaining) shows the placeholder in the poster's place — the column was empty
  447. // but for the short id, the page looked unfinished; while an incomplete title loads, the skeleton instead
  448. posterLoading = completing && !hasPoster
  449. noPoster = !hasPoster && !completing
  450. completeBusy = false
  451. isSeries = found && showRow.type != 'movie'
  452. skeletonSeasons = ['1', '2', '3']
  453. __title = found ? title + ' — ' + appTitle : appTitle
  454. // tracker#41 (mission 037b): the title's own address (og:url in the served head) — under a moved slug (a merged duplicate's, a
  455. // former one: lib/shows.hl showBySlug finds the keeper) this page IS the keeper's, and the head names the keeper's address; hl:web
  456. // has no page-level <link rel="canonical">. From the slug alone (slugInfo), not from the session.
  457. canonicalPath = slugInfo.canonical
  458. __meta = canonicalPath != '' ? [{ property = 'og:url' content = canonicalPath }] : []
  459. // mission T17 (boot time): the server listens while bootscan.hl still builds the lists / slug maps / search index (lib/warm.hl); until the 'titles'
  460. // stage is there this page says so instead of showing half a map
  461. warming = !warmReady('titles')
  462. warmNote = warming ? warmText() : ''
  463. View {
  464. showPage {
  465. if (warming) { p { id = "warming" class = "message banner" warmNote } }
  466. if (notFound) {
  467. article { class = "main"
  468. h1 { "Not found" }
  469. p { "This show doesn't exist." }
  470. }
  471. }
  472. if (found) {
  473. showHeader {
  474. showPoster {
  475. if (hasPoster) { img { src = posterUrl alt = title } }
  476. if (noPoster) { img { class = "no-poster" src = "/posters/none" alt = "no poster" } }
  477. if (posterLoading) { skeletonPoster { "aria-hidden" = "true" } }
  478. // tracker#34: Follow directly under the poster, as wide as the poster (creator: "the follow button should go below
  479. // the picture … and expand to the size o the poster")
  480. button { id = "follow" type = "button" class = followClass followText on click(e) { emit toggleFollow(e) } }
  481. if (hasShortId) { shortIdLabel { id = "shortid" title = "Short id" shortId } }
  482. }
  483. showMeta {
  484. showTitle {
  485. h1 { class = "typed" typeWord { class = typeClass typeText } typeSep { "|" } typeName { title } }
  486. if (hasStatus) { span { class = statusClass statusText } }
  487. if (hasFacts) { showFacts { id = "moviefacts" factsText } }
  488. }
  489. if (isMovie) {
  490. movieWatch {
  491. button { id = "moviewatch" type = "button" class = movieWatchClass "aria-label" = "mark movie watched"
  492. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  493. circle { cx = "12" cy = "12" r = "10" }
  494. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  495. }
  496. on click(e) { emit toggleMovie(e) }
  497. }
  498. movieWatchLabel { movieWatchText }
  499. }
  500. }
  501. if (hasLinks) {
  502. showLinks {
  503. for (l of linkRows) { a { class = "pill quiet extlink" href = l.href target = "_blank" rel = "noopener" title = l.title "aria-label" = l.title "data-site" = l.site l.label } }
  504. }
  505. }
  506. // mission 025: the franchise widget right under the title/poster block — on a phone (showMeta dissolves, see styles.hl)
  507. // after the poster and before the genres, plot and cast; from 40rem in the right column under the title
  508. FranchiseWidget { widgets = franchiseWidgets }
  509. if (hasGenres) {
  510. showGenres {
  511. for (g of genreRows) { a { class = "pill type-4 genre-pill" href = g.href g.name } }
  512. }
  513. }
  514. showSummary { summary }
  515. if (hasCrew) {
  516. showCrew { class = crewClass
  517. for (r of crewRows) {
  518. if (r.isLabel) { crewLabel { r.text } }
  519. if (r.isPerson) { a { class = r.itemClass href = r.href r.name } }
  520. }
  521. if (crewMore) {
  522. button { id = "crewtoggle" type = "button" class = "quiet showall"
  523. whenCollapsed { crewAllText }
  524. whenAll { "Show less" }
  525. on click(e) { emit toggleCrewAll(e) }
  526. }
  527. }
  528. }
  529. }
  530. if (hasCast) {
  531. showCast { class = castClass
  532. castHeading { "Cast" }
  533. for (c of castRows) {
  534. if (c.isLabel) { castLabel { class = c.itemClass c.text } }
  535. if (c.isPerson) { a { class = c.itemClass href = c.href "data-role" = c.roleText c.name } }
  536. }
  537. if (castMore) {
  538. button { id = "casttoggle" type = "button" class = "quiet showall"
  539. whenCollapsed { castAllText }
  540. whenAll { "Show less" }
  541. on click(e) { emit toggleCastAll(e) }
  542. }
  543. }
  544. }
  545. }
  546. if (completing) { skeletonCast { "aria-hidden" = "true" } }
  547. }
  548. }
  549. if (completing) {
  550. showLoading { id = "showloading" "aria-busy" = "true"
  551. if (isSeries) {
  552. for (k of skeletonSeasons) {
  553. skeletonRow { "aria-hidden" = "true"
  554. skeletonCheck { }
  555. skeletonTitle { }
  556. }
  557. }
  558. }
  559. showProbe { "aria-hidden" = "true" on animationiteration(e) { emit completeTick(e) } }
  560. }
  561. }
  562. if (hasRows) {
  563. showSeasons {
  564. for (row of rows) {
  565. if (row.isSeason) {
  566. seasonRow { class = row.rowClass
  567. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark season watched"
  568. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  569. circle { cx = "12" cy = "12" r = "10" }
  570. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  571. }
  572. on click(e) { emit toggleSeason(row.id) }
  573. }
  574. button { type = "button" class = "season-toggle" value = row.id
  575. seasonLabel { row.label }
  576. seasonCount { row.episodeCountText }
  577. seasonCaret { "aria-hidden" = "true"
  578. svg { viewBox = "0 0 24 24" width = "20" height = "20"
  579. path { d = "M6 9 L12 15 L18 9" }
  580. }
  581. }
  582. on click(e) { emit toggleCollapse(row.id) }
  583. }
  584. }
  585. }
  586. if (row.isEpisode) {
  587. episodeRow {
  588. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark episode watched"
  589. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  590. circle { cx = "12" cy = "12" r = "10" }
  591. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  592. }
  593. on click(e) { emit toggleEpisode(row.id) }
  594. }
  595. episodeNumber { row.episodeNumber }
  596. episodeTitle { row.title }
  597. episodeDate { row.airDate }
  598. }
  599. }
  600. if (row.isSkeleton) {
  601. skeletonRow { "aria-hidden" = "true"
  602. skeletonCheck { }
  603. skeletonNumber { }
  604. skeletonTitle { }
  605. }
  606. }
  607. }
  608. }
  609. }
  610. Modal { id = "signin" title = "Sign in"
  611. p { signInText }
  612. footer {
  613. button { type = "button" value = "close" "Close" }
  614. a { id = "signin-link" class = "button primary" href = signInHref "Sign in with ident" }
  615. }
  616. }
  617. }
  618. }
  619. }
  620. // Every rebuild of `rows` happens SERVER-SIDE, never by calling `buildRows` from a client handler:
  621. // a member function whose body reaches an hl:mpackdb-backed import (seasonsOfShow, episodesOfSeason,
  622. // watchesOfUser, …) compiles to nothing on the client (no case ever assigns it — a genuine Hybriel
  623. // gap, filed under `issues`) even though the client bundle still calls it, so `this.buildRows(...)`
  624. // throws "not a function" in the browser. The client here only ever ASSIGNS the `rows` the server
  625. // already built (`rows = r.rows`) — never calls a tainted local helper itself. `slug` goes along so
  626. // the face can refetch the show without depending on implicit access to a sibling member.
  627. //
  628. // tracker#17: opening shows the skeleton rows BEFORE the request; the answer replaces them unless the season was closed
  629. // meanwhile (then nothing). An error closes the season again. Closing never asks the server.
  630. on toggleCollapse(seasonId) {
  631. collapsedChanged = true
  632. m = collapsed
  633. if (collapsed[seasonId] != true) {
  634. m[seasonId] = true
  635. collapsed = m
  636. rows = closedRows(rows, seasonId)
  637. return null
  638. }
  639. m[seasonId] = false
  640. collapsed = m
  641. rows = openingRows(rows, seasonId)
  642. if (adultShow) {
  643. let a = emit server showRows(slug, collapsed)
  644. if (collapsed[seasonId] == true) { return null }
  645. if (a == null || a.error != null) { m[seasonId] = true collapsed = m rows = closedRows(rows, seasonId) return null }
  646. rows = a.rows
  647. return null
  648. }
  649. let r = emit server showSeasonEpisodes('' + seasonId)
  650. if (collapsed[seasonId] == true) { return null }
  651. if (r == null || r.error != null) { m[seasonId] = true collapsed = m rows = closedRows(rows, seasonId) return null }
  652. rows = filledRows(rows, seasonId, r.episodes, watchedEpisodes)
  653. }
  654. // tracker#26: the probe's tick — `showComplete` step by step until `done` (once per page: `completeBusy`; other requests are
  655. // served between two calls); the last answer replaces the skeletons. A lost answer (null) lets the next tick go on where the
  656. // server is; an error (TMDB down, adult) ends the loading and keeps what the page has.
  657. on completeTick(e) {
  658. if (completeBusy || !completing) { return null }
  659. completeBusy = true
  660. s = slug
  661. let r = emit server showComplete(s)
  662. while (r != null && r.error == null && r.done != true && slug == s) { r = emit server showComplete(s) }
  663. completeBusy = false
  664. if (r == null || slug != s) { return null }
  665. if (r.error != null) { completing = false return null }
  666. title = r.title
  667. summary = r.summary
  668. poster = r.poster
  669. genreRows = r.genreRows
  670. castRows = r.castRows
  671. castCount = r.castCount
  672. castMore = r.castMore
  673. castAllText = 'Show all (' + r.castCount + ')'
  674. crewRows = r.crewRows
  675. crewCount = r.crewCount
  676. crewMore = r.crewMore
  677. crewAllText = 'Show all crew (' + r.crewCount + ')'
  678. linkRows = r.linkRows
  679. collapsed = r.collapsed
  680. collapsedChanged = true
  681. rows = r.rows
  682. completing = false
  683. }
  684. // tracker#28: the cast / crew "Show all" toggles — client-only, no request (CSS shows the hidden names)
  685. on toggleCastAll(e) {
  686. castClass = castClass == 'all' ? 'collapsed' : 'all'
  687. }
  688. on toggleCrewAll(e) {
  689. crewClass = crewClass == 'all' ? 'collapsed' : 'all'
  690. }
  691. // signed out: the modal, nothing is sent
  692. // mission 062: the new `rows` come with the SAME ack as the session sync (SESSION SYNC above: `rows` derives from the session) —
  693. // but that sync is built with the MOUNT's open seasons. So the face sends its own rows only once this page opened/closed a season
  694. // (`collapsedChanged`, or a completed title); else they came twice (a second buildRows + 14 kB on The Simpsons: ~40 ms per click)
  695. on toggleEpisode(episodeId) {
  696. if (!signedIn) { document.getElementById('signin').showModal() return null }
  697. let r = emit server showToggleEpisode(slug, '' + episodeId, collapsed, collapsedChanged)
  698. if (r == null || r.error != null) { return null }
  699. if (r.rows != null) { rows = r.rows }
  700. }
  701. on toggleSeason(seasonId) {
  702. if (!signedIn) { document.getElementById('signin').showModal() return null }
  703. let r = emit server showToggleSeason(slug, '' + seasonId, collapsed, collapsedChanged)
  704. if (r == null || r.error != null) { return null }
  705. if (r.rows != null) { rows = r.rows }
  706. }
  707. // #24: the movie's own check — signed out the modal, nothing sent
  708. on toggleMovie(e) {
  709. if (!signedIn) { document.getElementById('signin').showModal() return null }
  710. let r = emit server showToggleMovie(slug)
  711. if (r == null || r.error != null) { return null }
  712. movieWatched = r.watched
  713. movieWatchClass = r.watched ? 'checkicon solid' : 'checkicon regular'
  714. movieWatchText = r.watched ? 'Watched' : 'Not watched'
  715. }
  716. on toggleFollow(e) {
  717. if (!signedIn) { document.getElementById('signin').showModal() return null }
  718. let r = emit server showToggleFollow(slug)
  719. if (r == null || r.error != null) { return null }
  720. following = r.following
  721. followClass = r.following ? 'follow primary' : 'follow inverted'
  722. followText = r.following ? 'Following' : 'Follow'
  723. }
  724. // ---- the faces (the trailing `session` is always the server's: hybriel#16) ----
  725. // tracker#26: complete an incomplete title and answer the page's parts — public data, NO session (no page re-mount)
  726. on server showComplete(slug) {
  727. return completedPageOf(textArg(slug))
  728. }
  729. // every row for these open/closed seasons — only an ADULT show's page still uses it (its followers; tracker#17)
  730. on server showRows(slug, collapsed, session) {
  731. show = showBySlug(slug)
  732. uid = userIdOfSession(session)
  733. if (show == null || adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  734. return { ok = true rows = buildRows(show, uid, collapsed) }
  735. }
  736. // tracker#17: one season's episodes, in order — public data, so NO `session` (no page re-mount, no sync: the fast path).
  737. // Refuses a season of an adult title (those pages use showRows above).
  738. on server showSeasonEpisodes(seasonId) {
  739. if (seasonId == null || hlTypeName(seasonId) != 'String') { return { error = 'no such season' } }
  740. season = seasonById(seasonId)
  741. if (season == null) { return { error = 'no such season' } }
  742. show = showById(season.show)
  743. if (show == null || show.adult == true) { return { error = 'no such season' } }
  744. out = []
  745. for (e of episodesOfSeason(season)) { out.push({ id = e.id episodeNumber = e.episodeNumber title = e.title != null ? e.title : '' airDate = airDateOf(e) }) }
  746. return { ok = true episodes = out }
  747. }
  748. on server showToggleEpisode(slug, episodeId, collapsed, withRows, session) {
  749. show = showBySlug(slug)
  750. if (show == null) { return { error = 'no such show' } }
  751. uid = userIdOfSession(session)
  752. if (uid == null) { return { error = 'you are not signed in' } }
  753. if (adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  754. // mission SK: only an episode OF THIS SHOW — the id is the peer's (any text became a watch row before)
  755. ep = episodeId != null && hlTypeName(episodeId) == 'String' ? episodeById(episodeId) : null
  756. if (ep == null || ep.show != show.id) { return { error = 'no such episode' } }
  757. if (toggleWatched(uid, 'episode', episodeId) == null) { return { error = 'could not save the watch' } }
  758. return withRows == true ? { ok = true rows = buildRows(show, uid, collapsed) } : { ok = true }
  759. }
  760. on server showToggleSeason(slug, seasonId, collapsed, withRows, session) {
  761. show = showBySlug(slug)
  762. if (show == null) { return { error = 'no such show' } }
  763. uid = userIdOfSession(session)
  764. if (uid == null) { return { error = 'you are not signed in' } }
  765. if (adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  766. season = seasonId != null && hlTypeName(seasonId) == 'String' ? seasonById(seasonId) : null
  767. if (season == null || season.show != show.id) { return { error = 'no such season' } }
  768. // #23: not all episodes watched → watch them all; all watched → unwatch them all (lib/watches.hl)
  769. if (toggleSeasonWatched(uid, season) == null) { return { error = 'could not save the watch' } }
  770. return withRows == true ? { ok = true rows = buildRows(show, uid, collapsed) } : { ok = true }
  771. }
  772. // #24: a movie's watched check (only a movie: a series is watched by its episodes)
  773. on server showToggleMovie(slug, session) {
  774. show = showBySlug(slug)
  775. if (show == null || show.type != 'movie') { return { error = 'no such movie' } }
  776. uid = userIdOfSession(session)
  777. if (uid == null) { return { error = 'you are not signed in' } }
  778. if (adultHiddenFor(show, uid)) { return { error = 'no such movie' } }
  779. watched = toggleWatched(uid, 'movie', show.id)
  780. if (watched == null) { return { error = 'could not save the watch' } }
  781. return { ok = true watched = watched }
  782. }
  783. on server showToggleFollow(slug, session) {
  784. show = showBySlug(slug)
  785. if (show == null) { return { error = 'no such show' } }
  786. uid = userIdOfSession(session)
  787. if (uid == null) { return { error = 'you are not signed in' } }
  788. // mission SK: an adult title is its followers' only — nobody else may start following it (that opened its page to anyone who
  789. // guessed the slug); a follower may still stop
  790. if (adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  791. follow = toggleFollowed(uid, show.id)
  792. if (follow == null) { return { error = 'could not save the follow' } }
  793. return { ok = true following = follow }
  794. }

Branches

Latest commits

  • 641f3b54Tracker: Apollo answermre
  • 8b3cbddaTracker: status, TR7 fix livemre
  • ec30162aTracker: TR7 fix livemre
  • 54cbec80compose: ignore SIGPIPE (TR7 crash loop, exit 141)mre
  • 3e164b63Tracker: status after CL1mre
  • 9d686bb3Tracker: CL1 reviewedmre
  • b8bba562CL1: crash loop report (SIGPIPE confirmed, trap wrapper option)mre
  • 298785f2Tracker: CL1 startedmre
  • 36b22710Tracker: port slot, CL1 briefmre
  • a401190fTracker: GO for the crash loopmre
  • e195d372Tracker: token pathsmre
  • 7f541d11Tracker conductor: CONDUCTOR.md, short STATUS.md, old status + decisions archive to archive/2026-10-31mre
  • 8dd423f7README: login.js stays by caramboleyo's explicit rulemre
  • d8df1493tracker: standby service on port 45018 and a gap-free hand-over in deploy.sh step 4mre
  • 36dd1686ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • ff9b838etracker: the Ended status pill uses the same red as layouts (pill danger); gate updatedmre
  • 40d9719eTP2: LOG line and report for the tracker pillsmre
  • ab3f2ba5tracker: status, genres, TMDB/IMDb/TVDB/TVmaze links and list kinds use the theme's pill; dense season list with the season check centred on its title line; gates for bothmre
  • 521061d6tracker header on phones: signed in, the brand fits whole at 360 and 390 px (tighter gaps and side paddings, slightly smaller brand, narrow screens and signed in only); mobile gate checks itmre
  • 18114a53tracker: franchises gate waits for the signed-out selector instead of the removed Log in buttonmre