gitoriaLog in with ident

tracker

All repositories: gitoria

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

Branches

Latest commits

  • 1ed5457etracker#20 + #21 (mission 068): typed headings "<Type> | <name>" in type colours; TV titles split into Series (/series) and Shows (/shows) by TMDB type + Reality/Talk/News genres — kind stored by sync/import/adult backfill + new kind backfill (resumes), /movies/<slug>, /shows/<slug> of a series/movie → 301, /my/series + /my/shows, home 5 tiles + 3 rows, search/filmography labels; gates kinds 32 + browser 266, tests/realdata-068.mjs, tools/count-kinds.hl, docs/kinds.md, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.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