gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2a4cfc552a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre2a4cfc55/components/search.hl

3.2 KB

  1. // components/search.hl — `/search`: ONE FIELD, results while you type. Songs, artists and albums that contain every word (case and accents ignored). The artists and albums
  2. // (at most 10 each) stand above the songs; the songs are the virtual list. The search waits 250 ms after the last key before it asks.
  3. parent './main.hl'
  4. import { navigate } from 'hl:web'
  5. import VirtualList from './virtual-list/virtual-list.hl'
  6. import { thousands, searchGroups } from '../lib/rows.hl'
  7. __title = 'Search · Jukebox'
  8. String q = ''
  9. Hybrid searchCtx = { kind = 'search' q = '' }
  10. Number songTotal = 0
  11. Hybrid chunk = []
  12. Number chunkFrom = 0
  13. Hybrid artistHits = []
  14. Hybrid albumHits = []
  15. String playingId = ''
  16. String countText = q == '' ? 'Type a title, an artist or an album.' : thousands(songTotal) + (songTotal == 1 ? ' song' : ' songs')
  17. Boolean hasArtists = artistHits.length > 0
  18. Boolean hasAlbums = albumHits.length > 0
  19. Boolean hasAny = artistHits.length > 0 || albumHits.length > 0
  20. String stamp = ''
  21. on server jbSearch(text) {
  22. return searchGroups(text)
  23. }
  24. on searchLoad(first, wanted) {
  25. let start = first - 20
  26. if (start < 0) { start = 0 }
  27. r = emit server jbRows(searchCtx, start, 100)
  28. songTotal = r.total
  29. chunk = r.rows
  30. chunkFrom = r.offset
  31. return null
  32. }
  33. loadRange = (first, wanted) => { emit searchLoad(first, wanted) }
  34. // the field changed: wait for the last key, then ask
  35. on searchTyped(e) {
  36. q = e.target.value.trim()
  37. stamp = '' + Date.now()
  38. window.setTimeout(() => { emit searchRun(stamp) }, 250)
  39. return null
  40. }
  41. on searchRun(mark) {
  42. if (mark != stamp) { return null }
  43. if (q == '') {
  44. songTotal = 0
  45. chunk = []
  46. artistHits = []
  47. albumHits = []
  48. return null
  49. }
  50. searchCtx = { kind = 'search' q = q }
  51. g = emit server jbSearch(q)
  52. artistHits = g.artists
  53. albumHits = g.albums
  54. songTotal = g.songs.total
  55. chunk = g.songs.rows
  56. chunkFrom = 0
  57. emit vlTop()
  58. return null
  59. }
  60. picked = (id, index) => {
  61. playingId = id
  62. emit jbPlay(searchCtx, index)
  63. }
  64. View {
  65. jbScreen {
  66. jbTools { input { id = "q" type = "search" placeholder = "Search songs, artists, albums" 'aria-label' = "Search" autocomplete = "off" on input(e) { emit searchTyped(e) } } }
  67. jbCount { output { id = "count" countText } }
  68. VirtualList { itemCount = songTotal rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = playingId listLabel = "Songs found"
  69. jbHits {
  70. if (hasArtists) { h2 { "Artists" } }
  71. for (a of artistHits) { button { type = "button" 'data-id' = a.id on click(e) { emit searchArtist(e) } if (a.hasImg) { img { src = a.img alt = "" loading = "lazy" } } if (a.noImg) { span { class = "jb-nopic" } } span { class = "jb-name" a.title } span { class = "jb-note" a.sub } } }
  72. if (hasAlbums) { h2 { "Albums" } }
  73. for (a of albumHits) { button { type = "button" 'data-id' = a.id on click(e) { emit searchAlbum(e) } if (a.hasImg) { img { src = a.img alt = "" loading = "lazy" } } if (a.noImg) { span { class = "jb-nopic" } } span { class = "jb-name" a.title } span { class = "jb-note" a.sub } } }
  74. if (hasAny) { h2 { "Songs" } }
  75. }
  76. }
  77. }
  78. }
  79. on searchArtist(e) { navigate('/artists/' + e.target.closest('button').getAttribute('data-id')) return null }
  80. on searchAlbum(e) { navigate('/albums/' + e.target.closest('button').getAttribute('data-id')) return null }

Branches

Latest commits

  • 2a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre
  • 93a44212jukebox: report, numbers of the full scan, notes on the index key rulemre
  • bf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmre
  • 28a82fa2jukebox: README, STATUS, LOG, DECISIONSmre
  • d13987dfjukebox: library scanner, ID3 reader, mpackdb database and JSON API, with fixtures and a gatemre