tracker
All repositories: gitoria
9.8 KB
// components/search.hl — `/search` and `/search/<text>` (tracker.worldapi.org#14). Creator's words: "in the actionbar a// search symbol that first checks our database and then has a fetch from web button that actually searches tmdb then for// things we dont have yet". The header's search icon (components/main.hl) opens this page.//// * OUR DATABASE as you type: every keystroke asks the face `searchDb` (search.hl's in-memory index — no table scan) and the// lists are replaced whole; the address follows the text (`history.replaceState` → `/search/<text>`), so a reload or a// shared link opens the same results, rendered on the server. Titles (series + movies, with the year) and people.// * "Fetch from web": the face `searchWeb` asks TMDB (search/multi) and lists the titles we DON'T have yet; "Add" imports// one (`searchImport`: a new show, then the daily sync's own `syncShow` — seasons, episodes, poster, ids) and opens its// page. Signed out, "Add" opens the sign-in modal and sends nothing; searching itself needs no sign-in.//// THE ADDRESS: `/search/<text>`, not `/search?q=` (the architect's reading) — hl:web gives a page its route's path params// 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// client-side navigation still encoded — search.hl `queryOfParam` decodes what is left. '/', '?', '#' go into the address// as spaces (see searchTyped).//// HYBRIEL TRAPS (mission 052): hybriel#121 (rows appended after a session face appear twice) — no list here is ever// appended to, every list is replaced whole; hybriel#122 (after a session face, members using a route param + session are// re-derived without the route param) — no member reads both: the results come from `q` alone, the sign-in state from// `session` alone, and the only session face (`searchImport`) answers no list. The gate checks the lists after a failed// import (a session face that stays on the page).parent './main.hl'import Modal from './modal.hl'import { navigate } from 'hl:web'import { appTitle } from '../project.hl'import { userIdOfSession, loginHref } from '../users.hl'import { showById, personById, posterUrlOf, titleWithYear, titlePath, typeWordOf, typeClassOf } from '../shows.hl'import { queryOfParam, dbSearch, webSearch, importTitle } from '../search.hl'import { applyCredits, persistDetails } from '../details.hl'// ---- pure helpers (static: an mpackdb-backed helper must be `static`, hybriel#115/#116; and LOCAL, mission 047) ----// tracker.worldapi.org#20/#21: our titles say Movie / Series / Show in their type's colour and link to their own page// (/movies/, /series/, /shows/<slug>); a TMDB result says Movie or TV (TMDB's search tells no TV type — its kind is known// once it is added)// everything the page shows for one text — replaced whole on every keystrokestatic resultsOf = (text) => {let t = text != null ? '' + text : ''let r = dbSearch(t)let titleRows = []for (x of r.titles) {let s = showById(x.id)if (s != null) { titleRows.push({ id = s.id title = titleWithYear(s) href = titlePath(s) posterUrl = posterUrlOf(s) typeLabel = typeWordOf(s) typeClass = typeClassOf(s) }) }}let peopleRows = []for (x of r.people) {let p = personById(x.id)if (p != null) { peopleRows.push({ id = p.id name = p.name href = '/person/' + p.urlSegment }) }}let note = ''if (t.trim() == '') { note = 'Search our shows, movies and people.' }else if (r.tooShort) { note = 'Type at least 2 letters.' }else if (titleRows.length == 0 && peopleRows.length == 0) { note = 'Nothing in our database yet.' }let more = ''if (r.titleCount > titleRows.length) { more = 'The first ' + titleRows.length + ' of ' + r.titleCount + ' titles — type more to narrow it down.' }return { text = t titleRows = titleRows peopleRows = peopleRows note = note more = more canFetch = t.trim() != '' && !r.tooShort }}static webRowsOf = (text) => {let w = webSearch(text)let rows = []for (x of w.rows) {rows.push({ key = x.kind + ':' + x.tmdbId kind = x.kind tmdbId = x.tmdbId title = x.year != '' ? x.title + ' (' + x.year + ')' : x.titleoverview = x.overview posterUrl = x.posterUrl typeLabel = x.kind == 'movie' ? 'Movie' : 'TV' typeClass = x.kind == 'movie' ? 'type-word type-movie' : 'type-word' })}let note = ''if (w.failed != null) { note = 'TMDB did not answer — try again in a moment.' }else if (rows.length == 0) { note = w.left > 0 ? 'TMDB found nothing we don\'t have already.' : 'TMDB found nothing either.' }return { text = text rows = rows note = note }}// ---- reactive members -----------------------------------------------------------------------q = nullsession = nulluserId = userIdOfSession(session)signedIn = userId != nullsignInHref = loginHrefstartText = queryOfParam(q)query = startTextfound = resultsOf(startText)// the text the lists on the page belong to (also an attribute of <search-page>: the gate waits for it)foundText = found.texttitleRows = found.titleRowspeopleRows = found.peopleRowshasTitles = titleRows.length > 0hasPeople = peopleRows.length > 0note = found.notehasNote = note != ''more = found.morehasMore = more != ''canFetch = found.canFetchwebRows = []hasWeb = webRows.length > 0webNote = ''hasWebNote = webNote != ''webBusy = falsebusyText = ''isBusy = busyText != ''importError = ''hasImportError = importError != ''__title = startText != '' ? startText + ' — search — ' + appTitle : 'Search — ' + appTitleView {searchPage { "data-for" = foundTextsearchBar {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) } }}if (hasNote) { p { id = "searchnote" class = "muted" note } }if (hasTitles) {searchSection { id = "titles"h2 { "Titles" }for (row of titleRows) {searchRow {img { class = "search-poster" src = row.posterUrl alt = "" }a { class = "search-title" href = row.href row.title }searchType { class = row.typeClass row.typeLabel }}}if (hasMore) { p { class = "muted search-more" more } }}}if (hasPeople) {searchSection { id = "people"h2 { "People" }for (row of peopleRows) {searchRow { a { class = "search-person" href = row.href row.name } }}}}if (canFetch) {webBar {button { id = "fetchweb" type = "button" "Fetch from web" on click(e) { emit searchFetch(e) } }if (webBusy) { span { class = "muted" "Asking TMDB…" } }}}if (hasWebNote) { p { id = "webnote" class = "muted" webNote } }if (hasImportError) { p { id = "importerror" class = "message" importError } }if (isBusy) { p { id = "importbusy" class = "muted" busyText } }if (hasWeb) {searchSection { id = "web"h2 { "From the web (TMDB)" }for (row of webRows) {webRow {img { class = "search-poster" src = row.posterUrl alt = "" }webText {webTitle { row.title }searchType { class = row.typeClass row.typeLabel }}button { type = "button" class = "inverted add" value = row.key "Add" on click(e) { emit searchPick(row.kind, row.tmdbId, row.title) } }}}}}Modal { id = "signin" title = "Sign in"p { "You need to sign in to add titles." }footer {button { type = "button" value = "close" "Close" }a { id = "signin-link" class = "button" href = signInHref "Sign in with ident" }}}}}// every keystroke: the address follows the text, then our database answers (an answer for an older text is dropped)on searchTyped(e) {let v = e.target.valuequery = v// the server decodes the path BEFORE routing: an encoded '/' would split the segment (404) and '?' / '#' would cut it —// in the address they become spaces (the search treats them as word breaks anyway)let t = v.replaceAll('/', ' ').replaceAll('?', ' ').replaceAll('#', ' ').trim()window.history.replaceState(window.history.state, '', t == '' ? '/search' : '/search/' + encodeURIComponent(t))let r = emit server searchDb(v)if (r == null || query != v) { return null }found = rwebRows = []webNote = ''importError = ''}on searchFetch(e) {let v = querywebBusy = trueimportError = ''let r = emit server searchWeb(v)webBusy = falseif (r == null || query != v) { return null }webRows = r.rowswebNote = r.note}// signed out: the modal, nothing is senton searchPick(kind, tmdbId, title) {if (!signedIn) { document.getElementById('signin').showModal() return null }if (busyText != '') { return null }importError = ''busyText = 'Adding ' + title + ' …'let r = emit server searchImport(kind, '' + tmdbId)busyText = ''if (r == null || r.error != null) {importError = r != null ? 'Could not add it: ' + r.error : 'Could not add it.'return null}navigate(r.path)}// ---- the faces (unique names, hl:web dispatches by name across all files; the trailing `session` is the server's) ----on server searchDb(text) {return resultsOf(text != null ? '' + text : '')}on server searchWeb(text) {return webRowsOf(text != null ? '' + text : '')}on server searchImport(kind, tmdbId, session) {if (userIdOfSession(session) == null) { return { error = 'you are not signed in' } }let r = importTitle(kind, tmdbId)if (r.error != null) { return { error = r.error } }// tracker#28: the imported title's cast + crew, from the import's own details answerif (r.created == true && r.details != null) {let c = applyCredits(r.show, r.details)persistDetails()console.log('search import credits: ' + r.path + ' cast=' + c.cast + ' crew=' + c.crew + ' people=' + c.people + ' ms=' + c.ms + (c.error != '' ? ' error: ' + c.error : ''))}return { ok = true slug = r.slug path = r.path created = r.created }}
Branches
- mainmain branch
Latest commits
- 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
- f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
- f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
- 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
- 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
- c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre