gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2a4cfc552a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre2a4cfc55/components/songs.hl

2.9 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 songsSort(e) {
  45. sortBy = e.target.value
  46. emit songsReload()
  47. return null
  48. }
  49. on songsFav(e) {
  50. favOn = !favOn
  51. emit songsReload()
  52. return null
  53. }
  54. on songsMin(e) {
  55. n = toNumber(e.target.value)
  56. if (n == null || n < 1) { return null }
  57. favMin = n
  58. if (favOn) { emit songsReload() }
  59. return null
  60. }
  61. View {
  62. jbScreen {
  63. jbTools {
  64. select { id = "sort" 'aria-label' = "Sort by" on change(e) { emit songsSort(e) }
  65. option { value = "artist" "Sort: artist" }
  66. option { value = "title" "Sort: title" }
  67. option { value = "album" "Sort: album" }
  68. option { value = "plays" "Sort: most played" }
  69. }
  70. button { id = "fav" type = "button" class = favClass 'aria-pressed' = favOn on click(e) { emit songsFav(e) } "Favourites" }
  71. }
  72. jbCount {
  73. output { id = "count" countText }
  74. if (favOn) {
  75. span { "played at least" }
  76. input { id = "favmin" type = "number" min = "1" value = favMin inputmode = "numeric" 'aria-label' = "Minimum play count" on input(e) { emit songsMin(e) } }
  77. span { "times" }
  78. }
  79. }
  80. VirtualList { itemCount = songTotal rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = playingId listLabel = "Songs" }
  81. }
  82. }

Branches

Latest commits

  • 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