gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3909810d3909810dantcolony#40: mission references in README/STATUS/docs point to the moved missionsmre3909810d/components/search.hl

9.8 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.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 '../users.hl'
  27. import { showById, personById, posterUrlOf, titleWithYear, titlePath, typeWordOf, typeClassOf } from '../shows.hl'
  28. import { queryOfParam, dbSearch, webSearch, importTitle } from '../search.hl'
  29. import { applyCredits, persistDetails } from '../details.hl'
  30. // ---- pure helpers (static: an mpackdb-backed helper must be `static`, hybriel#115/#116; and LOCAL, mission 047) ----
  31. // tracker.worldapi.org#20/#21: our titles say Movie / Series / Show in their type's colour and link to their own page
  32. // (/movies/, /series/, /shows/<slug>); a TMDB result says Movie or TV (TMDB's search tells no TV type — its kind is known
  33. // once it is added)
  34. // everything the page shows for one text — replaced whole on every keystroke
  35. static resultsOf = (text) => {
  36. let t = text != null ? '' + text : ''
  37. let r = dbSearch(t)
  38. let titleRows = []
  39. for (x of r.titles) {
  40. let s = showById(x.id)
  41. if (s != null) { titleRows.push({ id = s.id title = titleWithYear(s) href = titlePath(s) posterUrl = posterUrlOf(s) typeLabel = typeWordOf(s) typeClass = typeClassOf(s) }) }
  42. }
  43. let peopleRows = []
  44. for (x of r.people) {
  45. let p = personById(x.id)
  46. if (p != null) { peopleRows.push({ id = p.id name = p.name href = '/person/' + p.urlSegment }) }
  47. }
  48. let note = ''
  49. if (t.trim() == '') { note = 'Search our shows, movies and people.' }
  50. else if (r.tooShort) { note = 'Type at least 2 letters.' }
  51. else if (titleRows.length == 0 && peopleRows.length == 0) { note = 'Nothing in our database yet.' }
  52. let more = ''
  53. if (r.titleCount > titleRows.length) { more = 'The first ' + titleRows.length + ' of ' + r.titleCount + ' titles — type more to narrow it down.' }
  54. return { text = t titleRows = titleRows peopleRows = peopleRows note = note more = more canFetch = t.trim() != '' && !r.tooShort }
  55. }
  56. static webRowsOf = (text) => {
  57. let w = webSearch(text)
  58. let rows = []
  59. for (x of w.rows) {
  60. rows.push({ key = x.kind + ':' + x.tmdbId kind = x.kind tmdbId = x.tmdbId title = x.year != '' ? x.title + ' (' + x.year + ')' : x.title
  61. overview = x.overview posterUrl = x.posterUrl typeLabel = x.kind == 'movie' ? 'Movie' : 'TV' typeClass = x.kind == 'movie' ? 'type-word type-movie' : 'type-word' })
  62. }
  63. let note = ''
  64. if (w.failed != null) { note = 'TMDB did not answer — try again in a moment.' }
  65. else if (rows.length == 0) { note = w.left > 0 ? 'TMDB found nothing we don\'t have already.' : 'TMDB found nothing either.' }
  66. return { text = text rows = rows note = note }
  67. }
  68. // ---- reactive members -----------------------------------------------------------------------
  69. q = null
  70. session = null
  71. userId = userIdOfSession(session)
  72. signedIn = userId != null
  73. signInHref = loginHref
  74. startText = queryOfParam(q)
  75. query = startText
  76. found = resultsOf(startText)
  77. // the text the lists on the page belong to (also an attribute of <search-page>: the gate waits for it)
  78. foundText = found.text
  79. titleRows = found.titleRows
  80. peopleRows = found.peopleRows
  81. hasTitles = titleRows.length > 0
  82. hasPeople = peopleRows.length > 0
  83. note = found.note
  84. hasNote = note != ''
  85. more = found.more
  86. hasMore = more != ''
  87. canFetch = found.canFetch
  88. webRows = []
  89. hasWeb = webRows.length > 0
  90. webNote = ''
  91. hasWebNote = webNote != ''
  92. webBusy = false
  93. busyText = ''
  94. isBusy = busyText != ''
  95. importError = ''
  96. hasImportError = importError != ''
  97. __title = startText != '' ? startText + ' — search — ' + appTitle : 'Search — ' + appTitle
  98. View {
  99. searchPage { "data-for" = foundText
  100. searchBar {
  101. 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) } }
  102. }
  103. if (hasNote) { p { id = "searchnote" class = "muted" note } }
  104. if (hasTitles) {
  105. searchSection { id = "titles"
  106. h2 { "Titles" }
  107. for (row of titleRows) {
  108. searchRow {
  109. img { class = "search-poster" src = row.posterUrl alt = "" }
  110. a { class = "search-title" href = row.href row.title }
  111. searchType { class = row.typeClass row.typeLabel }
  112. }
  113. }
  114. if (hasMore) { p { class = "muted search-more" more } }
  115. }
  116. }
  117. if (hasPeople) {
  118. searchSection { id = "people"
  119. h2 { "People" }
  120. for (row of peopleRows) {
  121. searchRow { a { class = "search-person" href = row.href row.name } }
  122. }
  123. }
  124. }
  125. if (canFetch) {
  126. webBar {
  127. button { id = "fetchweb" type = "button" "Fetch from web" on click(e) { emit searchFetch(e) } }
  128. if (webBusy) { span { class = "muted" "Asking TMDB…" } }
  129. }
  130. }
  131. if (hasWebNote) { p { id = "webnote" class = "muted" webNote } }
  132. if (hasImportError) { p { id = "importerror" class = "message" importError } }
  133. if (isBusy) { p { id = "importbusy" class = "muted" busyText } }
  134. if (hasWeb) {
  135. searchSection { id = "web"
  136. h2 { "From the web (TMDB)" }
  137. for (row of webRows) {
  138. webRow {
  139. img { class = "search-poster" src = row.posterUrl alt = "" }
  140. webText {
  141. webTitle { row.title }
  142. searchType { class = row.typeClass row.typeLabel }
  143. }
  144. button { type = "button" class = "inverted add" value = row.key "Add" on click(e) { emit searchPick(row.kind, row.tmdbId, row.title) } }
  145. }
  146. }
  147. }
  148. }
  149. Modal { id = "signin" title = "Sign in"
  150. p { "You need to sign in to add titles." }
  151. footer {
  152. button { type = "button" value = "close" "Close" }
  153. a { id = "signin-link" class = "button" href = signInHref "Sign in with ident" }
  154. }
  155. }
  156. }
  157. }
  158. // every keystroke: the address follows the text, then our database answers (an answer for an older text is dropped)
  159. on searchTyped(e) {
  160. let v = e.target.value
  161. query = v
  162. // the server decodes the path BEFORE routing: an encoded '/' would split the segment (404) and '?' / '#' would cut it —
  163. // in the address they become spaces (the search treats them as word breaks anyway)
  164. let t = v.replaceAll('/', ' ').replaceAll('?', ' ').replaceAll('#', ' ').trim()
  165. window.history.replaceState(window.history.state, '', t == '' ? '/search' : '/search/' + encodeURIComponent(t))
  166. let r = emit server searchDb(v)
  167. if (r == null || query != v) { return null }
  168. found = r
  169. webRows = []
  170. webNote = ''
  171. importError = ''
  172. }
  173. on searchFetch(e) {
  174. let v = query
  175. webBusy = true
  176. importError = ''
  177. let r = emit server searchWeb(v)
  178. webBusy = false
  179. if (r == null || query != v) { return null }
  180. webRows = r.rows
  181. webNote = r.note
  182. }
  183. // signed out: the modal, nothing is sent
  184. on searchPick(kind, tmdbId, title) {
  185. if (!signedIn) { document.getElementById('signin').showModal() return null }
  186. if (busyText != '') { return null }
  187. importError = ''
  188. busyText = 'Adding ' + title + ' …'
  189. let r = emit server searchImport(kind, '' + tmdbId)
  190. busyText = ''
  191. if (r == null || r.error != null) {
  192. importError = r != null ? 'Could not add it: ' + r.error : 'Could not add it.'
  193. return null
  194. }
  195. navigate(r.path)
  196. }
  197. // ---- the faces (unique names, hl:web dispatches by name across all files; the trailing `session` is the server's) ----
  198. on server searchDb(text) {
  199. return resultsOf(text != null ? '' + text : '')
  200. }
  201. on server searchWeb(text) {
  202. return webRowsOf(text != null ? '' + text : '')
  203. }
  204. on server searchImport(kind, tmdbId, session) {
  205. if (userIdOfSession(session) == null) { return { error = 'you are not signed in' } }
  206. let r = importTitle(kind, tmdbId)
  207. if (r.error != null) { return { error = r.error } }
  208. // tracker#28: the imported title's cast + crew, from the import's own details answer
  209. if (r.created == true && r.details != null) {
  210. let c = applyCredits(r.show, r.details)
  211. persistDetails()
  212. console.log('search import credits: ' + r.path + ' cast=' + c.cast + ' crew=' + c.crew + ' people=' + c.people + ' ms=' + c.ms + (c.error != '' ? ' error: ' + c.error : ''))
  213. }
  214. return { ok = true slug = r.slug path = r.path created = r.created }
  215. }

