tracker
All repositories: gitoria
9.5 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-helpers.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 '../lib/users.hl'import { showById, personById, posterUrlOf, titleWithYear, titlePath, typeWordOf, typeClassOf } from '../lib/shows.hl'import { dbSearch, webSearch } from '../lib/search.hl'import { queryOfParam } from '../lib/search-helpers.hl'import { importWithCredits } from '../lib/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) => {t = text != null ? '' + text : ''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) => {w = webSearch(text)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" class = "primary" "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 primary" 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) {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)t = v.replaceAll('/', ' ').replaceAll('?', ' ').replaceAll('#', ' ').trim()window.history.replaceState(window.history.state, '', t == '' ? '/search' : '/search/' + encodeURIComponent(t))r = emit server searchDb(v)if (r == null || query != v) { return null }found = rwebRows = []webNote = ''importError = ''}on searchFetch(e) {v = querywebBusy = trueimportError = ''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 + ' …'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' } }// tracker#28: with the imported title's cast + crew, from the import's own details answer (details.hl)r = importWithCredits(kind, tmdbId)if (r.error != null) { return { error = r.error } }return { ok = true slug = r.slug path = r.path created = r.created }}
Branches
- mainmain branch
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