gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit54070a4e54070a4etracker#8: /my/unwatched + /my/schedule (301 from old), S01E01, title (year), 1 episode, watched-set lookup (unwatched 15s -> 1s)mre54070a4e/components/unwatched.hl

4.9 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. rows = signedIn ? unwatchedRowsOf(userId) : []
  66. hasRows = rows.length > 0
  67. noRows = !hasRows
  68. emptyText = signedIn ? 'No unwatched episodes.' : 'Sign in to see the shows you follow.'
  69. __title = 'Unwatched — ' + appTitle
  70. View {
  71. unwatchedPage {
  72. h1 { "Unwatched" }
  73. if (noRows) { p { class = "muted" emptyText } }
  74. if (hasRows) {
  75. unwatchedRows {
  76. for (row of rows) {
  77. unwatchedRow {
  78. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark episode watched"
  79. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  80. circle { cx = "12" cy = "12" r = "10" }
  81. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  82. }
  83. on click(e) { emit toggleEpisode(row.id) }
  84. }
  85. a { class = "unwatched-show" href = row.showHref row.showTitle }
  86. unwatchedEpisode { row.episodeLabel }
  87. unwatchedDate { row.release }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. // The client only ever ASSIGNS the `rows` the server already rebuilt — never calls the tainted
  95. // local helper itself (components/show.hl's own `on toggleEpisode` follows the same shape, and
  96. // the same reason: `unwatchedRowsOf` touches mpackdb-backed imports, so it compiles to nothing on
  97. // the client, hybriel#115/#116).
  98. on toggleEpisode(episodeId) {
  99. if (!signedIn) { return null }
  100. let r = emit server unwatchedToggle('' + episodeId)
  101. if (r == null || r.error != null) { return null }
  102. rows = r.rows
  103. }
  104. // ---- the face (the trailing `session` is always the server's: hybriel#16) ----
  105. on server unwatchedToggle(episodeId, session) {
  106. let uid = userIdOfSession(session)
  107. if (uid == null) { return { error = 'you are not signed in' } }
  108. let watchRows = watchesOfUser(uid)
  109. let ok = setWatched(uid, 'episode', episodeId, watchRows, true)
  110. if (!ok) { return { error = 'could not save the watch' } }
  111. return { ok = true rows = unwatchedRowsOf(uid) }
  112. }

Branches

Latest commits

  • 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
  • 17375427tracker#2: tools/migrate.hl + tools/verify.hl — old MongoDB data into mpackdb with new idsmre
  • 31aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre
  • 2ad9d29ctracker#1: login exactly like calendar (identity selector in the header, empty homepage)mre
  • 3691e176tracker#1: empty tracker with the ident login (state of 2026-09-27)mre