tracker
All repositories: gitoria
9.6 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 updates the address (`navigate(path, replace = true)` → `/search/<text>`).// The route supplies `found` from search.hl's in-memory index (no table scan), so a reload or a// shared link opens the same results, rendered on the server. Titles (series + movies, with the year) and people (tracker#37:// with their photo, each → their page).// * "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 '../lib/app.hl'import { userIdOfSession, loginHref } from '../lib/users.hl'import { searchImportOf, resultsOf, webRowsOf } from '../lib/search.hl'import { queryOfParam } from '../lib/search-helpers.hl'import { warmReady, warmText } from '../lib/warm.hl'import { textArg } from '../lib/util.hl'import { allowHit, importPerHour } from '../lib/security.hl'// ---- 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 — ' + appTitle// mission T17 (boot time): the server listens while bootscan.hl still builds the lists / slug maps / search index (lib/warm.hl); until the 'all'// stage is there this page says so instead of showing half a mapwarming = !warmReady('all')warmNote = warming ? warmText() : ''// Component styles use the shared theme variables.Style {searchRow {display = 'flex'alignItems = 'center'gap = '.8rem'padding = '.4rem 0''.pill' {flex = 'none'}}webRow {display = 'flex'alignItems = 'center'gap = '.8rem'padding = '.4rem 0''.pill' {flex = 'none'}}searchPage {display = 'block'}searchBar {display = 'block'marginBottom = '.8rem'}'#searchinput' {display = 'block'width = '100%'padding = '.55rem .75rem'font = 'inherit'color = 'var(--color-text-strong)'background = 'var(--color-surface)'border = '0'borderRadius = 'var(--radius-small)'outline = 'none'focus {boxShadow = '0 0 0 2px ' + 'var(--color-accent)'}}searchSection {display = 'block'marginBottom = '1rem'h2 {margin = '.4rem 0 .2rem'fontSize = '.85rem'fontWeight = '600'letterSpacing = '.04em'textTransform = 'uppercase'color = 'var(--color-text-muted)'}}imgSearchPoster {flex = 'none'display = 'block'width = '2.5rem'height = 'auto'aspectRatio = '2 / 3'objectFit = 'cover'borderRadius = 'var(--radius-small)'background = 'var(--color-surface)'}searchTitle {flex = '1'minWidth = '0'fontWeight = '600'overflowWrap = 'anywhere'padding = '.7rem 0'margin = '-.7rem 0'}searchPerson {flex = '1'minWidth = '0'fontWeight = '600'color = 'var(--color-type5)'overflowWrap = 'anywhere'padding = '.7rem 0'margin = '-.7rem 0'}webText {flex = '1'minWidth = '0'display = 'flex'flexDirection = 'column'}webTitle {fontWeight = '600'color = 'var(--color-text-strong)'overflowWrap = 'anywhere'}webBar {display = 'flex'alignItems = 'center'gap = '.8rem'margin = '.6rem 0'}}View {searchPage { "data-for" = foundTextif (warming) { p { id = "warming" class = "message banner" warmNote } }searchBar {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 { Style.imgSearchPoster src = row.posterUrl alt = "" }a { Style.searchTitle 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 {img { Style.imgSearchPoster src = row.photoUrl alt = "" }a { Style.searchPerson 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 { Style.imgSearchPoster 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 and supplies the database results through `found`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()navigate(t == '' ? '/search' : '/search/' + encodeURIComponent(t), replace = true)webRows = []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(textArg(&text))}on server searchWeb(text) {return webRowsOf(textArg(&text))}on server searchImport(kind, tmdbId, session) {uid = userIdOfSession(&session)if (uid == null) { return { error = 'you are not signed in' } }// mission SK: an import is a TMDB request and a new record — at most `importPerHour` an hour per user; the id is a number or textif (hlTypeName(tmdbId) != 'Number' && hlTypeName(tmdbId) != 'String') { return { error = 'bad TMDB id' } }if (!allowHit('import', &uid, &importPerHour, 3600000)) { return { error = 'too many imports this hour — try again later' } }return searchImportOf(&kind, tmdbId)}
Branches
Latest commits
- 4b54f6f9Merge branch 'records-audit' into mainTracker
- cab4a3bc|||PR records: branch audit, PR-onlyTracker
- 641e1c4cMerge branch 'records-dp71' into mainTracker
- 85a6e9f5|||PR records: DP71 checked in ChromeTracker
- f5be5f18records: gitoria PR-only planTracker
- 46a37036records: DP71 liveTracker
- 3bcb7039Status/log: DP71 in progressTracker
- 5b3a5693Log: SR1b merged via PR 2, DP71 startedTracker
- 783957c2Merge branch 'sr1-search' into mainTracker
- 792b9652README: search results come from the routeTracker
- fd8570b1|||PR search: one server exchange per keystrokeTracker
- e8f5cbcaLog: SR1 result, SR1bTracker
- 8ad275a4Log/status: tracker 68, SR1Tracker
- f5a06a0fLog: gitoria push setup, SR1Tracker
- d6b109baMission SR1mre
- 608b7558Log: FF1 merged via PR #1mre
- 2939d94cMerge branch 'ff1-gate-failfast' into mainTracker
- c934361a|||PR tests: gates fail fast when the app exits during startmre
- d714ae42Log/status: AP56 closed out, FF1mre
- a429d088Mission FF1mre