gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitd1a91be9d1a91be9Merge hm57-let: tracker#57 let only for reassigned namesmred1a91be9/components/unwatched.hl

7.2 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 '../lib/users.hl'
  18. import { followedShowIds, adultHiddenForUser } from '../lib/follows.hl'
  19. import { cardOf, episodeRowsOf, episodeCode, episodeById, showById } from '../lib/shows.hl'
  20. import { watchesOfUser, watchedSetOf, setWatched, watchClassOf } from '../lib/watches.hl'
  21. import { todayStr } from '../lib/util.hl'
  22. // ---- pure helpers (static: see the header comment above) ------------------------------------
  23. // newest release first, `release` a plain 'YYYY-MM-DD' string; equal releases: the row found LATER first (as the old insertion
  24. // sort did). Mission 070: one merge sort over all rows (n log n) instead of inserting each row into a new list (n² list copies:
  25. // 1,287 rows on the creator's data = 0.8 M element copies per page, and since Hybriel 8efba065 every copy also feeds the
  26. // byte-triggered GC — /my/unwatched took 5.7 s). No list sort() (hybriel#1), so hand-written; `&`: no copy of the lists (#48).
  27. static mergeByReleaseDesc = (&a, &b) => {
  28. out = []
  29. let i = 0
  30. let j = 0
  31. while (i < a.length && j < b.length) {
  32. if (a[i].release >= b[j].release) { out.push(a[i]) i = i + 1 } else { out.push(b[j]) j = j + 1 }
  33. }
  34. while (i < a.length) { out.push(a[i]) i = i + 1 }
  35. while (j < b.length) { out.push(b[j]) j = j + 1 }
  36. return out
  37. }
  38. static sortByReleaseDesc = (&rows) => {
  39. // runs of one, the found order reversed (ties: later first), merged pairwise until one run is left
  40. let runs = []
  41. let k = rows.length - 1
  42. while (k >= 0) { runs.push([rows[k]]) k = k - 1 }
  43. if (runs.length == 0) { return [] }
  44. while (runs.length > 1) {
  45. next = []
  46. let r = 0
  47. while (r + 1 < runs.length) { next.push(mergeByReleaseDesc(&runs[r], runs[r + 1])) r = r + 2 }
  48. if (r < runs.length) { next.push(runs[r]) }
  49. runs = next
  50. }
  51. return runs[0]
  52. }
  53. // tracker#30 (mission 025): each followed title's slim cached card + episode rows (shows.hl cardOf / episodeRowsOf, in the
  54. // seasonsOfShow/episodesOfSeason order) and the user's cached watched set — no season or episode record is fetched per load
  55. static unwatchedRowsOf = (&userId) => {
  56. if (userId == null) { return [] }
  57. today = todayStr()
  58. watched = watchedSetOf(&userId)
  59. out = []
  60. for (sid of followedShowIds(&userId)) {
  61. c = cardOf(&sid)
  62. if (c != null) {
  63. for (e of episodeRowsOf(&sid)) {
  64. released = e.release != null && e.release <= today
  65. if (released && watched['episode:' + e.id] != true) {
  66. out.push({
  67. id = e.id showTitle = c.titleYear showHref = c.href
  68. episodeLabel = episodeCode(&e.s, &e.e) + ' · ' + e.title
  69. release = e.release watchClass = watchClassOf(false)
  70. })
  71. }
  72. }
  73. }
  74. }
  75. return sortByReleaseDesc(&out)
  76. }
  77. // ---- reactive members -----------------------------------------------------------------------
  78. session = null
  79. userId = userIdOfSession(&session)
  80. signedIn = userId != null
  81. // a plain copy of userId for `rows` (mission 047: session sync, see components/show.hl `me`)
  82. me = userId
  83. rows = signedIn ? unwatchedRowsOf(&me) : []
  84. hasRows = rows.length > 0
  85. noRows = !hasRows
  86. emptyText = signedIn ? 'No unwatched episodes.' : 'Sign in to see the shows you follow.'
  87. __title = 'Unwatched — ' + appTitle
  88. // HM49: component rules keep the existing selectors and shared theme variables.
  89. Style {
  90. unwatchedPage {
  91. display = 'block'
  92. }
  93. unwatchedRows {
  94. display = 'block'
  95. }
  96. unwatchedRow {
  97. display = 'grid'
  98. gridTemplateColumns = '2rem minmax(0, 1fr) auto'
  99. alignItems = 'center'
  100. gap = '0 .6rem'
  101. padding = '.5rem 0'
  102. @media {
  103. minWidth = '40rem'
  104. display = 'flex'
  105. }
  106. 'button.checkicon' {
  107. gridRow = 'span 2'
  108. }
  109. }
  110. unwatchedShow {
  111. fontWeight = '600'
  112. overflowWrap = 'anywhere'
  113. padding = '.7rem 0'
  114. margin = '-.7rem 0'
  115. @media {
  116. minWidth = '40rem'
  117. flex = 'none'
  118. }
  119. }
  120. unwatchedEpisode {
  121. gridColumn = '2 / 4'
  122. gridRow = '2'
  123. color = 'var(--color-text)'
  124. overflowWrap = 'anywhere'
  125. @media {
  126. minWidth = '40rem'
  127. flex = '1'
  128. }
  129. }
  130. unwatchedDate {
  131. gridRow = '1'
  132. gridColumn = '3'
  133. fontSize = '.85rem'
  134. color = 'var(--color-text-muted)'
  135. fontVariantNumeric = 'tabular-nums'
  136. @media {
  137. minWidth = '40rem'
  138. flex = 'none'
  139. }
  140. }
  141. }
  142. View {
  143. unwatchedPage {
  144. h1 { "Unwatched" }
  145. if (noRows) { p { class = "muted" emptyText } }
  146. if (hasRows) {
  147. unwatchedRows {
  148. for (row of rows) {
  149. unwatchedRow {
  150. button { type = "button" class = row.watchClass value = row.id "aria-label" = "mark episode watched"
  151. svg { viewBox = "0 0 24 24" width = "22" height = "22" "aria-hidden" = "true"
  152. circle { cx = "12" cy = "12" r = "10" }
  153. path { d = "M7 12.5 L10.5 16 L17 8.5" }
  154. }
  155. on click(e) { emit toggleEpisode(row.id) }
  156. }
  157. a { Style.unwatchedShow href = row.showHref row.showTitle }
  158. unwatchedEpisode { row.episodeLabel }
  159. unwatchedDate { row.release }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. // The client only ever ASSIGNS the `rows` the server already rebuilt — never calls the tainted
  167. // local helper itself (components/show.hl's own `on toggleEpisode` follows the same shape, and
  168. // the same reason: `unwatchedRowsOf` touches mpackdb-backed imports, so it compiles to nothing on
  169. // the client, hybriel#115/#116).
  170. on toggleEpisode(episodeId) {
  171. if (!signedIn) { return null }
  172. r = emit server unwatchedToggle('' + episodeId)
  173. if (r == null || r.error != null) { return null }
  174. rows = r.rows
  175. }
  176. // ---- the face (the trailing `session` is always the server's: hybriel#16) ----
  177. on server unwatchedToggle(episodeId, session) {
  178. uid = userIdOfSession(&session)
  179. if (uid == null) { return { error = 'you are not signed in' } }
  180. // mission SK: only an episode that exists, of a title this user may see (any text became a watch row before)
  181. ep = episodeId != null && hlTypeName(episodeId) == 'String' ? episodeById(&episodeId) : null
  182. show = ep != null ? showById(&ep.show) : null
  183. if (show == null || adultHiddenForUser(&show, &uid)) { return { error = 'no such episode' } }
  184. watchRows = watchesOfUser(&uid)
  185. ok = setWatched(&uid, 'episode', &episodeId, &watchRows, true)
  186. if (!ok) { return { error = 'could not save the watch' } }
  187. return { ok = true rows = unwatchedRowsOf(&uid) }
  188. }

Branches

Latest commits

  • d1a91be9Merge hm57-let: tracker#57 let only for reassigned namesmre
  • a404ed75Report HM57 audit, gates and integration notesmre
  • 1dcb87a7Use plain declarations for unchanged bindingsmre
  • b90395e3log: HM51 mergedmre
  • 9888d076Merge hm51-classes: tracker#51 views use Style referencesmre
  • 4399bc2fReference remaining component-owned root Style rulesmre
  • 9edcc2dflog: #58 live, HM57 startedmre
  • 73fa20ddMerge hm49b-styles: tracker#49 rest of the component stylesmre
  • aed12917Reference owned Style rules in genres and searchmre
  • 14195720log: HM49B done, HM51 startedmre
  • 78ee6b56Move remaining component styles into Style blocksmre
  • 7f04de33log: HM49Bmre
  • 00616cf3log: #49 batch merged, DP67 startedmre
  • d7232e86Merge hm49-styles: tracker#49 first batch of component stylesmre
  • 079f376dMove seven components' styles into Style blocksmre
  • 17d66feelog: #58 mergedmre
  • 69a6640bMerge hm58-map: tracker#58 project.hl only the mapmre
  • a85f7900Move route logic out of the project mapmre
  • 13dea5belog: #56 live, HM49 and HM58 startedmre
  • a31c8f2fdocs: tracker#36 remaining listmre