gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb638e99db638e99dMerge t38 (tracker#38 pagination, #35 Returning/Airing label) into main: LOG/STATUS keep both sides; pager gate follows #37's /people (everyone, last updated first: seed updatedAt); gates pager 229/0, browser 374/0mreb638e99d/components/search.hl

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

Branches

Latest commits

  • b638e99dMerge t38 (tracker#38 pagination, #35 Returning/Airing label) into main: LOG/STATUS keep both sides; pager gate follows #37's /people (everyone, last updated first: seed updatedAt); gates pager 229/0, browser 374/0mre
  • f8ffa4dbtracker: report 032 + The Remaining + #39mre
  • 7565a863tracker: LOG timemre
  • b10f00c8tracker#39: double episodes — migrated episodes whose TMDB id TMDB replaced are adopted by their number in the sync (old id -> migratedTmdbId); merge.hl step 3 merges each season's doubles at start (keeper: most watches > synced > first; watches moved/parked; tombstones into mergedEpisodes, nothing deleted); tools/count-duplicate-episodes.hl; gate fixture + paths-m039; live copy 850 -> 0 in 64 s; gates 373/0, 32/0, 52/0mre
  • 9448d643tracker#35 follow-up (mission 033): TVmaze 'Running' is labelled 'Returning', or 'Airing' while a non-special episode of the two newest seasons is released within today +-7 days (data unchanged); gate fixtures Running/Airing/Aired + a special; browser 366/0, kinds 32/0, franchises 52/0, pager 229/0, check-theme 0mre
  • 8751adb8tracker: report 032mre
  • 9bce1f65tracker mission 032: STATUS gate files + the hour-boundary flakemre
  • 718bfb89tracker#37 (mission 032): /people = everyone, last updated first (updatedAt stamped by the person fill; view built at boot, touched people first at once), photo + name tiles (person colour) with the /movies pagination, /people/<letter> removed; photo = our file, tmdbProfile, a cast/crew entry's profile (in-memory map at boot), else the new 'no photo' placeholder; new cast/crew/created_by people keep tmdbProfile; search people rows with the photo; /settings = the heading only; util.hl sortDesc starts from sorted runs (same result, 105k: 1.6 s -> 0.15 s); gates 369/0, 32/0, 52/0, check-theme 0; README/STATUS/LOGmre
  • 03ec792ftracker#38 (mission 033): pagination goes exactly to the clicked page — tilelist read the clicked button's text after pagination.hl's own handler had rebuilt the buttons (real clicks only); now li.current, else the button's own text; new gate tests/pager.mjs (5 lists x 11 pages, 390/1280, real + script clicks, Back/Forward) 229/0; browser 365/0, kinds 32/0, franchises 52/0, check-theme 0mre
  • 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