gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf83571c3f83571c3tracker#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 + STATUSmref83571c3/components/search.hl

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

Branches

Latest commits

  • 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
  • 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
  • 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
  • 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
  • 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
  • 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
  • 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
  • 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre
  • cbdc4ea7tracker#12: link icons TMDB/IMDb/TVDB/TVmaze; sync fills missing ids (TVmaze lookup); movies fetched via /movie/mre