tracker
All repositories: gitoria
5.5 KB
// components/myshows.hl — `/my/shows` (tracker.worldapi.org#7): every show the signed-in user follows,// the one followed last on top. Creator's words: "trackers /my/shows that just ists the shows in desc// order i followed them, small poster, title, last episode like s08e35". Each row: the small poster (the// same `/posters/<name>` route + placeholder as the show page, shows.hl `posterUrlOf`: one `/posters/none` URL when the file is missing), the title linking// to `/shows/<slug>`, and the LAST WATCHED episode as `S08E35` — the architect's reading (in the ticket):// the highest season/episode number the user has watched of that show; nothing watched → no episode.//// Read-only page (no check icons, no click), so like /schedule it needs no `on server` face — `rows` is// one server-side render from `session`. Since #13 SERIES only — the movies a user follows are /my/movies// (components/mymovies.hl). Reused (not copied): `followsOfUser`, `insertByFollowDesc` (follows.hl),// `watchesOfUser` (watches.hl), `cardOf`/`episodeKeyOf`/`posterUrlOfName`/`episodeCode` (shows.hl).//// COST (tracker#30, mission 025): no record is read per load — each followed title's slim cached card (shows.hl cardOf) and// each watched episode's cached { show s e } (episodeKeyOf; the user's watches are kept, watches.hl). Before, one fetch per// followed title (cast + crew) and one per watched episode (11.7k) — 4.4 s on a process after the first-start jobs.//// tracker.worldapi.org#21 (mission 068): TWO lists from this one component — `/my/series` (the followed SERIES) and `/my/shows`// (the followed SHOWS: reality, talk, news; shows.hl titleKind) — routed as `/my/:tv` (project.hl, after the other /my/ routes);// any other word is "Not found". Each row links to the title's own page (shows.hl titlePath).parent './main.hl'import { appTitle } from '../project.hl'import { userIdOfSession } from '../lib/users.hl'import { followsOfUser, insertByFollowDesc } from '../lib/follows.hl'import { cardOf, episodeKeyOf, posterUrlOfName, episodeCode } from '../lib/shows.hl'import { watchesOfUser } from '../lib/watches.hl'// ---- pure helpers (static: an mpackdb-backed helper must be `static`, hybriel#115/#116) ------// show id → the highest watched episode of it { seasonNumber, episodeNumber }, only for the shows in `follows` — by each// watched episode's own `show` (shows.hl episodeKeyOf, cached), so an episode outside the title's seasons still countsstatic lastWatchedOf = (&userId, &follows) => {followed = {}for (f of follows) { followed[f.show] = true }best = {}for (w of watchesOfUser(&userId)) {if (w.targetType == 'episode' && w.target != null) {let k = episodeKeyOf(&w.target)if (k.show != null && followed[k.show] == true && k.s != null && k.e != null) {let b = best[k.show]if (b == null || k.s > b.seasonNumber || (k.s == b.seasonNumber && k.e > b.episodeNumber)) {best[k.show] = { seasonNumber = k.s episodeNumber = k.e }}}}}return best}// the kind a list shows: 'series' for /my/series, 'show' for /my/shows, null for anything elsestatic listKindOf = (&tv) => { return tv == 'series' ? 'series' : (tv == 'shows' ? 'show' : null) }static myShowsRowsOf = (&userId, &kind) => {if (userId == null || kind == null) { return [] }// tracker.worldapi.org#13: movies have their own list, /my/movies; #21: series and shows each theirsfollows = []for (f of followsOfUser(&userId)) {let c = cardOf(&f.show)if (c != null && c.type != 'movie' && c.kind == kind) { follows.push(f) }}last = lastWatchedOf(&userId, &follows)let out = []for (f of follows) {let c = cardOf(&f.show)if (c != null) {let lw = last[c.id]let hasEpisode = lw != nullout = insertByFollowDesc(&out, {id = c.id title = c.titleYear href = c.hrefposterUrl = posterUrlOfName(&c.posterName)hasEpisode = hasEpisodeepisodeLabel = hasEpisode ? episodeCode(&lw.seasonNumber, &lw.episodeNumber) : ''followedAt = f.at != null ? f.at : 0})}}return out}// ---- reactive members -----------------------------------------------------------------------tv = nulllistKind = listKindOf(&tv)found = listKind != nullnotFound = listKind == nullisSeries = listKind == 'series'listWord = isSeries ? 'Series' : 'Shows'listClass = isSeries ? 'type-word type-series' : 'type-word type-show'session = nulluserId = userIdOfSession(&session)signedIn = userId != null// a plain copy of userId for `rows` (mission 047: session sync, see components/show.hl `me`)me = userIdrows = signedIn ? myShowsRowsOf(&me, &listKind) : []hasRows = rows.length > 0noRows = found && !hasRowsemptyText = signedIn ? (isSeries ? 'You follow no series yet.' : 'You follow no shows yet.') : (isSeries ? 'Sign in to see the series you follow.' : 'Sign in to see the shows you follow.')__title = found ? 'My ' + listWord.toLowerCase() + ' — ' + appTitle : appTitleView {myShowsPage { "data-kind" = listKindif (notFound) {h1 { "Not found" }p { "This list doesn't exist." }}// tracker.worldapi.org#20: "My" and the list's type word in its colourif (found) { h1 { class = "typed" "My" typeWord { class = listClass listWord } } }if (noRows) { p { class = "muted" emptyText } }if (hasRows) {myShowsRows {for (row of rows) {myShowRow {img { class = "myshow-poster" src = row.posterUrl alt = row.title }a { class = "myshow-title" href = row.href row.title }if (row.hasEpisode) { myShowEpisode { row.episodeLabel } }}}}}}}
Branches
Latest commits
- 0d253b45mission: T36Amre
- 2aa22d23log: #36 GOmre
- 833aee2flog: #50 closed, HM56 startedmre
- ac58c1e5mission: HM56mre
- 58979c0clog: HM54 held for decision, DP65 startedmre
- bb2ebc67log: #64 live, #53 mergedmre
- 27cde42fMerge hm53-dom: tracker#53 inputs bound to membersmre
- 2156cc7flog: HM54 reviewmre
- 9fb82efclog: HM54 gap, fill continuesmre
- b632eb8dlog: HM53 done, HM54 startedmre
- ccb1a263tracker#53: bind editor drafts and use key event focus targetmre
- 3356fcfclog: #52 blocked, HM53 startedmre
- 833dcfc9Merge hm52-search: report only, tracker#52 blocked by framework gapmre
- 73010cc0HM52: report replace-navigation search draft regressionmre
- 1742e92bstatus: DP64 and HM52 runningmre
- 29ad5b58log: #64 merged, DP64 and HM52 startedmre
- fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
- b2e2206dlog: #63 livemre
- 5831e0e0log: HM64 donemre
- 4042b923Flatten catalog membership rows into paired slotsmre