gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit52e09eb252e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre52e09eb2/components/show.hl

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

Branches

Latest commits

  • 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
  • c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
  • 593a6350boot: resumable start-up scan, the server listens first (T17)mre
  • be4890a0reports: H2 hydration audit (no test change needed)mre
  • 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
  • d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
  • 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
  • 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
  • 4625aa22re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • a6dfd6ecdeploy: person-lookup gate (tracker#46)mre
  • 33ad4bd5Merge commit 'f57f64f'mre
  • 7d38cec4docker-compose: nofile 65536 (default soft 1024 refused boot: errno 24 in fs.listDir, Hybriel 528bc89f)mre
  • f57f64f0mission 046: report, LOGmre
  • 5965963adeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • efe1b485mission 046: re-vendor Hybriel master 60b2817b (integration 8, #203): plugins mpackdb + web (bin/ git-ignored: hybriel, libhlrt.a, hlc.o, hlrt/ from native/zig-out)mre
  • 53099ffbmission 046: person page reads a slim per-title credit row cache (no whole-record fetch per credit); gate tests/person-lookup.mjsmre
  • 9b3828aemission 046a: report, LOGmre
  • 4b37356emission 046: franchise seed supersedeCollections reads the curated timelines once (10 s one-tick block at the end of boot)mre
  • ac6268e3mission 046a: re-vendor Hybriel 528bc89f (integration 6): plugins mpackdb/time/web (bin/ git-ignored)mre