Branches

Latest commits

  • 3909810dantcolony#40: mission references in README/STATUS/docs point to the moved missionsmre
  • e63b1d28antcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 1cda451dtracker: Hybriel master 190aa11d (#127 both shapes, GC correctness fc838894) — conductor adopts despite /my/series 2.4x after jobs (memory 8.0 → 1.7 GB boot); see reports/071mre
  • c1fa2f2etracker (mission 071): Hybriel master 190aa11d measured on the real copy vs the live binary 8590df63 — NOT adopted (after the first-start jobs /my/series 2.4x slower, /series 1.6x, RSS swings 7.4-12.2 GB; fresh it is flat at 1.7-2.2 GB and /my/unwatched faster), vendor stays 8efba065, candidate kept in .scratch/w071/vendor-190aa11d; tests/kinds.mjs: collection seed off (its TMDB request broke check 1 in 1 of 4 runs); tests/realdata-071.sh + realdata-071-bench.mjs + tools/realdata-071-table.py; README + STATUS (numbers, how to repeat); gates 325/0, 32/0, 50/0mre
  • 8081350atracker docs (mission 070): README (summary, Config HL_GC_BYTES — kept at Hybriel's default, the 256 MiB setting is taken out of docker-compose.yml again: the jobs grew to 12+ GB with it too, see STATUS), Test (three gates), Deploy (first start ~50 min: kinds then seed, restart once after collections done, memory numbers), Vendored Hybriel 8efba065 + #48 audit, Files; STATUS mission 070 entry (merges, migrated counts, lambda audit, gates, RSS old vs new, how to repeat, open points); docs/kinds.md + docs/franchises.md job order; tests/realdata-070-*.sh, tools/count-migrated.hl, tools/ref-params.py, tools/lambda-audit.pymre
  • 1ad19c8ctracker: re-vendor Hybriel master 8efba065 (#126 GC by bytes, #48 lambda parameters copy) (mission 070): bin/hybriel sha256 50361e95…, plugins core crypto data fetch fs http http1 mpackdb proc smtp time web; lambda audit: 13 lambdas change a passed record/list (11 through a local alias), no caller relies on it — unchanged; 319 read-only lambda parameters get & (no copy per call: /my/schedule 2.35 → 0.46 s, /my/unwatched 13.7 → 5.7 s on the real copy); /my/unwatched one merge sort instead of n² inserts; docker-compose HL_GC_BYTES=268435456; deploy.sh runs kinds.mjs + franchises.mjs too (default ports 8700–8710); tests/realdata-070.mjs; gates browser 325/0, kinds 32/0, franchises 50/0mre
  • 46b21389tracker (mission 070, conductor): the sync never destroys migrated data — the one-time summary step MOVES a copied summary to migratedSummary (marker summaries-moved.txt) instead of clearing it; a migrated record's first title/genres/homepage/tagline TMDB replaces → migratedTitle/migratedGenres/migratedHomepage/migratedTagline, a migrated season's/episode's title/summary → migratedTitle/migratedSummary (set once); tests/peek-shows.hl prints them; gate 325/0mre
  • 749019b0Merge t19 (tracker#19 franchises + timelines) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs/faketmdb.mjs, both sides kept; franchise/timeline pages get #20's typed heading (Franchise | …, Timeline | …), their title links via titlePath (/movies|/series|/shows); the collection seed waits for repair, kinds and credits too; franchises.mjs URLs + 2 new checks; gates browser 323/0, kinds 32/0, franchises 50/0mre
  • daf49feaMerge t20 (tracker#20 typed headings + #21 series/shows split) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/search.hl/components/search.hl/browser.mjs/faketmdb.mjs, both sides kept; clock order backfill → repair → kinds → credits; withDetailsFields stores tmdbType + kind; gates: browser.mjs URLs → /series|/movies, typed h1 selectors; kinds.mjs repair/credits off, fixture name = seed name; browser 323/0, kinds 32/0mre
  • 20e09d89Merge t18 (tracker#18 delta sync) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs, both sides kept; pageShowOf summary = summaryOfmre
  • f83571c3tracker#18 (mission 067): daily sync by change lists — TMDB /tv|movie/changes (since the stored day, paged) + TVmaze /updates/shows → only our changed titles (followed: full step, unfollowed: light step — changed seasons, no TVmaze), full walk on first run / gap > 14 days / failed list; show record refreshed (title, tmdbSummary, tagline, status, genres …; renamed titles re-indexed); summary = the creator's own text (page: summary > tmdbSummary > tvmazeSummary), one-time clear of copied summaries (9,647 on the live copy); gate 261, tests/realdata-018*.mjs, README + STATUSmre
  • 1ed5457etracker#20 + #21 (mission 068): typed headings "<Type> | <name>" in type colours; TV titles split into Series (/series) and Shows (/shows) by TMDB type + Reality/Talk/News genres — kind stored by sync/import/adult backfill + new kind backfill (resumes), /movies/<slug>, /shows/<slug> of a series/movie → 301, /my/series + /my/shows, home 5 tiles + 3 rows, search/filmography labels; gates kinds 32 + browser 266, tests/realdata-068.mjs, tools/count-kinds.hl, docs/kinds.md, README + STATUSmre
  • f2b00674Merge t26 (tracker#26 + #28) into main (mission 062): short ids for every new person (castPersonId, guest route), guest stars stored on the title and created as people only when opened (/person/tmdb/<id>?show=<id> → 302), lean watch/follow clicks (showRow a small object, cast/crew from the slug, watches cached per user, face rows only after a season toggle); gate 311, tests/realdata-062.mjs, README + STATUSmre
  • 0553b51ftracker#19 (mission 066): franchises and timelines — tables, /franchises, /franchises/<slug>, /timelines/<slug> (Timeline | Release sort, series by last episode), the Prequel | Timeline | Sequel widget with the franchise above, the creator's editor, TMDB collection seed in the app (resumes, paced); gate tests/franchises.mjs 48/0 + browser.mjs 266/0, tests/realdata-066.mjs, docs/franchises.md, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • 10bb3f93tracker#28 (mission 061): full cast (all seasons, main cast by episodes, guest stars) + crew (created by, directed by, written by, screenplay, story, music) — stored by the details completion, the daily sync, the search import (one details request) and a background credits job (resumes, RSS limit); show page collapsed after 20 with client-side Show all; showBySlug via a slug map; gate 249, tests/realdata-028.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • 25a50bc4tracker#26 (mission 059): titles from a filmography are completed — on open (skeleton, step-wise face showComplete, no reload) and by the in-app details repair (resumes, TMDB-paced, series in parts); cast from TMDB credits; gate 231, tests/realdata-026.mjs, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.mjs, README + STATUSmre
  • 1704ec45tracker#17 (mission 057): season caret down/up, skeleton rows while a season loads, sessionless showSeasonEpisodes face (no page re-mount), client-only close; gate 214, tests/realdata-057.mjs, README + STATUSmre