gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8f1d45428f1d4542tracker#40: superseded collections — a TMDB collection timeline whose titles are all in one curated timeline is hidden (supersededBy; kept: own page + editor finder), set by the collection seed when it makes one and by the curated build (lifted when the cover is gone); partly covered ones join that franchise; no second widget (First Contact: only Star Trek — Prime); gate franchiseseed 26/0, browser 365/0, kinds 32/0, franchises 53/0, check-theme 0; real copy 24 supersededmre8f1d4542/components/search.hl

9.5 KB

  1. // components/search.hl — `/search` and `/search/<text>` (tracker.worldapi.org#14). Creator's words: "in the actionbar a
  2. // search symbol that first checks our database and then has a fetch from web button that actually searches tmdb then for
  3. // things we dont have yet". The header's search icon (components/main.hl) opens this page.
  4. //
  5. // * OUR DATABASE as you type: every keystroke asks the face `searchDb` (search.hl's in-memory index — no table scan) and the
  6. // lists are replaced whole; the address follows the text (`history.replaceState` → `/search/<text>`), so a reload or a
  7. // shared link opens the same results, rendered on the server. Titles (series + movies, with the year) and people.
  8. // * "Fetch from web": the face `searchWeb` asks TMDB (search/multi) and lists the titles we DON'T have yet; "Add" imports
  9. // one (`searchImport`: a new show, then the daily sync's own `syncShow` — seasons, episodes, poster, ids) and opens its
  10. // page. Signed out, "Add" opens the sign-in modal and sends nothing; searching itself needs no sign-in.
  11. //
  12. // THE ADDRESS: `/search/<text>`, not `/search?q=` (the architect's reading) — hl:web gives a page its route's path params
  13. // but no query string, so the text travels as the route param `q`. A full page load gets it already decoded by the server, a
  14. // client-side navigation still encoded — search-helpers.hl `queryOfParam` decodes what is left. '/', '?', '#' go into the address
  15. // as spaces (see searchTyped).
  16. //
  17. // HYBRIEL TRAPS (mission 052): hybriel#121 (rows appended after a session face appear twice) — no list here is ever
  18. // appended to, every list is replaced whole; hybriel#122 (after a session face, members using a route param + session are
  19. // re-derived without the route param) — no member reads both: the results come from `q` alone, the sign-in state from
  20. // `session` alone, and the only session face (`searchImport`) answers no list. The gate checks the lists after a failed
  21. // import (a session face that stays on the page).
  22. parent './main.hl'
  23. import Modal from './modal.hl'
  24. import { navigate } from 'hl:web'
  25. import { appTitle } from '../project.hl'
  26. import { userIdOfSession, loginHref } from '../lib/users.hl'
  27. import { showById, personById, posterUrlOf, titleWithYear, titlePath, typeWordOf, typeClassOf } from '../lib/shows.hl'
  28. import { dbSearch, webSearch } from '../lib/search.hl'
  29. import { queryOfParam } from '../lib/search-helpers.hl'
  30. import { importWithCredits } from '../lib/details.hl'
  31. // ---- pure helpers (static: an mpackdb-backed helper must be `static`, hybriel#115/#116; and LOCAL, mission 047) ----
  32. // tracker.worldapi.org#20/#21: our titles say Movie / Series / Show in their type's colour and link to their own page
  33. // (/movies/, /series/, /shows/<slug>); a TMDB result says Movie or TV (TMDB's search tells no TV type — its kind is known
  34. // once it is added)
  35. // everything the page shows for one text — replaced whole on every keystroke
  36. static resultsOf = (text) => {
  37. t = text != null ? '' + text : ''
  38. r = dbSearch(t)
  39. let titleRows = []
  40. for (x of r.titles) {
  41. let s = showById(x.id)
  42. if (s != null) { titleRows.push({ id = s.id title = titleWithYear(s) href = titlePath(s) posterUrl = posterUrlOf(s) typeLabel = typeWordOf(s) typeClass = typeClassOf(s) }) }
  43. }
  44. let peopleRows = []
  45. for (x of r.people) {
  46. let p = personById(x.id)
  47. if (p != null) { peopleRows.push({ id = p.id name = p.name href = '/person/' + p.urlSegment }) }
  48. }
  49. let note = ''
  50. if (t.trim() == '') { note = 'Search our shows, movies and people.' }
  51. else if (r.tooShort) { note = 'Type at least 2 letters.' }
  52. else if (titleRows.length == 0 && peopleRows.length == 0) { note = 'Nothing in our database yet.' }
  53. let more = ''
  54. if (r.titleCount > titleRows.length) { more = 'The first ' + titleRows.length + ' of ' + r.titleCount + ' titles — type more to narrow it down.' }
  55. return { text = t titleRows = titleRows peopleRows = peopleRows note = note more = more canFetch = t.trim() != '' && !r.tooShort }
  56. }
  57. static webRowsOf = (text) => {
  58. w = webSearch(text)
  59. rows = []
  60. for (x of w.rows) {
  61. rows.push({ key = x.kind + ':' + x.tmdbId kind = x.kind tmdbId = x.tmdbId title = x.year != '' ? x.title + ' (' + x.year + ')' : x.title
  62. overview = x.overview posterUrl = x.posterUrl typeLabel = x.kind == 'movie' ? 'Movie' : 'TV' typeClass = x.kind == 'movie' ? 'type-word type-movie' : 'type-word' })
  63. }
  64. let note = ''
  65. if (w.failed != null) { note = 'TMDB did not answer — try again in a moment.' }
  66. else if (rows.length == 0) { note = w.left > 0 ? 'TMDB found nothing we don\'t have already.' : 'TMDB found nothing either.' }
  67. return { text = text rows = rows note = note }
  68. }
  69. // ---- reactive members -----------------------------------------------------------------------
  70. q = null
  71. session = null
  72. userId = userIdOfSession(session)
  73. signedIn = userId != null
  74. signInHref = loginHref
  75. startText = queryOfParam(q)
  76. query = startText
  77. found = resultsOf(startText)
  78. // the text the lists on the page belong to (also an attribute of <search-page>: the gate waits for it)
  79. foundText = found.text
  80. titleRows = found.titleRows
  81. peopleRows = found.peopleRows
  82. hasTitles = titleRows.length > 0
  83. hasPeople = peopleRows.length > 0
  84. note = found.note
  85. hasNote = note != ''
  86. more = found.more
  87. hasMore = more != ''
  88. canFetch = found.canFetch
  89. webRows = []
  90. hasWeb = webRows.length > 0
  91. webNote = ''
  92. hasWebNote = webNote != ''
  93. webBusy = false
  94. busyText = ''
  95. isBusy = busyText != ''
  96. importError = ''
  97. hasImportError = importError != ''
  98. __title = startText != '' ? startText + ' — search — ' + appTitle : 'Search — ' + appTitle
  99. View {
  100. searchPage { "data-for" = foundText
  101. searchBar {
  102. input { id = "searchinput" type = "search" name = "q" value = startText placeholder = "Shows, movies, people" autocomplete = "off" autofocus = "autofocus" enterkeyhint = "search" "aria-label" = "Search" on input(e) { emit searchTyped(e) } }
  103. }
  104. if (hasNote) { p { id = "searchnote" class = "muted" note } }
  105. if (hasTitles) {
  106. searchSection { id = "titles"
  107. h2 { "Titles" }
  108. for (row of titleRows) {
  109. searchRow {
  110. img { class = "search-poster" src = row.posterUrl alt = "" }
  111. a { class = "search-title" href = row.href row.title }
  112. searchType { class = row.typeClass row.typeLabel }
  113. }
  114. }
  115. if (hasMore) { p { class = "muted search-more" more } }
  116. }
  117. }
  118. if (hasPeople) {
  119. searchSection { id = "people"
  120. h2 { "People" }
  121. for (row of peopleRows) {
  122. searchRow { a { class = "search-person" href = row.href row.name } }
  123. }
  124. }
  125. }
  126. if (canFetch) {
  127. webBar {
  128. button { id = "fetchweb" type = "button" class = "primary" "Fetch from web" on click(e) { emit searchFetch(e) } }
  129. if (webBusy) { span { class = "muted" "Asking TMDB…" } }
  130. }
  131. }
  132. if (hasWebNote) { p { id = "webnote" class = "muted" webNote } }
  133. if (hasImportError) { p { id = "importerror" class = "message" importError } }
  134. if (isBusy) { p { id = "importbusy" class = "muted" busyText } }
  135. if (hasWeb) {
  136. searchSection { id = "web"
  137. h2 { "From the web (TMDB)" }
  138. for (row of webRows) {
  139. webRow {
  140. img { class = "search-poster" src = row.posterUrl alt = "" }
  141. webText {
  142. webTitle { row.title }
  143. searchType { class = row.typeClass row.typeLabel }
  144. }
  145. button { type = "button" class = "inverted add" value = row.key "Add" on click(e) { emit searchPick(row.kind, row.tmdbId, row.title) } }
  146. }
  147. }
  148. }
  149. }
  150. Modal { id = "signin" title = "Sign in"
  151. p { "You need to sign in to add titles." }
  152. footer {
  153. button { type = "button" value = "close" "Close" }
  154. a { id = "signin-link" class = "button primary" href = signInHref "Sign in with ident" }
  155. }
  156. }
  157. }
  158. }
  159. // every keystroke: the address follows the text, then our database answers (an answer for an older text is dropped)
  160. on searchTyped(e) {
  161. v = e.target.value
  162. query = v
  163. // the server decodes the path BEFORE routing: an encoded '/' would split the segment (404) and '?' / '#' would cut it —
  164. // in the address they become spaces (the search treats them as word breaks anyway)
  165. t = v.replaceAll('/', ' ').replaceAll('?', ' ').replaceAll('#', ' ').trim()
  166. window.history.replaceState(window.history.state, '', t == '' ? '/search' : '/search/' + encodeURIComponent(t))
  167. r = emit server searchDb(v)
  168. if (r == null || query != v) { return null }
  169. found = r
  170. webRows = []
  171. webNote = ''
  172. importError = ''
  173. }
  174. on searchFetch(e) {
  175. v = query
  176. webBusy = true
  177. importError = ''
  178. r = emit server searchWeb(v)
  179. webBusy = false
  180. if (r == null || query != v) { return null }
  181. webRows = r.rows
  182. webNote = r.note
  183. }
  184. // signed out: the modal, nothing is sent
  185. on searchPick(kind, tmdbId, title) {
  186. if (!signedIn) { document.getElementById('signin').showModal() return null }
  187. if (busyText != '') { return null }
  188. importError = ''
  189. busyText = 'Adding ' + title + ' …'
  190. r = emit server searchImport(kind, '' + tmdbId)
  191. busyText = ''
  192. if (r == null || r.error != null) {
  193. importError = r != null ? 'Could not add it: ' + r.error : 'Could not add it.'
  194. return null
  195. }
  196. navigate(r.path)
  197. }
  198. // ---- the faces (unique names, hl:web dispatches by name across all files; the trailing `session` is the server's) ----
  199. on server searchDb(text) {
  200. return resultsOf(text != null ? '' + text : '')
  201. }
  202. on server searchWeb(text) {
  203. return webRowsOf(text != null ? '' + text : '')
  204. }
  205. on server searchImport(kind, tmdbId, session) {
  206. if (userIdOfSession(session) == null) { return { error = 'you are not signed in' } }
  207. // tracker#28: with the imported title's cast + crew, from the import's own details answer (details.hl)
  208. r = importWithCredits(kind, tmdbId)
  209. if (r.error != null) { return { error = r.error } }
  210. return { ok = true slug = r.slug path = r.path created = r.created }
  211. }

