gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchplaying-row05c3578c|||PR Keep each playing row bound to the shell song on day76mreplaying-row/components/songs.hl

6.8 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, lastScroll, rememberScroll, startRowFor } 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. // where the list was left (kept per sort, see lib/remember.hl); the first rows are the ones around that place
  14. Number savedTop = lastScroll('songs:' + sortBy)
  15. Number firstRow = startRowFor(savedTop)
  16. Hybrid firstRows = rowsFor({ kind = 'songs' sort = sortBy minPlays = 0 }, firstRow, 100)
  17. Number songTotal = firstRows.total
  18. Hybrid chunk = firstRows.rows
  19. Number chunkFrom = firstRows.offset
  20. String listResetKey = ''
  21. String favClass = favOn ? 'on' : ''
  22. Boolean selArtist = sortBy == 'artist'
  23. Boolean selTitle = sortBy == 'title'
  24. Boolean selAlbum = sortBy == 'album'
  25. Boolean selPlays = sortBy == 'plays'
  26. String countText = thousands(songTotal) + (songTotal == 1 ? ' song' : ' songs')
  27. // the list asks for the rows near the viewport; one request of 100 rows around them
  28. on songsLoad(first, wanted) {
  29. let start = first - 20
  30. if (start < 0) { start = 0 }
  31. r = emit server songsRows(songCtx, start, 100)
  32. songTotal = r.total
  33. chunk = r.rows
  34. chunkFrom = r.offset
  35. return null
  36. }
  37. // the list changed (order or filter): the first rows, back to the top
  38. on songsReload() {
  39. songCtx = { kind = 'songs' sort = sortBy minPlays = favOn ? favMin : 0 }
  40. r = emit server songsRows(songCtx, 0, 100)
  41. songTotal = r.total
  42. chunk = r.rows
  43. chunkFrom = 0
  44. savedTop = 0
  45. listResetKey = sortBy + ':' + favOn + ':' + favMin
  46. return null
  47. }
  48. loadRange = (first, wanted) => { emit songsLoad(first, wanted) }
  49. // "12×" → 12. A row that shows a length has no count.
  50. playsIn = (aside) => {
  51. if (aside.length < 2 || aside[aside.length - 1] != '×') { return -1 }
  52. n = toNumber(aside.slice(0, aside.length - 1))
  53. return n == null ? -1 : n
  54. }
  55. // most played first, same records, ties keep their order
  56. byPlays = (rows) => {
  57. out = []
  58. for (r of rows) {
  59. let j = out.length
  60. pc = playsIn(r.aside)
  61. out.push(r)
  62. while (j > 0 && playsIn(out[j - 1].aside) < pc) {
  63. out[j] = out[j - 1]
  64. j = j - 1
  65. }
  66. out[j] = r
  67. }
  68. return out
  69. }
  70. // the rows of the current window, from the server: a song entered or left it
  71. on songsFill() {
  72. r = emit server songsRows(songCtx, chunkFrom, 100)
  73. if (r == null) { return null }
  74. songTotal = r.total
  75. chunk = r.rows
  76. chunkFrom = r.offset
  77. return null
  78. }
  79. // a play was counted. The count arrives with the event. The row is written here, then the rows already
  80. // held are re-sorted, which moves that row. One fetch only when the song is not in this window.
  81. on client jbPlays(id, plays) {
  82. if (songCtx.sort != 'plays') { return null }
  83. let i = 0
  84. let at = -1
  85. while (i < chunk.length) {
  86. if (chunk[i].id == id) { at = i }
  87. i = i + 1
  88. }
  89. if (at < 0) { emit songsFill() return null }
  90. chunk[at].aside = plays + '×'
  91. chunk = byPlays(chunk)
  92. return null
  93. }
  94. picked = (String id, Number index) => {
  95. $parent.jbPlay(songCtx, index, id)
  96. emit songsLoad(index, 0)
  97. }
  98. on songsShuffleFav(Hybrid e) {
  99. $parent.jbShuffle({ kind = 'favourites' minPlays = favMin })
  100. return null
  101. }
  102. on songsShuffle(Hybrid e) {
  103. $parent.jbShuffle({ kind = 'list' ctx = songCtx })
  104. return null
  105. }
  106. on server songsRemember(sort) {
  107. return rememberSort(sort)
  108. }
  109. // the listener scrolled: keep the offset for the list as it is shown (its sort, and the favourites filter apart)
  110. on server songsRememberScroll(key, top) {
  111. return rememberScroll(key, top)
  112. }
  113. on songsScrolled(top) {
  114. emit server songsRememberScroll('songs:' + sortBy + (favOn ? ':fav' : ''), top)
  115. return null
  116. }
  117. rememberTop = (top) => { emit songsScrolled(top) }
  118. on songsSort(e) {
  119. sortBy = e.target.value
  120. emit server songsRemember(sortBy)
  121. emit songsReload()
  122. return null
  123. }
  124. on songsFav(e) {
  125. favOn = !favOn
  126. emit songsReload()
  127. return null
  128. }
  129. on songsMin(e) {
  130. n = toNumber(e.target.value)
  131. if (n == null || n < 1) { return null }
  132. favMin = n
  133. if (favOn) { emit songsReload() }
  134. return null
  135. }
  136. Style {
  137. jbTools {
  138. display = 'flex'
  139. flexWrap = 'wrap'
  140. alignItems = 'center'
  141. gap = '.35rem .6rem'
  142. paddingBottom = '.25rem'
  143. select {
  144. flex = '1 1 6rem'
  145. minWidth = '0'
  146. @media {
  147. minWidth = '60rem'
  148. flex = '0 0 14rem'
  149. }
  150. }
  151. // Keep the quoted attribute selector and its original specificity.
  152. 'input[type="search"]' { flex = '1 1 100%' }
  153. // Keep the quoted class selector and its original specificity.
  154. 'button.on' {
  155. color = 'var(--color-accent-text)'
  156. background = 'var(--color-accent)'
  157. }
  158. }
  159. jbCount {
  160. display = 'flex'
  161. flexWrap = 'wrap'
  162. alignItems = 'center'
  163. gap = '.25rem .5rem'
  164. minHeight = '1.75rem'
  165. color = 'var(--color-text-muted)'
  166. fontSize = '.9rem'
  167. // Keep the quoted attribute selector and its original specificity.
  168. 'input[type="number"]' {
  169. flex = 'none'
  170. width = '4.5rem'
  171. minHeight = '2.25rem'
  172. padding = '.2rem .5rem'
  173. textAlign = 'center'
  174. }
  175. button {
  176. minHeight = '2.25rem'
  177. padding = '.2rem .9rem'
  178. }
  179. }
  180. }
  181. View {
  182. jbScreen {
  183. jbTools {
  184. button { id = "shuffle-fav" type = "button" on click(e) { emit songsShuffleFav(e) } "Shuffle my favourites" }
  185. select { id = "sort" autocomplete = "off" 'aria-label' = "Sort by" on change(e) { emit songsSort(e) }
  186. option { value = "artist" selected = selArtist "Sort: artist" }
  187. option { value = "title" selected = selTitle "Sort: title" }
  188. option { value = "album" selected = selAlbum "Sort: album" }
  189. option { value = "plays" selected = selPlays "Sort: most played" }
  190. }
  191. button { id = "fav" type = "button" class = favClass 'aria-pressed' = favOn on click(e) { emit songsFav(e) } "Favourites" }
  192. button { id = "shuffle" type = "button" on click(e) { emit songsShuffle(e) } "Shuffle" }
  193. }
  194. jbCount {
  195. output { id = "count" countText }
  196. if (favOn) {
  197. span { "played at least" }
  198. input { id = "favmin" type = "number" min = "1" value = favMin inputmode = "numeric" 'aria-label' = "Minimum play count" on input(e) { emit songsMin(e) } }
  199. span { "times" }
  200. }
  201. }
  202. VirtualList { itemCount = songTotal rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = $parent.nowId scrollTop = savedTop onScroll = rememberTop resetKey = listResetKey listLabel = "Songs" }
  203. }
  204. }
  205. // This screen owns its row request across the server boundary.
  206. on server songsRows(Hybrid ctx, Number offset, Number limit) {
  207. return rowsFor(ctx, offset, limit)
  208. }

Branches

Latest commits

  • 05c3578c|||PR Keep each playing row bound to the shell song on day76mre
  • eaa7e6d6Vendor Hybriel day76 for live parent member readsmre
  • 0923398bMerge branch 'records-1124d' into mainJukebox
  • 78f0cc86|||PR records 2026-11-24: inbox-thread rule, "Not playing" confirmed and closedmre
  • c1b153c4Merge branch 'records-1124c' into mainJukebox
  • d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
  • 43b564dbMerge branch 'records-1124b' into mainJukebox
  • fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
  • 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
  • 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
  • 170d3735Merge branch 'code-order-2' into mainJukebox
  • 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
  • 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
  • 0ba85799Merge branch 'reset-classes' into mainJukebox
  • 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
  • 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
  • dcca21abjukebox#8 Move copies and queue logic into their topicsmre
  • 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
  • bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
  • a3796dc5Records: live step waits for idlemre