jukebox
All repositories: gitoria
5.3 KB
// 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// (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.parent './main.hl'import { navigate } from 'hl:web'import VirtualList from './virtual-list/virtual-list.hl'import { rowsFor, thousands, searchGroups } from '../lib/rows.hl'__title = 'Search · Jukebox'String q = ''Hybrid searchCtx = { kind = 'search' q = '' }Number songTotal = 0Hybrid chunk = []Number chunkFrom = 0Hybrid artistHits = []Hybrid albumHits = []String playingId = ''String countText = q == '' ? 'Type a title, an artist or an album.' : (hasAny || songTotal > 0 ? '' : 'Nothing found.')String artistsHead = 'Artists · ' + thousands(artistHits.length)String albumsHead = 'Albums · ' + thousands(albumHits.length)String songsHead = 'Songs · ' + thousands(songTotal)Boolean hasArtists = artistHits.length > 0Boolean hasAlbums = albumHits.length > 0Boolean hasAny = artistHits.length > 0 || albumHits.length > 0Boolean hasSongs = songTotal > 0String stamp = ''on server jbSearch(text) {return searchGroups(text)}on searchLoad(first, wanted) {let start = first - 20if (start < 0) { start = 0 }r = emit server searchRows(searchCtx, start, 100)songTotal = r.totalchunk = r.rowschunkFrom = r.offsetreturn null}loadRange = (first, wanted) => { emit searchLoad(first, wanted) }// the field changed: wait for the last key, then askon searchTyped(e) {q = e.target.value.trim()stamp = '' + Date.now()window.setTimeout(() => { emit searchRun(stamp) }, 250)return null}on searchRun(mark) {if (mark != stamp) { return null }if (q == '') {songTotal = 0chunk = []artistHits = []albumHits = []return null}searchCtx = { kind = 'search' q = q }g = emit server jbSearch(q)artistHits = g.artistsalbumHits = g.albumssongTotal = g.songs.totalchunk = g.songs.rowschunkFrom = 0emit vlTop()return null}on searchShuffle(Hybrid e) {$parent.jbShuffle({ kind = 'list' ctx = searchCtx })return null}picked = (String id, Number index) => {playingId = id$parent.jbPlay(searchCtx, index, id)emit searchLoad(index, 0)}Style {jbHits {display = 'block'padding = '0 0 .25rem'h2 {margin = '.5rem .6rem .15rem'fontSize = '.85rem'letterSpacing = '.04em'textTransform = 'uppercase'color = 'var(--color-text-muted)'}button {display = 'flex'alignItems = 'center'gap = '.7rem'width = '100%'height = '3.25rem'minHeight = '0'margin = '0'padding = '0 .6rem'fontWeight = '400'textAlign = 'left'color = 'var(--color-text)'background = 'transparent'hover { background = 'var(--color-surface)' }img {flex = 'none'width = '2.25rem'height = '2.25rem'borderRadius = 'var(--radius-small)'background = 'var(--color-surface)'objectFit = 'cover'}// Keep the quoted class selector and its original specificity.'.jb-nopic' {flex = 'none'width = '2.25rem'height = '2.25rem'borderRadius = 'var(--radius-small)'background = 'var(--color-surface)'objectFit = 'cover'}// Keep the quoted class selector and its original specificity.'span.jb-name' {flex = '1 1 auto'minWidth = '0'overflow = 'hidden'textOverflow = 'ellipsis'whiteSpace = 'nowrap'}// Keep the quoted class selector and its original specificity.'span.jb-note' {flex = 'none'fontSize = '.85rem'color = 'var(--color-text-muted)'}}p {margin = '.4rem .6rem'color = 'var(--color-text-muted)'}}}View {jbScreen {jbTools { input { id = "q" type = "search" placeholder = "Search songs, artists, albums" 'aria-label' = "Search" autocomplete = "off" on input(e) { emit searchTyped(e) } } }jbCount { output { id = "count" countText } button { id = "shuffle" type = "button" on click(e) { emit searchShuffle(e) } "Shuffle" } }VirtualList { itemCount = songTotal rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = playingId listLabel = "Songs found"jbHits {if (hasArtists) { h2 { artistsHead } }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 } } }if (hasAlbums) { h2 { albumsHead } }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 } } }if (hasSongs) { h2 { songsHead } }}}}}on searchArtist(e) { navigate('/artists/' + e.target.closest('button').getAttribute('data-id')) return null }on searchAlbum(e) { navigate('/albums/' + e.target.closest('button').getAttribute('data-id')) return null }// This screen owns its row request across the server boundary.on server searchRows(Hybrid ctx, Number offset, Number limit) {return rowsFor(ctx, offset, limit)}
Branches
Latest commits
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
- 33072bb5|||PR Record day72 gates and Chrome proofmre
- 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
- 6422a020Sync media-player at 51c3818mre
- b582ba1cVendor complete Hybriel day72 plugin setmre
- 02dccbc9Merge branch 'records-1119' into mainJukebox
- a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
- fc7db075Merge branch 'reconnect-retry' into mainJukebox
- ac6f4c6fL2: plain declaration for a in pickedNextmre
- 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
- 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
- 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
- 1f0cd77bMerge branch 'records-day41' into mainJukebox
- 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre