gitoriaLog in with ident

tracker

All repositories: gitoria

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

Branches

Latest commits

  • 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
  • dc1d4be4tracker mission 027: Hybriel master 06617221 vendored (plugin allocator fixes 3a781359 + 413f60e4); real copy RSS through first-start jobs + 400 loads flat ~2.55 GB (190aa11d 2.3 -> 5.6 GB), page times <= 1.1x; gates 342/0, 32/0, 52/0mre
  • 84e1b3e1tracker: reports 025 + 026mre
  • dc40d859tracker#31 (mission 026): duplicate titles merged — the 68 type+tmdbId pairs held by 157 records were the old tracker's (all migrated); merge.hl repair job (own clock, before the TMDB jobs) keeps one keeper per title (follows/watches > old short id > oldest), moves follows, watches, seasons, cast, credits, timelines, tombstones the rest (mergedInto, never deleted), slugs + short ids 301 to the keeper; stray seasons merged into their listed twin (Reacher S3 watches) or linked when watched; search import re-checks before its put; deploy.sh waits up to 90 s for 200; real copy 68 -> 0 dup ids, az5b2 follows/watches equal; gates 342/0, 32/0, 52/0mre
  • 2667da05tracker#30 (mission 025): /my/ pages from slim cached title cards, episode rows and watch sets (after the jobs /my/series 1.8 s -> 0.06 s, /my/unwatched 4.1 -> 0.18 s); timeline page shows its name once; franchise widget under the poster/title; movies with TV leftovers (First Contact) go through the details repair; tools/count-tmdb-ids.hl; gates 327/0, 52/0, 32/0mre
  • 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