gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit91c9fc8c91c9fc8ctracker#5: /unwatched — unwatched released episodes of followed shows, newest firstmre91c9fc8c/components/unwatched.hl

4.9 KB

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

Branches

Latest commits

  • 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