gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit05c3578c05c3578c|||PR Keep each playing row bound to the shell song on day76mre05c3578c/components/search.hl

5.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 { rowsFor, 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 countText = q == '' ? 'Type a title, an artist or an album.' : (hasAny || songTotal > 0 ? '' : 'Nothing found.')
  16. String artistsHead = 'Artists · ' + thousands(artistHits.length)
  17. String albumsHead = 'Albums · ' + thousands(albumHits.length)
  18. String songsHead = 'Songs · ' + thousands(songTotal)
  19. Boolean hasArtists = artistHits.length > 0
  20. Boolean hasAlbums = albumHits.length > 0
  21. Boolean hasAny = artistHits.length > 0 || albumHits.length > 0
  22. Boolean hasSongs = songTotal > 0
  23. String stamp = ''
  24. on server jbSearch(text) {
  25. return searchGroups(text)
  26. }
  27. on searchLoad(first, wanted) {
  28. let start = first - 20
  29. if (start < 0) { start = 0 }
  30. r = emit server searchRows(searchCtx, start, 100)
  31. songTotal = r.total
  32. chunk = r.rows
  33. chunkFrom = r.offset
  34. return null
  35. }
  36. loadRange = (first, wanted) => { emit searchLoad(first, wanted) }
  37. // the field changed: wait for the last key, then ask
  38. on searchTyped(e) {
  39. q = e.target.value.trim()
  40. stamp = '' + Date.now()
  41. window.setTimeout(() => { emit searchRun(stamp) }, 250)
  42. return null
  43. }
  44. on searchRun(mark) {
  45. if (mark != stamp) { return null }
  46. if (q == '') {
  47. songTotal = 0
  48. chunk = []
  49. artistHits = []
  50. albumHits = []
  51. return null
  52. }
  53. searchCtx = { kind = 'search' q = q }
  54. g = emit server jbSearch(q)
  55. artistHits = g.artists
  56. albumHits = g.albums
  57. songTotal = g.songs.total
  58. chunk = g.songs.rows
  59. chunkFrom = 0
  60. emit vlTop()
  61. return null
  62. }
  63. on searchShuffle(Hybrid e) {
  64. $parent.jbShuffle({ kind = 'list' ctx = searchCtx })
  65. return null
  66. }
  67. picked = (String id, Number index) => {
  68. $parent.jbPlay(searchCtx, index, id)
  69. emit searchLoad(index, 0)
  70. }
  71. Style {
  72. jbHits {
  73. display = 'block'
  74. padding = '0 0 .25rem'
  75. h2 {
  76. margin = '.5rem .6rem .15rem'
  77. fontSize = '.85rem'
  78. letterSpacing = '.04em'
  79. textTransform = 'uppercase'
  80. color = 'var(--color-text-muted)'
  81. }
  82. button {
  83. display = 'flex'
  84. alignItems = 'center'
  85. gap = '.7rem'
  86. width = '100%'
  87. height = '3.25rem'
  88. minHeight = '0'
  89. margin = '0'
  90. padding = '0 .6rem'
  91. fontWeight = '400'
  92. textAlign = 'left'
  93. color = 'var(--color-text)'
  94. background = 'transparent'
  95. hover { background = 'var(--color-surface)' }
  96. img {
  97. flex = 'none'
  98. width = '2.25rem'
  99. height = '2.25rem'
  100. borderRadius = 'var(--radius-small)'
  101. background = 'var(--color-surface)'
  102. objectFit = 'cover'
  103. }
  104. // Keep the quoted class selector and its original specificity.
  105. '.jb-nopic' {
  106. flex = 'none'
  107. width = '2.25rem'
  108. height = '2.25rem'
  109. borderRadius = 'var(--radius-small)'
  110. background = 'var(--color-surface)'
  111. objectFit = 'cover'
  112. }
  113. // Keep the quoted class selector and its original specificity.
  114. 'span.jb-name' {
  115. flex = '1 1 auto'
  116. minWidth = '0'
  117. overflow = 'hidden'
  118. textOverflow = 'ellipsis'
  119. whiteSpace = 'nowrap'
  120. }
  121. // Keep the quoted class selector and its original specificity.
  122. 'span.jb-note' {
  123. flex = 'none'
  124. fontSize = '.85rem'
  125. color = 'var(--color-text-muted)'
  126. }
  127. }
  128. p {
  129. margin = '.4rem .6rem'
  130. color = 'var(--color-text-muted)'
  131. }
  132. }
  133. }
  134. View {
  135. jbScreen {
  136. jbTools { input { id = "q" type = "search" placeholder = "Search songs, artists, albums" 'aria-label' = "Search" autocomplete = "off" on input(e) { emit searchTyped(e) } } }
  137. jbCount { output { id = "count" countText } button { id = "shuffle" type = "button" on click(e) { emit searchShuffle(e) } "Shuffle" } }
  138. VirtualList { itemCount = songTotal rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = $parent.nowId listLabel = "Songs found"
  139. jbHits {
  140. if (hasArtists) { h2 { artistsHead } }
  141. 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 } } }
  142. if (hasAlbums) { h2 { albumsHead } }
  143. 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 } } }
  144. if (hasSongs) { h2 { songsHead } }
  145. }
  146. }
  147. }
  148. }
  149. on searchArtist(e) { navigate('/artists/' + e.target.closest('button').getAttribute('data-id')) return null }
  150. on searchAlbum(e) { navigate('/albums/' + e.target.closest('button').getAttribute('data-id')) return null }
  151. // This screen owns its row request across the server boundary.
  152. on server searchRows(Hybrid ctx, Number offset, Number limit) {
  153. return rowsFor(ctx, offset, limit)
  154. }

Branches

Latest commits

  • 05c3578c|||PR Keep each playing row bound to the shell song on day76mre
  • eaa7e6d6Vendor Hybriel day76 for live parent member readsmre
  • 0923398bMerge branch 'records-1124d' into mainJukebox
  • 78f0cc86|||PR records 2026-11-24: inbox-thread rule, "Not playing" confirmed and closedmre
  • c1b153c4Merge branch 'records-1124c' into mainJukebox
  • d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
  • 43b564dbMerge branch 'records-1124b' into mainJukebox
  • fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
  • 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
  • 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
  • 170d3735Merge branch 'code-order-2' into mainJukebox
  • 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
  • 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
  • 0ba85799Merge branch 'reset-classes' into mainJukebox
  • 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
  • 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
  • dcca21abjukebox#8 Move copies and queue logic into their topicsmre
  • 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
  • bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
  • a3796dc5Records: live step waits for idlemre