gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit4043945640439456Merge hm63-searchtext: tracker#63 packed search textmre40439456/components/show.hl

42.6 KB

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

Branches

Latest commits

  • 40439456Merge hm63-searchtext: tracker#63 packed search textmre
  • b7e6b48ePack normalized search text behind numeric offsetsmre
  • b35f53e1log: DP62 stale runtime decisionmre
  • f9593602log: Apollo deploy rule correctionmre
  • 3c95f7f3log: DP62 and HM63 startedmre
  • 9c4397c9mission HM63mre
  • 8dfe42c8mission DP62mre
  • e347fef4Merge rv44: tracker#61 #62 on Hybriel day44mre
  • 8274bcf1log: RV44 done, deploy held for the usage windowmre
  • 1ef7a3b1RV44: report day44 gates and migration/restart proofsmre
  • a5f62f6cRV44: re-vendor Hybriel set day44 (source 222edef7, bin 4f0f263e)mre
  • 6159a248Merge branch 'hm62-personindex' into rv44mre
  • a8923d93log: RV44 startedmre
  • cf28cf77mission RV44mre
  • 585782dfLog: tracker#60 Chrome look, STATUS rewrittenmre
  • 147d0172conductor: caramboleyo is the user, not owner/creatorApollo
  • 21dd0cfblog: #60 live measurement, reviewmre
  • 7793cf94HM62b report: person indexes with fixed mpackdbmre
  • b4c8d3a9Document tracker#62 fixed-index migration and GC proofmre
  • 09d66ed5status: #60 livemre