jukebox
All repositories: gitoria
4.2 KB
// components/songs.hl — `/`: ALL SONGS in one long list (the virtual list: only the rows near the viewport exist, 100 are fetched at a time from the server).// Sort by artist, title, album or plays; the Favourites button keeps only the songs played at least N times (N is adjustable, default 5) and the line// under it says how many songs that is. A tap on a song plays it with this list as the queue (the shell's `jbPlay`).parent './main.hl'import VirtualList from './virtual-list/virtual-list.hl'import { rowsFor, thousands } from '../lib/rows.hl'__title = 'Songs · Jukebox'String sortBy = 'artist'Boolean favOn = falseNumber favMin = 5Hybrid songCtx = { kind = 'songs' sort = 'artist' minPlays = 0 }Hybrid firstRows = rowsFor({ kind = 'songs' sort = 'artist' minPlays = 0 }, 0, 100)Number songTotal = firstRows.totalHybrid chunk = firstRows.rowsNumber chunkFrom = 0String playingId = ''String favClass = favOn ? 'on' : ''String countText = thousands(songTotal) + (songTotal == 1 ? ' song' : ' songs')// the list asks for the rows near the viewport; one request of 100 rows around themon songsLoad(first, wanted) {let start = first - 20if (start < 0) { start = 0 }r = emit server jbRows(songCtx, start, 100)songTotal = r.totalchunk = r.rowschunkFrom = r.offsetreturn null}// the list changed (order or filter): the first rows, back to the topon songsReload() {songCtx = { kind = 'songs' sort = sortBy minPlays = favOn ? favMin : 0 }r = emit server jbRows(songCtx, 0, 100)songTotal = r.totalchunk = r.rowschunkFrom = 0emit vlTop()return null}loadRange = (first, wanted) => { emit songsLoad(first, wanted) }picked = (id, index) => {playingId = idemit jbPlay(songCtx, index)}on songsShuffleFav(e) {emit jbShuffle({ kind = 'favourites' minPlays = favMin })return null}on songsShuffle(e) {emit jbShuffle({ kind = 'list' ctx = songCtx })return null}on songsSort(e) {sortBy = e.target.valueemit songsReload()return null}on songsFav(e) {favOn = !favOnemit songsReload()return null}on songsMin(e) {n = toNumber(e.target.value)if (n == null || n < 1) { return null }favMin = nif (favOn) { emit songsReload() }return null}Style {'jb-tools' { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.35rem .6rem' paddingBottom = '.25rem' }'jb-tools select' { flex = '1 1 6rem' minWidth = '0' }'jb-tools input[type="search"]' { flex = '1 1 100%' }'jb-count input[type="number"]' { flex = 'none' width = '4.5rem' minHeight = '2.25rem' padding = '.2rem .5rem' textAlign = 'center' }'jb-tools button.jb-big' { flex = '1 1 100%' minHeight = '3.25rem' fontSize = '1.1rem' color = 'var(--color-accent-text)' background = 'var(--color-accent)' }'jb-tools button.on' { color = 'var(--color-accent-text)' background = 'var(--color-accent)' }'jb-count' { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.25rem .5rem' minHeight = '1.75rem' color = 'var(--color-text-muted)' fontSize = '.9rem' }'jb-count button' { minHeight = '2.25rem' padding = '.2rem .9rem' }'@media (min-width: 60rem)' {'jb-tools select' { flex = '0 0 14rem' }}}View {jbScreen {jbTools {button { id = "shuffle-fav" type = "button" class = "jb-big" on click(e) { emit songsShuffleFav(e) } "Shuffle my favourites" }select { id = "sort" 'aria-label' = "Sort by" on change(e) { emit songsSort(e) }option { value = "artist" "Sort: artist" }option { value = "title" "Sort: title" }option { value = "album" "Sort: album" }option { value = "plays" "Sort: most played" }}button { id = "fav" type = "button" class = favClass 'aria-pressed' = favOn on click(e) { emit songsFav(e) } "Favourites" }button { id = "shuffle" type = "button" on click(e) { emit songsShuffle(e) } "Shuffle" }}jbCount {output { id = "count" countText }if (favOn) {span { "played at least" }input { id = "favmin" type = "number" min = "1" value = favMin inputmode = "numeric" 'aria-label' = "Minimum play count" on input(e) { emit songsMin(e) } }span { "times" }}}VirtualList { itemCount = songTotal rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = playingId listLabel = "Songs" }}}
Branches
Latest commits
- 63d0f2eejukebox ST1 (jukebox#2): styles of main, songs and search moved into their own Style blocks (styles.hl 81 to 8 rules, pixel-identical at 390 and 1280); artist and album wait for an hl:web fixmre
- c5b8fde9jukebox JB3b: keyboard gap repro as a reportmre
- 9daebb4bjukebox JB3b: shuffle, now-playing overlay, next and previous, play counting, media session, gates; keyboard left open (Hybriel gap)mre
- 59c1373ejukebox JB3 (work in progress): albums without folder and with disc markers folded, compilations, duplicate songs, own play counter, server-side shuffle queuemre
- 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