Branches

Latest commits

  • 8f1d4542tracker#40: superseded collections — a TMDB collection timeline whose titles are all in one curated timeline is hidden (supersededBy; kept: own page + editor finder), set by the collection seed when it makes one and by the curated build (lifted when the cover is gone); partly covered ones join that franchise; no second widget (First Contact: only Star Trek — Prime); gate franchiseseed 26/0, browser 365/0, kinds 32/0, franchises 53/0, check-theme 0; real copy 24 supersededmre
  • 7d4b293dtracker#40: "Franchises" in the main menu (desktop header after People, phone sidebar) → /franchises, marked on franchise and timeline pages; gates 365/0, 32/0, 53/0, 24/0, check-theme 0mre
  • 93dfb0batracker#40 (mission 034): the curated franchises — data/franchises.json (17 franchises, 31 timelines, 285 TMDB titles, movies + series, in-universe/release order, 12 TMDB collections attached); lib/franchiseseed.hl + jobs.hl franchiseSeedTick (last start job, imports missing titles via details.hl importWithCredits = the search's Add, one per step paced, then one build; franchiseseed.db: editor changes win, the creator's same-name franchise adopted / timeline left alone, 404 remembered, resumable, idempotent); timeline heads 'N titles · in-universe order' (orderKind) and wrap on a phone; series pages show the widget; new gate tests/franchiseseed.mjs (5th in deploy.sh), the others run with TRACKER_FRANCHISE_SEED=0; gates 365/0, 32/0, 52/0, 24/0, check-theme 0; real copy 196 imported, 0 failed, 7 min, restart unchanged=31mre
  • 96ba683adeploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the scriptmre
  • eb3b9205tracker: report 031mre
  • 9b5d2e89tracker mission 031: README (What it does, Test: four gates + the #32 checks, Files: theme/, new pages), STATUS (real copy, A/B load, how to repeat, open points), LOGmre
  • 39950e4ctracker#32 (mission 031): the WorldAPI theme (theme/ vendored verbatim from layouts.worldapi.org 85b5654; styles.hl inherits it: accent green-dark, type colours 1-6; own base/header rules, row lines, genre-pill and inverted-button frames removed, the season foldable keeps its line; check-theme 21 -> 0, 4th deploy gate; main actions class primary) and the #32 header (theme AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst: desktop brand, search, Series|Shows|Movies|Genres|People, user icon with Unwatched..Settings, Logout; signed out the ident selector, phone the iD icon dropdown; phone menu in the sidebar overlay; marked entry by :has); /find -> /search/<q>, /genres, /people(/<letter>), /settings; main { ContentFirst { slot } } works around the hl:web one-line slot bug; gates 365/0, 32/0, 52/0, check-theme 0mre
  • a386dc92tracker: reports 029 + 030mre
  • 71e0fd7dtracker missions 029 + 030: README (What it does, Files, gate count), STATUS (real-copy numbers, how to repeat, open points), LOGmre
  • d36ea6eatracker#34 + #35 (mission 030): Follow directly under the poster, as wide as the poster (show.hl, styles.hl); the status pill next to a series' title — TVmaze's status (new tvmazeStatus, stored by the sync's TVmaze merge) else TMDB's, TVmaze Ended + TMDB Canceled = Canceled, inverted (filled, dark text, no border), green running / yellow pending / red canceled / muted ended (shows.hl statusOf); the daily delta asks TVmaze's status of an unfollowed series TVmaze's change list names (dailysync.hl syncRunStep, sync.hl syncTvmazeStatus); the status backfill after the details repair (backfill.hl, jobs.hl statusTick; resumable, 550 ms per TVmaze request); gates 354/0, 32/0, 52/0mre
  • 7d7d4487tracker#33 (mission 029): reduced titles — every title TMDB's details never went through this app (no detailsAt, no tmdbSync) is incomplete (shows.hl isIncomplete; the old tracker's migrated rows passed #26's test: 5,697 non-adult on the live copy, 691 series without seasons); the repair job does the visibly reduced first (shows.hl missingParts), the page completes one on open; a title TMDB has no poster for (The Remaining) shows the placeholder; tools/count-incomplete.hl; gate fixtures stand for synced titles (tmdbSync), tests/seed-reduced.hl + #33 checks; gates 347/0, 32/0, 52/0mre
  • 661c2592tracker: report 028mre
  • 27c916fatracker mission 028: README ("Code order", the new file map), STATUS (counts before/after, tests, how to repeat, open), LOGmre
  • d924f398tracker mission 028: comments name the new files (sync.hl, dailysync.hl, backfill.hl, credits.hl, jobs.hl, images.hl …); tools/ref-params.py + tools/lambda-audit.py also scan lib/ (they globbed the root only), lambda-audit counts a plain `x = p` alias like `let x = p`mre
  • 2e89b968tracker mission 028 (code order) 5/5 let: `let` only where a variable is reassigned — 667 never-reassigned lets became plain declarations (project.hl, lib/, components/, tools/, tests/); kept: 264 in loop bodies (a plain declaration there is 'Cannot reassign' on the 2nd pass), 234 reassigned, 27 whose name is also a member/outer/free name (a plain write would rebind it); tools/let-audit.py decides and fixes (README 'Code order'); tests/realdata-m028.{sh,mjs} = the page-output diff on a real copy; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
  • 54796ff2tracker mission 028 (code order) 4/5 thin faces + last copies: the show page's check/follow faces call lib/watches.hl toggleWatched / toggleSeasonWatched (seasonAllWatched moved there) and lib/follows.hl toggleFollowed; both logins (header selector face, /login/callback) share lib/users.hl userOfCode; todayStr/listOf copies in components and the export readers copied into tools/migrate.hl + tools/old-short-ids.hl now once (lib/util.hl, lib/export.hl); gates 342/0, 32/0, 52/0; old-short-ids output byte-identical, migrate output identicalmre
  • 06b078e3tracker mission 028 (code order) 3/5 project.hl is the map: config, routes, wiring and a feature → file index (914 → 258 lines); the background jobs (daily sync run, backfills, details repair, credits job, merge, short ids, collection seed) moved unchanged into lib/jobs.hl (a class: their state is reassigned every step, a static cannot be; one instance made after the server), the login callback into lib/users.hl, poster/photo serving into lib/images.hl, the /shows/<slug> rule into lib/shows.hl showsMovedPath; route handlers are thin wrappers; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
  • 94716fd2tracker mission 028 (code order) 2/5 util + topics: lib/util.hl holds envOr, storageDir, postersDir, profilesDir, newId, hexDigits, todayStr, dateOr, textOr, hasId, listOr, firstOf, sortDesc once (were copied into up to 5 files); tmdbsync.hl split into tmdb.hl (TMDB/TVmaze requests), sync.hl (one title's sync), sync-helpers.hl, backfill.hl; details.hl split into details.hl, credits.hl, credits-helpers.hl (isIncomplete to shows.hl); search-helpers.hl (words, query, ranking, slugs); collections.hl (the TMDB collection seed, out of franchises.hl); deltasync.hl renamed dailysync.hl; no behaviour change: gates 342/0, 32/0, 52/0, real-copy pages identicalmre
  • 186079b0tracker mission 028 (code order) 1/5 move: every root .hl except project.hl into lib/ (styles.hl into components/), import paths only; gates 342/0, 32/0, 52/0; real-copy pages identicalmre
  • 4f47f181tracker: report 027mre