gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb58e4495b58e4495jukebox 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)mreb58e4495/components/songs.hl

4.2 KB

  1. // 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).
  2. // 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
  3. // 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`).
  4. parent './main.hl'
  5. import VirtualList from './virtual-list/virtual-list.hl'
  6. import { rowsFor, thousands } from '../lib/rows.hl'
  7. __title = 'Songs · Jukebox'
  8. String sortBy = 'artist'
  9. Boolean favOn = false
  10. Number favMin = 5
  11. Hybrid songCtx = { kind = 'songs' sort = 'artist' minPlays = 0 }
  12. Hybrid firstRows = rowsFor({ kind = 'songs' sort = 'artist' minPlays = 0 }, 0, 100)
  13. Number songTotal = firstRows.total
  14. Hybrid chunk = firstRows.rows
  15. Number chunkFrom = 0
  16. String playingId = ''
  17. String favClass = favOn ? 'on' : ''
  18. String countText = thousands(songTotal) + (songTotal == 1 ? ' song' : ' songs')
  19. // the list asks for the rows near the viewport; one request of 100 rows around them
  20. on songsLoad(first, wanted) {
  21. let start = first - 20
  22. if (start < 0) { start = 0 }
  23. r = emit server jbRows(songCtx, start, 100)
  24. songTotal = r.total
  25. chunk = r.rows
  26. chunkFrom = r.offset
  27. return null
  28. }
  29. // the list changed (order or filter): the first rows, back to the top
  30. on songsReload() {
  31. songCtx = { kind = 'songs' sort = sortBy minPlays = favOn ? favMin : 0 }
  32. r = emit server jbRows(songCtx, 0, 100)
  33. songTotal = r.total
  34. chunk = r.rows
  35. chunkFrom = 0
  36. emit vlTop()
  37. return null
  38. }
  39. loadRange = (first, wanted) => { emit songsLoad(first, wanted) }
  40. picked = (id, index) => {
  41. playingId = id
  42. emit jbPlay(songCtx, index)
  43. }
  44. on songsShuffleFav(e) {
  45. emit jbShuffle({ kind = 'favourites' minPlays = favMin })
  46. return null
  47. }
  48. on songsShuffle(e) {
  49. emit jbShuffle({ kind = 'list' ctx = songCtx })
  50. return null
  51. }
  52. on songsSort(e) {
  53. sortBy = e.target.value
  54. emit songsReload()
  55. return null
  56. }
  57. on songsFav(e) {
  58. favOn = !favOn
  59. emit songsReload()
  60. return null
  61. }
  62. on songsMin(e) {
  63. n = toNumber(e.target.value)
  64. if (n == null || n < 1) { return null }
  65. favMin = n
  66. if (favOn) { emit songsReload() }
  67. return null
  68. }
  69. Style {
  70. 'jb-tools' { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.35rem .6rem' paddingBottom = '.25rem' }
  71. 'jb-tools select' { flex = '1 1 6rem' minWidth = '0' }
  72. 'jb-tools input[type="search"]' { flex = '1 1 100%' }
  73. 'jb-count input[type="number"]' { flex = 'none' width = '4.5rem' minHeight = '2.25rem' padding = '.2rem .5rem' textAlign = 'center' }
  74. 'jb-tools button.jb-big' { flex = '1 1 100%' minHeight = '3.25rem' fontSize = '1.1rem' color = 'var(--color-accent-text)' background = 'var(--color-accent)' }
  75. 'jb-tools button.on' { color = 'var(--color-accent-text)' background = 'var(--color-accent)' }
  76. 'jb-count' { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.25rem .5rem' minHeight = '1.75rem' color = 'var(--color-text-muted)' fontSize = '.9rem' }
  77. 'jb-count button' { minHeight = '2.25rem' padding = '.2rem .9rem' }
  78. '@media (min-width: 60rem)' {
  79. 'jb-tools select' { flex = '0 0 14rem' }
  80. }
  81. }
  82. View {
  83. jbScreen {
  84. jbTools {
  85. button { id = "shuffle-fav" type = "button" class = "jb-big" on click(e) { emit songsShuffleFav(e) } "Shuffle my favourites" }
  86. select { id = "sort" 'aria-label' = "Sort by" on change(e) { emit songsSort(e) }
  87. option { value = "artist" "Sort: artist" }
  88. option { value = "title" "Sort: title" }
  89. option { value = "album" "Sort: album" }
  90. option { value = "plays" "Sort: most played" }
  91. }
  92. button { id = "fav" type = "button" class = favClass 'aria-pressed' = favOn on click(e) { emit songsFav(e) } "Favourites" }
  93. button { id = "shuffle" type = "button" on click(e) { emit songsShuffle(e) } "Shuffle" }
  94. }
  95. jbCount {
  96. output { id = "count" countText }
  97. if (favOn) {
  98. span { "played at least" }
  99. input { id = "favmin" type = "number" min = "1" value = favMin inputmode = "numeric" 'aria-label' = "Minimum play count" on input(e) { emit songsMin(e) } }
  100. span { "times" }
  101. }
  102. }
  103. VirtualList { itemCount = songTotal rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = playingId listLabel = "Songs" }
  104. }
  105. }

Branches

Latest commits

  • 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
  • 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