gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit93be947693be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre93be9476/components/unwatched.hl

5.0 KB

  1. // components/unwatched.hl — `/my/unwatched` (tracker.worldapi.org#5, moved from `/unwatched` in #8): every already-released episode of a
  2. // show the signed-in user follows that they have not watched yet, newest release first. Creator's words:
  3. // "/unwatched lists all unwatched episodes of shows followed in release date desc order"; "check icon is
  4. // a disc with a check in it" — the SAME check icon and watch logic as the show page (step 4), reused
  5. // (not copied) from follows.hl/shows.hl/watches.hl: `watchClassOf`, `watchedSet`, `setWatched` come from
  6. // watches.hl, the check icon markup/CSS is the same `button.checkicon` shape/class styles.hl already has.
  7. //
  8. // A ROW ONLY EVER SHOWS AN UNWATCHED EPISODE, so a click always marks it watched (never toggles back,
  9. // unlike the show page's checks) and the row leaves the list — the ticket's own test: "click an
  10. // episode's check: it disappears from the list."
  11. //
  12. // ONE FLAT LIST, rebuilt whole server-side on every click — the same proven-safe shape components/show.hl
  13. // uses for exactly the same Hybriel reasons (hybriel#86, hybriel#115/#116: a plain member function that
  14. // touches an hl:mpackdb-backed import must be `static` and must only ever be called server-side).
  15. parent './main.hl'
  16. import { appTitle } from '../project.hl'
  17. import { userIdOfSession } from '../users.hl'
  18. import { followedShowIds } from '../follows.hl'
  19. import { showById, seasonsOfShow, episodesOfSeason, episodeCode, titleWithYear } from '../shows.hl'
  20. import { watchesOfUser, watchedSet, setWatched, watchClassOf } from '../watches.hl'
  21. import { now, timestamp } from 'hl:time'
  22. // ---- pure helpers (static: see the header comment above) ------------------------------------
  23. static todayStr = () => { return timestamp(now()).slice(0, 10) }
  24. // insertion sort, hand-written (no list sort(), hybriel#1) — a follow list is a handful of shows,
  25. // a season a handful of episodes; newest release first, `release` is a plain 'YYYY-MM-DD' string
  26. static insertByReleaseDesc = (sorted, row) => {
  27. let out = []
  28. let inserted = false
  29. for (x of sorted) {
  30. if (!inserted && row.release >= x.release) { out.push(row) inserted = true }
  31. out.push(x)
  32. }
  33. if (!inserted) { out.push(row) }
  34. return out
  35. }
  36. static unwatchedRowsOf = (userId) => {
  37. if (userId == null) { return [] }
  38. let today = todayStr()
  39. let watched = watchedSet(watchesOfUser(userId))
  40. let out = []
  41. for (sid of followedShowIds(userId)) {
  42. let show = showById(sid)
  43. if (show != null) {
  44. for (s of seasonsOfShow(show)) {
  45. for (e of episodesOfSeason(s)) {
  46. let released = e.release != null && e.release <= today
  47. if (released && watched['episode:' + e.id] != true) {
  48. let title = e.title != null ? e.title : ''
  49. out = insertByReleaseDesc(out, {
  50. id = e.id showTitle = titleWithYear(show) showHref = '/shows/' + show.urlSegment
  51. episodeLabel = episodeCode(e.seasonNumber, e.episodeNumber) + ' · ' + title
  52. release = e.release watchClass = watchClassOf(false)
  53. })
  54. }
  55. }
  56. }
  57. }
  58. }
  59. return out
  60. }
  61. // ---- reactive members -----------------------------------------------------------------------
  62. session = null
  63. userId = userIdOfSession(session)
  64. signedIn = userId != null
  65. // a plain copy of userId for `rows` (mission 047: session sync, see components/show.hl `me`)
  66. me = userId
  67. rows = signedIn ? unwatchedRowsOf(me) : []
  68. hasRows = rows.length > 0
  69. noRows = !hasRows
  70. emptyText = signedIn ? 'No unwatched episodes.' : 'Sign in to see the shows you follow.'
  71. __title = 'Unwatched — ' + appTitle
  72. View {
  73. unwatchedPage {
  74. h1 { "Unwatched" }
  75. if (noRows) { p { class = "muted" emptyText } }
  76. if (hasRows) {
  77. unwatchedRows {
  78. for (row of rows) {
  79. unwatchedRow {
  80. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark episode watched"
  81. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  82. circle { cx = "12" cy = "12" r = "10" }
  83. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  84. }
  85. on click(e) { emit toggleEpisode(row.id) }
  86. }
  87. a { class = "unwatched-show" href = row.showHref row.showTitle }
  88. unwatchedEpisode { row.episodeLabel }
  89. unwatchedDate { row.release }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. // The client only ever ASSIGNS the `rows` the server already rebuilt — never calls the tainted
  97. // local helper itself (components/show.hl's own `on toggleEpisode` follows the same shape, and
  98. // the same reason: `unwatchedRowsOf` touches mpackdb-backed imports, so it compiles to nothing on
  99. // the client, hybriel#115/#116).
  100. on toggleEpisode(episodeId) {
  101. if (!signedIn) { return null }
  102. let r = emit server unwatchedToggle('' + episodeId)
  103. if (r == null || r.error != null) { return null }
  104. rows = r.rows
  105. }
  106. // ---- the face (the trailing `session` is always the server's: hybriel#16) ----
  107. on server unwatchedToggle(episodeId, session) {
  108. let uid = userIdOfSession(session)
  109. if (uid == null) { return { error = 'you are not signed in' } }
  110. let watchRows = watchesOfUser(uid)
  111. let ok = setWatched(uid, 'episode', episodeId, watchRows, true)
  112. if (!ok) { return { error = 'could not save the watch' } }
  113. return { ok = true rows = unwatchedRowsOf(uid) }
  114. }

Branches

Latest commits

  • 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
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
  • 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
  • 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre
  • cbdc4ea7tracker#12: link icons TMDB/IMDb/TVDB/TVmaze; sync fills missing ids (TVmaze lookup); movies fetched via /movie/mre
  • b105bcd8tracker#11: Hybriel master ff51cf46 (checks no longer vanish), mobile-first styles, carets, follow button, sign-in modal, inverted check, orange castmre
  • 31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre
  • 2fa9d997tracker#9: TMDB sync (followed shows: seasons, episodes, posters), tools/sync-tmdb.hl + daily run 04:00 UTC, fake TMDB in gatemre
  • 49e1f61edeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • 54070a4etracker#8: /my/unwatched + /my/schedule (301 from old), S01E01, title (year), 1 episode, watched-set lookup (unwatched 15s -> 1s)mre
  • 3251488atracker#7: /my/shows (followed shows, newest follow first, poster, title, last watched SxxEyy); gate can take screenshots (TRACKER_GATE_SHOTS)mre
  • 44b7d9f9tracker#6: /schedule — upcoming episodes of followed shows, soonest firstmre
  • 91c9fc8ctracker#5: /unwatched — unwatched released episodes of followed shows, newest firstmre
  • a97c0295tracker#4: show page /shows/:slug (header, seasons, episodes, watch checks) + tools/relink-episode-seasons.hlmre
  • 05f407c5tracker: no border on any button except inverted ones (Log out, ident status and identities too); header brand weight 100mre