gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitdaf49feadaf49feaMerge t20 (tracker#20 typed headings + #21 series/shows split) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/search.hl/components/search.hl/browser.mjs/faketmdb.mjs, both sides kept; clock order backfill → repair → kinds → credits; withDetailsFields stores tmdbType + kind; gates: browser.mjs URLs → /series|/movies, typed h1 selectors; kinds.mjs repair/credits off, fixture name = seed name; browser 323/0, kinds 32/0mredaf49fea/components/show.hl

38.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. 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 { appTitle } from '../project.hl'
  58. import { userIdOfSession, loginHref } from '../users.hl'
  59. import { isFollowing, setFollowed } from '../follows.hl'
  60. import { showBySlug, showById, genreById, personById, seasonsOfShow, episodesOfSeason, seasonById, posterName, externalLinksOf, summaryOf, titleKind } from '../shows.hl'
  61. import { watchesOfUser, isWatched, watchedSet, setWatched, setSeasonWatched, watchClassOf } from '../watches.hl'
  62. import { needsDetails, completeStep, completeLine, persistDetails } from '../details.hl'
  63. // ---- pure helpers ----------------------------------------------------------------------------
  64. // `static`, like calendar.hl's `soonOf` — a PLAIN instance member function that calls an
  65. // hl:mpackdb-backed import (seasonsOfShow, episodesOfSeason, watchesOfUser, …) comes back null
  66. // when called from an `on server` face (confirmed by running the gate: "'buildRows' is not
  67. // callable — it holds null" at the face's call site, even though the SAME call works fine as a
  68. // member's own initializer at the top of this file). `static` is the proven-safe shape (calendar's
  69. // `soonOf`, called from `calLoad`/`calSettingsLoad`, an mpackdb-backed helper exactly like this one).
  70. static initialCollapsed = (seasons) => {
  71. let m = {}
  72. let i = 0
  73. while (i < seasons.length) {
  74. if (i > 0) { m[seasons[i].id] = true }
  75. i = i + 1
  76. }
  77. return m
  78. }
  79. static genreRowsOf = (show) => {
  80. let out = []
  81. for (gid of show.genres) {
  82. let g = genreById(gid)
  83. if (g != null) { out.push({ id = g.id name = g.name href = '/genres/' + g.urlSegment }) }
  84. }
  85. return out
  86. }
  87. // tracker#28: how many names show before "Show all" (cast; per crew job)
  88. static castShown = 20
  89. static crewShown = 6
  90. static listOf = (v) => { return v == null ? [] : v }
  91. // the cast as flat rows (no nested for, see THE ROWS above): `isPerson` rows { name, href, roleText (' (Character)' or ''),
  92. // itemClass } and before the first guest one `isLabel` row "Guest stars". itemClass: `more` = hidden until "Show all", `end` =
  93. // no comma after it (the last of a group), `cut` = the last one shown while collapsed (no comma then)
  94. static castRowsOf = (show) => {
  95. let people = []
  96. for (c of listOf(show.cast)) {
  97. let p = c != null && c.person != null ? personById(c.person) : null
  98. // mission 062: a guest without a person record — the link creates it on the first open (project.hl guestRoute)
  99. 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 }) }
  100. 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 }) }
  101. }
  102. let out = []
  103. let k = 0
  104. let guests = false
  105. while (k < people.length) {
  106. let c = people[k]
  107. if (c.guest && !guests && k > 0) {
  108. guests = true
  109. out.push({ isLabel = true isPerson = false text = 'Guest stars' name = '' href = '' roleText = '' itemClass = k >= castShown ? 'more' : '' })
  110. }
  111. let last = k == people.length - 1 || (people[k + 1].guest && !c.guest)
  112. let cls = (k >= castShown ? ' more' : '') + (last ? ' end' : '') + (k == castShown - 1 ? ' cut' : '')
  113. out.push({ isLabel = false isPerson = true text = '' name = c.name href = c.href roleText = c.role != '' ? ' (' + c.role + ')' : '' itemClass = 'artist-link' + cls })
  114. k = k + 1
  115. }
  116. return out
  117. }
  118. static castCountOf = (rows) => {
  119. let n = 0
  120. for (r of rows) { if (r.isPerson) { n = n + 1 } }
  121. return n
  122. }
  123. static crewLabels = { creator = 'Created by' director = 'Directed by' writer = 'Written by' screenplay = 'Screenplay' story = 'Story' composer = 'Music' }
  124. // the crew as flat rows: per job (in stored order) an `isLabel` row, then its people (itemClass as for the cast, `more` after
  125. // the first crewShown of a job)
  126. static crewRowsOf = (show) => {
  127. let people = []
  128. for (c of listOf(show.crew)) {
  129. let p = c != null ? personById(c.person) : null
  130. if (p != null && crewLabels[c.job] != null) { people.push({ name = c.name != null ? c.name : p.name href = '/person/' + p.urlSegment job = c.job }) }
  131. }
  132. let out = []
  133. let k = 0
  134. let inJob = 0
  135. while (k < people.length) {
  136. let c = people[k]
  137. if (k == 0 || people[k - 1].job != c.job) {
  138. inJob = 0
  139. out.push({ isLabel = true isPerson = false text = crewLabels[c.job] name = '' href = '' itemClass = '' })
  140. }
  141. let last = k == people.length - 1 || people[k + 1].job != c.job
  142. 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' : '') })
  143. inJob = inJob + 1
  144. k = k + 1
  145. }
  146. return out
  147. }
  148. // how many crew names are hidden while collapsed (0 = no toggle) and how many there are
  149. static crewHiddenOf = (rows) => {
  150. let n = 0
  151. for (r of rows) { if (r.isPerson && r.itemClass.includes(' more')) { n = n + 1 } }
  152. return n
  153. }
  154. static crewCountOf = (rows) => {
  155. let n = 0
  156. for (r of rows) { if (r.isPerson) { n = n + 1 } }
  157. return n
  158. }
  159. // a View attribute must be a literal, a member or a field path — never an inline expression — so
  160. // every ternary (watched -> icon class, collapsed -> row class) is resolved HERE, once, into a
  161. // plain field the View just reads (row.watchClass, row.rowClass); `watchClassOf` itself lives in
  162. // watches.hl (shared with /unwatched and /schedule, "reuse, don't copy")
  163. // #22: an episode's air date as the lists show it ('YYYY-MM-DD'), '' when it has none
  164. static airDateOf = (e) => { return e.release != null && hlTypeName(e.release) == 'String' ? e.release : '' }
  165. // #23: a season is watched when ALL its episodes are (by the ids it lists); one without episodes keeps its own season watch
  166. static seasonAllWatched = (s, watched) => {
  167. if (s.episodes.length == 0) { return watched['season:' + s.id] == true }
  168. for (eid of s.episodes) { if (watched['episode:' + eid] != true) { return false } }
  169. return true
  170. }
  171. static buildRows = (show, uid, collapsed) => {
  172. let watched = watchedSet(uid != null ? watchesOfUser(uid) : [])
  173. let 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. let m = {}
  194. if (uid == null) { return m }
  195. let 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. let 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. let 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. let 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. let 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. let s = showBySlug(slug)
  276. return s != null && adultHiddenFor(s, uid) ? null : s
  277. }
  278. // 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
  279. // AND re-sends it after every watch/follow click (SESSION SYNC below): the whole record was ~1 MB on The Simpsons (300 cast + crew
  280. // entries). null = not found / hidden.
  281. static pageShowOf = (slug, uid) => {
  282. let s = visibleShow(slug, uid)
  283. if (s == null) { return null }
  284. let movie = s.type == 'movie'
  285. return { id = s.id title = s.title summary = summaryOf(s) type = s.type adult = s.adult == true shortId = s.shortId != null ? '' + s.shortId : ''
  286. poster = posterName(s) genreRows = genreRowsOf(s) linkRows = externalLinksOf(s) completing = completingOf(s) following = followingOf(s, uid)
  287. movieWatched = movie ? movieWatchedOf(s, uid) : false }
  288. }
  289. // the seasons/episodes rows and the per-season watch state by the slug (the record itself stays on the server)
  290. static rowsOfSlug = (slug, uid, collapsed) => {
  291. let s = showBySlug(slug)
  292. return s != null ? buildRows(s, uid, collapsed) : []
  293. }
  294. static watchedEpisodesOfSlug = (slug, uid) => {
  295. let s = showBySlug(slug)
  296. return s != null ? watchedEpisodesOf(s, uid) : {}
  297. }
  298. // the initial open/closed seasons and the title's kind (tracker#20/#21: the heading's type word) from the SLUG alone (not from
  299. // `showRow`, which reads the session — see `collapsed`) — one slug lookup for both
  300. static slugInfoOf = (slug) => {
  301. let s = showBySlug(slug)
  302. return s != null ? { collapsed = initialCollapsed(seasonsOfShow(s)) kind = titleKind(s) } : { collapsed = {} kind = 'series' }
  303. }
  304. // mission 062: the cast and crew rows by the SLUG alone (not from `showRow`, which reads the session — see `castRows`). An
  305. // ADULT title (its page only for its followers) shows none: every member is shipped to the browser, and adult titles never get
  306. // credits anyway (details.hl skips them; at most a migrated cast)
  307. static publicShowOf = (slug) => {
  308. let s = showBySlug(slug)
  309. return s != null && s.adult != true ? s : null
  310. }
  311. static castOfSlug = (slug) => {
  312. let s = publicShowOf(slug)
  313. return s != null ? castRowsOf(s) : []
  314. }
  315. static crewOfSlug = (slug) => {
  316. let s = publicShowOf(slug)
  317. return s != null ? crewRowsOf(s) : []
  318. }
  319. // tracker#26: the page loads this title's full details on open
  320. static completingOf = (show) => { return needsDetails(show) }
  321. // the face's work: ONE step of completing the title (details.hl completeStep — a series takes a few; a second viewer drives the
  322. // same job or finds it complete); when done, every part of the page that changes — the rows without anyone's watch state (a
  323. // title that was incomplete had no episodes to watch)
  324. static completedPageOf = (slug) => {
  325. let show = showBySlug(slug)
  326. if (show == null || show.adult == true) { return { error = 'no such show' } }
  327. if (needsDetails(show)) {
  328. let r = completeStep(show.id)
  329. if (r.retry || r.adult == true) { return { error = r.error != '' ? r.error : 'no such show' } }
  330. if (!r.done) { return { done = false steps = r.sum.steps } }
  331. if (!r.skipped) {
  332. persistDetails()
  333. console.log('details on open: ' + completeLine(show.title, r.sum))
  334. }
  335. show = showById(show.id)
  336. }
  337. let cl = initialCollapsed(seasonsOfShow(show))
  338. let pn = posterName(show)
  339. let crew = crewRowsOf(show)
  340. let cast = castRowsOf(show)
  341. return { done = true title = show.title summary = summaryOf(show) poster = pn genreRows = genreRowsOf(show) castRows = cast
  342. castCount = castCountOf(cast) castMore = castCountOf(cast) > castShown crewRows = crew crewCount = crewCountOf(crew) crewMore = crewHiddenOf(crew) > 0
  343. linkRows = externalLinksOf(show) collapsed = cl rows = buildRows(show, null, cl) }
  344. }
  345. // ---- reactive members -----------------------------------------------------------------------
  346. slug = null
  347. session = null
  348. userId = userIdOfSession(session)
  349. signedIn = userId != null
  350. // SESSION SYNC (mission 047; since hybriel #121/#122, mission 056): a face taking `session` answers with a `sync` of every
  351. // member derived from session that reaches an import (here `showRow`, `found`, `following`, `rows`, …), re-derived on the
  352. // server with the page's route params but the MOUNT's other state — so client state (`collapsed`) must never derive from
  353. // them. `me` stays the plain copy mission 047 introduced.
  354. me = userId
  355. showRow = pageShowOf(slug, me)
  356. found = showRow != null
  357. notFound = showRow == null
  358. // the Follow toggle: "Follow" = the inverted button (accent border), "Following" = the filled one
  359. following = found ? showRow.following : false
  360. followClass = following ? 'follow' : 'follow inverted'
  361. followText = following ? 'Following' : 'Follow'
  362. signInHref = loginHref
  363. // #24: a movie's watched check (same icon/classes as the episodes); the classes written out, not `watchClassOf` (an import of
  364. // the mpackdb-backed watches.hl cannot run in the browser when the member is re-derived there)
  365. isMovie = found && showRow.type == 'movie'
  366. movieWatched = isMovie ? showRow.movieWatched : false
  367. movieWatchClass = movieWatched ? 'checkicon solid' : 'checkicon regular'
  368. movieWatchText = movieWatched ? 'Watched' : 'Not watched'
  369. 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.'
  370. title = found ? showRow.title : ''
  371. // tracker#20: "Series | Reacher" — the kind from the slug (pure strings here: they are re-derived in the browser too)
  372. slugInfo = slugInfoOf(slug)
  373. pageKind = slugInfo.kind
  374. typeText = pageKind == 'movie' ? 'Movie' : (pageKind == 'show' ? 'Show' : 'Series')
  375. typeClass = 'type-word type-' + pageKind
  376. // tracker#18: the creator's own text, else TMDB's, else TVmaze's (pageShowOf → shows.hl summaryOf)
  377. summary = found && showRow.summary != null ? showRow.summary : ''
  378. poster = found ? showRow.poster : null
  379. hasPoster = poster != null
  380. posterUrl = hasPoster ? '/posters/' + poster : ''
  381. // mission 060 (tracker.worldapi.org#27): the short id under the poster (none yet while the backfill has not reached it)
  382. shortId = found ? showRow.shortId : ''
  383. hasShortId = shortId != ''
  384. genreRows = found ? showRow.genreRows : []
  385. hasGenres = genreRows.length > 0
  386. // mission 062: cast + crew from the SLUG (`castOfSlug`, `crewOfSlug`), never from `showRow` — a member derived from the session is
  387. // re-derived and re-SENT after every watch/follow click (SESSION SYNC above): The Simpsons' 300 names took 0.7 s per click
  388. castRows = castOfSlug(slug)
  389. hasCast = castRows.length > 0
  390. // tracker#28: "Show all (N)" — the toggles' state is CLIENT state: literals, never derived from `showRow` (session sync)
  391. castCount = castCountOf(castRows)
  392. castMore = castCount > castShown
  393. castAllText = 'Show all (' + castCount + ')'
  394. castClass = 'collapsed'
  395. crewRows = crewOfSlug(slug)
  396. hasCrew = crewRows.length > 0
  397. crewCount = crewCountOf(crewRows)
  398. crewMore = crewHiddenOf(crewRows) > 0
  399. crewAllText = 'Show all crew (' + crewCount + ')'
  400. crewClass = 'collapsed'
  401. linkRows = found ? showRow.linkRows : []
  402. hasLinks = linkRows.length > 0
  403. // NOT from `showRow`/`found`: they read the session (via `me`), so a member derived from them is re-derived on the server
  404. // after every session face with the MOUNT's state — `collapsed` (client state) would snap back to the initial seasons (mission
  405. // 056: the 2nd episode click in a re-opened season did nothing). The season ids of a hidden page are no secret.
  406. collapsed = slugInfo.collapsed
  407. // mission 062: has this page opened/closed a season (client state) — then a watch face sends its own rows (toggleEpisode)
  408. collapsedChanged = false
  409. rows = found ? rowsOfSlug(slug, me, collapsed) : []
  410. hasRows = rows.length > 0
  411. watchedEpisodes = found ? watchedEpisodesOfSlug(slug, me) : {}
  412. // an adult page (followers only) opens its seasons through the session face `showRows`
  413. adultShow = found && showRow.adult == true
  414. // tracker#26: incomplete → skeletons + the probe until `showComplete` answered
  415. completing = found ? showRow.completing : false
  416. completeBusy = false
  417. isSeries = found && showRow.type != 'movie'
  418. skeletonSeasons = ['1', '2', '3']
  419. __title = found ? title + ' — ' + appTitle : appTitle
  420. View {
  421. showPage {
  422. if (notFound) {
  423. article { class = "main"
  424. h1 { "Not found" }
  425. p { "This show doesn't exist." }
  426. }
  427. }
  428. if (found) {
  429. showHeader {
  430. showPoster {
  431. if (hasPoster) { img { src = posterUrl alt = title } }
  432. if (completing) { skeletonPoster { "aria-hidden" = "true" } }
  433. if (hasShortId) { shortIdLabel { id = "shortid" title = "Short id" shortId } }
  434. }
  435. showMeta {
  436. showTitle {
  437. h1 { class = "typed" typeWord { class = typeClass typeText } typeSep { "|" } typeName { title } }
  438. button { id = "follow" type = "button" class = followClass followText on click(e) { emit toggleFollow(e) } }
  439. }
  440. if (isMovie) {
  441. movieWatch {
  442. button { id = "moviewatch" type = "button" class = movieWatchClass "aria-label" = "mark movie watched"
  443. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  444. circle { cx = "12" cy = "12" r = "10" }
  445. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  446. }
  447. on click(e) { emit toggleMovie(e) }
  448. }
  449. movieWatchLabel { movieWatchText }
  450. }
  451. }
  452. if (hasLinks) {
  453. showLinks {
  454. 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 } }
  455. }
  456. }
  457. if (hasGenres) {
  458. showGenres {
  459. for (g of genreRows) { a { class = "genre-pill" href = g.href g.name } }
  460. }
  461. }
  462. showSummary { summary }
  463. if (hasCrew) {
  464. showCrew { class = crewClass
  465. for (r of crewRows) {
  466. if (r.isLabel) { crewLabel { r.text } }
  467. if (r.isPerson) { a { class = r.itemClass href = r.href r.name } }
  468. }
  469. if (crewMore) {
  470. button { id = "crewtoggle" type = "button" class = "quiet showall"
  471. whenCollapsed { crewAllText }
  472. whenAll { "Show less" }
  473. on click(e) { emit toggleCrewAll(e) }
  474. }
  475. }
  476. }
  477. }
  478. if (hasCast) {
  479. showCast { class = castClass
  480. castHeading { "Cast" }
  481. for (c of castRows) {
  482. if (c.isLabel) { castLabel { class = c.itemClass c.text } }
  483. if (c.isPerson) { a { class = c.itemClass href = c.href "data-role" = c.roleText c.name } }
  484. }
  485. if (castMore) {
  486. button { id = "casttoggle" type = "button" class = "quiet showall"
  487. whenCollapsed { castAllText }
  488. whenAll { "Show less" }
  489. on click(e) { emit toggleCastAll(e) }
  490. }
  491. }
  492. }
  493. }
  494. if (completing) { skeletonCast { "aria-hidden" = "true" } }
  495. }
  496. }
  497. if (completing) {
  498. showLoading { id = "showloading" "aria-busy" = "true"
  499. if (isSeries) {
  500. for (k of skeletonSeasons) {
  501. skeletonRow { "aria-hidden" = "true"
  502. skeletonCheck { }
  503. skeletonTitle { }
  504. }
  505. }
  506. }
  507. showProbe { "aria-hidden" = "true" on animationiteration(e) { emit completeTick(e) } }
  508. }
  509. }
  510. if (hasRows) {
  511. showSeasons {
  512. for (row of rows) {
  513. if (row.isSeason) {
  514. seasonRow { class = row.rowClass
  515. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark season watched"
  516. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  517. circle { cx = "12" cy = "12" r = "10" }
  518. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  519. }
  520. on click(e) { emit toggleSeason(row.id) }
  521. }
  522. button { type = "button" class = "season-toggle" value = row.id
  523. seasonLabel { row.label }
  524. seasonCount { row.episodeCountText }
  525. seasonCaret { "aria-hidden" = "true"
  526. svg { viewBox = "0 0 24 24" width = "20" height = "20"
  527. path { d = "M6 9 L12 15 L18 9" }
  528. }
  529. }
  530. on click(e) { emit toggleCollapse(row.id) }
  531. }
  532. }
  533. }
  534. if (row.isEpisode) {
  535. episodeRow {
  536. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark episode watched"
  537. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  538. circle { cx = "12" cy = "12" r = "10" }
  539. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  540. }
  541. on click(e) { emit toggleEpisode(row.id) }
  542. }
  543. episodeNumber { row.episodeNumber }
  544. episodeTitle { row.title }
  545. episodeDate { row.airDate }
  546. }
  547. }
  548. if (row.isSkeleton) {
  549. skeletonRow { "aria-hidden" = "true"
  550. skeletonCheck { }
  551. skeletonNumber { }
  552. skeletonTitle { }
  553. }
  554. }
  555. }
  556. }
  557. }
  558. Modal { id = "signin" title = "Sign in"
  559. p { signInText }
  560. footer {
  561. button { type = "button" value = "close" "Close" }
  562. a { id = "signin-link" class = "button" href = signInHref "Sign in with ident" }
  563. }
  564. }
  565. }
  566. }
  567. }
  568. // Every rebuild of `rows` happens SERVER-SIDE, never by calling `buildRows` from a client handler:
  569. // a member function whose body reaches an hl:mpackdb-backed import (seasonsOfShow, episodesOfSeason,
  570. // watchesOfUser, …) compiles to nothing on the client (no case ever assigns it — a genuine Hybriel
  571. // gap, filed under `issues`) even though the client bundle still calls it, so `this.buildRows(...)`
  572. // throws "not a function" in the browser. The client here only ever ASSIGNS the `rows` the server
  573. // already built (`rows = r.rows`) — never calls a tainted local helper itself. `slug` goes along so
  574. // the face can refetch the show without depending on implicit access to a sibling member.
  575. //
  576. // tracker#17: opening shows the skeleton rows BEFORE the request; the answer replaces them unless the season was closed
  577. // meanwhile (then nothing). An error closes the season again. Closing never asks the server.
  578. on toggleCollapse(seasonId) {
  579. collapsedChanged = true
  580. let m = collapsed
  581. if (collapsed[seasonId] != true) {
  582. m[seasonId] = true
  583. collapsed = m
  584. rows = closedRows(rows, seasonId)
  585. return null
  586. }
  587. m[seasonId] = false
  588. collapsed = m
  589. rows = openingRows(rows, seasonId)
  590. if (adultShow) {
  591. let a = emit server showRows(slug, collapsed)
  592. if (collapsed[seasonId] == true) { return null }
  593. if (a == null || a.error != null) { m[seasonId] = true collapsed = m rows = closedRows(rows, seasonId) return null }
  594. rows = a.rows
  595. return null
  596. }
  597. let r = emit server showSeasonEpisodes('' + seasonId)
  598. if (collapsed[seasonId] == true) { return null }
  599. if (r == null || r.error != null) { m[seasonId] = true collapsed = m rows = closedRows(rows, seasonId) return null }
  600. rows = filledRows(rows, seasonId, r.episodes, watchedEpisodes)
  601. }
  602. // tracker#26: the probe's tick — `showComplete` step by step until `done` (once per page: `completeBusy`; other requests are
  603. // served between two calls); the last answer replaces the skeletons. A lost answer (null) lets the next tick go on where the
  604. // server is; an error (TMDB down, adult) ends the loading and keeps what the page has.
  605. on completeTick(e) {
  606. if (completeBusy || !completing) { return null }
  607. completeBusy = true
  608. let s = slug
  609. let r = emit server showComplete(s)
  610. while (r != null && r.error == null && r.done != true && slug == s) { r = emit server showComplete(s) }
  611. completeBusy = false
  612. if (r == null || slug != s) { return null }
  613. if (r.error != null) { completing = false return null }
  614. title = r.title
  615. summary = r.summary
  616. poster = r.poster
  617. genreRows = r.genreRows
  618. castRows = r.castRows
  619. castCount = r.castCount
  620. castMore = r.castMore
  621. castAllText = 'Show all (' + r.castCount + ')'
  622. crewRows = r.crewRows
  623. crewCount = r.crewCount
  624. crewMore = r.crewMore
  625. crewAllText = 'Show all crew (' + r.crewCount + ')'
  626. linkRows = r.linkRows
  627. collapsed = r.collapsed
  628. collapsedChanged = true
  629. rows = r.rows
  630. completing = false
  631. }
  632. // tracker#28: the cast / crew "Show all" toggles — client-only, no request (CSS shows the hidden names)
  633. on toggleCastAll(e) {
  634. castClass = castClass == 'all' ? 'collapsed' : 'all'
  635. }
  636. on toggleCrewAll(e) {
  637. crewClass = crewClass == 'all' ? 'collapsed' : 'all'
  638. }
  639. // signed out: the modal, nothing is sent
  640. // mission 062: the new `rows` come with the SAME ack as the session sync (SESSION SYNC above: `rows` derives from the session) —
  641. // 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
  642. // (`collapsedChanged`, or a completed title); else they came twice (a second buildRows + 14 kB on The Simpsons: ~40 ms per click)
  643. on toggleEpisode(episodeId) {
  644. if (!signedIn) { document.getElementById('signin').showModal() return null }
  645. let r = emit server showToggleEpisode(slug, '' + episodeId, collapsed, collapsedChanged)
  646. if (r == null || r.error != null) { return null }
  647. if (r.rows != null) { rows = r.rows }
  648. }
  649. on toggleSeason(seasonId) {
  650. if (!signedIn) { document.getElementById('signin').showModal() return null }
  651. let r = emit server showToggleSeason(slug, '' + seasonId, collapsed, collapsedChanged)
  652. if (r == null || r.error != null) { return null }
  653. if (r.rows != null) { rows = r.rows }
  654. }
  655. // #24: the movie's own check — signed out the modal, nothing sent
  656. on toggleMovie(e) {
  657. if (!signedIn) { document.getElementById('signin').showModal() return null }
  658. let r = emit server showToggleMovie(slug)
  659. if (r == null || r.error != null) { return null }
  660. movieWatched = r.watched
  661. movieWatchClass = r.watched ? 'checkicon solid' : 'checkicon regular'
  662. movieWatchText = r.watched ? 'Watched' : 'Not watched'
  663. }
  664. on toggleFollow(e) {
  665. if (!signedIn) { document.getElementById('signin').showModal() return null }
  666. let r = emit server showToggleFollow(slug)
  667. if (r == null || r.error != null) { return null }
  668. following = r.following
  669. followClass = r.following ? 'follow' : 'follow inverted'
  670. followText = r.following ? 'Following' : 'Follow'
  671. }
  672. // ---- the faces (the trailing `session` is always the server's: hybriel#16) ----
  673. // tracker#26: complete an incomplete title and answer the page's parts — public data, NO session (no page re-mount)
  674. on server showComplete(slug) {
  675. return completedPageOf(slug != null ? '' + slug : '')
  676. }
  677. // every row for these open/closed seasons — only an ADULT show's page still uses it (its followers; tracker#17)
  678. on server showRows(slug, collapsed, session) {
  679. let show = showBySlug(slug)
  680. let uid = userIdOfSession(session)
  681. if (show == null || adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  682. return { ok = true rows = buildRows(show, uid, collapsed) }
  683. }
  684. // tracker#17: one season's episodes, in order — public data, so NO `session` (no page re-mount, no sync: the fast path).
  685. // Refuses a season of an adult title (those pages use showRows above).
  686. on server showSeasonEpisodes(seasonId) {
  687. if (seasonId == null || hlTypeName(seasonId) != 'String') { return { error = 'no such season' } }
  688. let season = seasonById(seasonId)
  689. if (season == null) { return { error = 'no such season' } }
  690. let show = showById(season.show)
  691. if (show == null || show.adult == true) { return { error = 'no such season' } }
  692. let out = []
  693. for (e of episodesOfSeason(season)) { out.push({ id = e.id episodeNumber = e.episodeNumber title = e.title != null ? e.title : '' airDate = airDateOf(e) }) }
  694. return { ok = true episodes = out }
  695. }
  696. on server showToggleEpisode(slug, episodeId, collapsed, withRows, session) {
  697. let show = showBySlug(slug)
  698. if (show == null) { return { error = 'no such show' } }
  699. let uid = userIdOfSession(session)
  700. if (uid == null) { return { error = 'you are not signed in' } }
  701. if (adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  702. let rows = watchesOfUser(uid)
  703. let watched = isWatched(rows, 'episode', episodeId) == false
  704. let ok = setWatched(uid, 'episode', episodeId, rows, watched)
  705. if (!ok) { return { error = 'could not save the watch' } }
  706. return withRows == true ? { ok = true rows = buildRows(show, uid, collapsed) } : { ok = true }
  707. }
  708. on server showToggleSeason(slug, seasonId, collapsed, withRows, session) {
  709. let show = showBySlug(slug)
  710. if (show == null) { return { error = 'no such show' } }
  711. let uid = userIdOfSession(session)
  712. if (uid == null) { return { error = 'you are not signed in' } }
  713. if (adultHiddenFor(show, uid)) { return { error = 'no such show' } }
  714. let season = seasonById(seasonId)
  715. if (season == null) { return { error = 'no such season' } }
  716. let rows = watchesOfUser(uid)
  717. // #23: not all episodes watched → watch them all; all watched → unwatch them all
  718. let watched = !seasonAllWatched(season, watchedSet(rows))
  719. let ok = setSeasonWatched(uid, seasonId, season.episodes, rows, watched)
  720. if (!ok) { return { error = 'could not save the watch' } }
  721. return withRows == true ? { ok = true rows = buildRows(show, uid, collapsed) } : { ok = true }
  722. }
  723. // #24: a movie's watched check (only a movie: a series is watched by its episodes)
  724. on server showToggleMovie(slug, session) {
  725. let show = showBySlug(slug)
  726. if (show == null || show.type != 'movie') { return { error = 'no such movie' } }
  727. let uid = userIdOfSession(session)
  728. if (uid == null) { return { error = 'you are not signed in' } }
  729. if (adultHiddenFor(show, uid)) { return { error = 'no such movie' } }
  730. let rows = watchesOfUser(uid)
  731. let watched = isWatched(rows, 'movie', show.id) == false
  732. if (!setWatched(uid, 'movie', show.id, rows, watched)) { return { error = 'could not save the watch' } }
  733. return { ok = true watched = watched }
  734. }
  735. on server showToggleFollow(slug, session) {
  736. let show = showBySlug(slug)
  737. if (show == null) { return { error = 'no such show' } }
  738. let uid = userIdOfSession(session)
  739. if (uid == null) { return { error = 'you are not signed in' } }
  740. let follow = isFollowing(uid, show.id) == false
  741. if (!setFollowed(uid, show.id, follow)) { return { error = 'could not save the follow' } }
  742. return { ok = true following = follow }
  743. }

Branches

Latest commits

  • daf49feaMerge t20 (tracker#20 typed headings + #21 series/shows split) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/search.hl/components/search.hl/browser.mjs/faketmdb.mjs, both sides kept; clock order backfill → repair → kinds → credits; withDetailsFields stores tmdbType + kind; gates: browser.mjs URLs → /series|/movies, typed h1 selectors; kinds.mjs repair/credits off, fixture name = seed name; browser 323/0, kinds 32/0mre
  • 20e09d89Merge t18 (tracker#18 delta sync) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs, both sides kept; pageShowOf summary = summaryOfmre
  • f83571c3tracker#18 (mission 067): daily sync by change lists — TMDB /tv|movie/changes (since the stored day, paged) + TVmaze /updates/shows → only our changed titles (followed: full step, unfollowed: light step — changed seasons, no TVmaze), full walk on first run / gap > 14 days / failed list; show record refreshed (title, tmdbSummary, tagline, status, genres …; renamed titles re-indexed); summary = the creator's own text (page: summary > tmdbSummary > tvmazeSummary), one-time clear of copied summaries (9,647 on the live copy); gate 261, tests/realdata-018*.mjs, README + STATUSmre
  • 1ed5457etracker#20 + #21 (mission 068): typed headings "<Type> | <name>" in type colours; TV titles split into Series (/series) and Shows (/shows) by TMDB type + Reality/Talk/News genres — kind stored by sync/import/adult backfill + new kind backfill (resumes), /movies/<slug>, /shows/<slug> of a series/movie → 301, /my/series + /my/shows, home 5 tiles + 3 rows, search/filmography labels; gates kinds 32 + browser 266, tests/realdata-068.mjs, tools/count-kinds.hl, docs/kinds.md, README + STATUSmre
  • f2b00674Merge t26 (tracker#26 + #28) into main (mission 062): short ids for every new person (castPersonId, guest route), guest stars stored on the title and created as people only when opened (/person/tmdb/<id>?show=<id> → 302), lean watch/follow clicks (showRow a small object, cast/crew from the slug, watches cached per user, face rows only after a season toggle); gate 311, tests/realdata-062.mjs, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • 10bb3f93tracker#28 (mission 061): full cast (all seasons, main cast by episodes, guest stars) + crew (created by, directed by, written by, screenplay, story, music) — stored by the details completion, the daily sync, the search import (one details request) and a background credits job (resumes, RSS limit); show page collapsed after 20 with client-side Show all; showBySlug via a slug map; gate 249, tests/realdata-028.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • 25a50bc4tracker#26 (mission 059): titles from a filmography are completed — on open (skeleton, step-wise face showComplete, no reload) and by the in-app details repair (resumes, TMDB-paced, series in parts); cast from TMDB credits; gate 231, tests/realdata-026.mjs, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.mjs, README + STATUSmre
  • 1704ec45tracker#17 (mission 057): season caret down/up, skeleton rows while a season loads, sessionless showSeasonEpisodes face (no page re-mount), client-only close; gate 214, tests/realdata-057.mjs, README + STATUSmre
  • f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
  • f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
  • 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
  • 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
  • c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
  • 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
  • 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre