jukebox
All repositories: gitoria
5.8 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'import { lastSort, rememberSort } from '../lib/remember.hl'__title = 'Songs · Jukebox'String sortBy = lastSort()Boolean favOn = falseNumber favMin = 5Hybrid songCtx = { kind = 'songs' sort = sortBy minPlays = 0 }Hybrid firstRows = rowsFor({ kind = 'songs' sort = sortBy minPlays = 0 }, 0, 100)Number songTotal = firstRows.totalHybrid chunk = firstRows.rowsNumber chunkFrom = 0String playingId = ''String favClass = favOn ? 'on' : ''Boolean selArtist = sortBy == 'artist'Boolean selTitle = sortBy == 'title'Boolean selAlbum = sortBy == 'album'Boolean selPlays = sortBy == 'plays'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) }// "12×" → 12. A row that shows a length has no count.playsIn = (aside) => {if (aside.length < 2 || aside[aside.length - 1] != '×') { return -1 }n = toNumber(aside.slice(0, aside.length - 1))return n == null ? -1 : n}// most played first, same records, ties keep their orderbyPlays = (rows) => {out = []for (r of rows) {let j = out.lengthpc = playsIn(r.aside)out.push(r)while (j > 0 && playsIn(out[j - 1].aside) < pc) {out[j] = out[j - 1]j = j - 1}out[j] = r}return out}// the rows of the current window, from the server: a song entered or left iton songsFill() {r = emit server jbRows(songCtx, chunkFrom, 100)if (r == null) { return null }songTotal = r.totalchunk = r.rowschunkFrom = r.offsetreturn null}// a play was counted. The count arrives with the event. The row is written here, then the rows already// held are re-sorted, which moves that row. One fetch only when the song is not in this window.on client jbPlays(id, plays) {if (songCtx.sort != 'plays') { return null }let i = 0let at = -1while (i < chunk.length) {if (chunk[i].id == id) { at = i }i = i + 1}if (at < 0) { emit songsFill() return null }chunk[at].aside = plays + '×'chunk = byPlays(chunk)return null}picked = (id, index) => {playingId = idemit jbPlay(songCtx, index, id)emit songsLoad(index, 0)}on songsShuffleFav(e) {emit jbShuffle({ kind = 'favourites' minPlays = favMin })return null}on songsShuffle(e) {emit jbShuffle({ kind = 'list' ctx = songCtx })return null}on server songsRemember(sort) {return rememberSort(sort)}on songsSort(e) {sortBy = e.target.valueemit server songsRemember(sortBy)emit 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 {jbTools { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.35rem .6rem' paddingBottom = '.25rem'select { flex = '1 1 6rem' minWidth = '0' }'input[type="search"]' { flex = '1 1 100%' }'button.jb-big' { flex = '1 1 100%' minHeight = '3.25rem' fontSize = '1.1rem' color = 'var(--color-accent-text)' background = 'var(--color-accent)' }'button.on' { color = 'var(--color-accent-text)' background = 'var(--color-accent)' }}jbCount { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.25rem .5rem' minHeight = '1.75rem' color = 'var(--color-text-muted)' fontSize = '.9rem''input[type="number"]' { flex = 'none' width = '4.5rem' minHeight = '2.25rem' padding = '.2rem .5rem' textAlign = 'center' }button { minHeight = '2.25rem' padding = '.2rem .9rem' }}'@media (min-width: 60rem)' {jbTools { 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" autocomplete = "off" 'aria-label' = "Sort by" on change(e) { emit songsSort(e) }option { value = "artist" selected = selArtist "Sort: artist" }option { value = "title" selected = selTitle "Sort: title" }option { value = "album" selected = selAlbum "Sort: album" }option { value = "plays" selected = selPlays "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
- a82c0805Records: mission 001 brief (Style form)mre
- a4bce6d1Records: ticket push subscriptionmre
- 14abde3bjukebox: records: Atlas's records moved to worldapi-conductor/archivemre
- 0433e9a8jukebox: records: gitoria remote added and pushedmre
- 1722d707jukebox: records: repo creation handed to Gitoriamre
- b42e7dfbjukebox: conductor records (CONDUCTOR.md, STATUS.md), old STATUS archivedmre
- 1b0d0bc1jukebox: a startup error prints its message before exit 1 (hybriel#247)mre
- b19c478bjukebox JB18 (jukebox#17): onto Hybriel set-day31 (b287cd82, contains the SIGPIPE fix 6d2ca454): plugins/core and plugins/web re-vendored, bin/ from the set; a client that closes /stream while it is written no longer kills the server (90 aborted streams survived, the old bin died with exit 141 on the first)mre
- 73867a2ejukebox#2: Style blocks in the language's nested form (rules named after the View's own elements, pseudo-classes nested, merged duplicates); the same CSS rules, the pages look the samemre
- 06c548d6jukebox JB15: report, log linemre
- 980859cbjukebox JB15 (jukebox#15): the now-playing overlay on a short screen (tablet or phone on its side) gave the queue 12 to 100 px because the big cover took the room; the cover now shrinks with the screen height and goes away under 41rem, the queue keeps 3+ rows; gate tests/jb15.mjs at 8 sizesmre
- 9efc40ffjukebox#12 #14: Grok session 1793246574527-181160mre
- 7d58b36ejukebox JB13 (jukebox#13): Next and Previous ask for the songs after / before the current song's id in the current order, not for place + 1; gate tests/jb13.mjs checks Next with the queue down to one song after the order changedmre
- 51358794jukebox JB14 (jukebox#14): the Songs screen opens sorted the way it was left (kept on the server in storage/ui.json), the sort control shows the sort the rows really have (selected options, autocomplete off); gate tests/jb14.mjsmre
- cc68a063jukebox JB13 (jukebox#13): a tapped song plays the song that was tapped, found by its id in the list as it is now (not by its row number, which counted plays move); the queue goes on from its place there, the rows refresh on the tap; gate tests/jb13.mjs (songs by plays, favourites)mre
- 88d3d5c1jukebox JB12b (jukebox#12): the scroll handle is big (2.75rem x 4rem, accent colour, grip) and drawn on every device, no media query; native bar hidden; gate tests/touch.mjs checks the drawn width with and without touchmre
- b58e4495jukebox JB11 (jukebox#11): the next song starts in the ended event on the same audio element, so it also starts with the screen locked; gate tests/jb11.mjs (hidden tab, no frames)mre
- 12a26233jukebox JB12 (jukebox#12): the long lists get a scroll handle a finger can use on touch screens (44 px tap area, slim look, drag through all rows), gate tests/touch.mjsmre
- 0f2157a9jukebox JV1: onto Hybriel set-day27b: readBytes and stat for /stream and the mp3 tags (no dd, head or tail), startup fault exits 1, fs and mpackdb plugins re-vendored; songs with a comma in the title are indexed againmre
- 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