gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5135879451358794jukebox 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.mjsmre51358794/components/songs.hl

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

Branches

Latest commits

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