Skip to content

Commit

Permalink
[web] Add the medium numbers when an album has multiple media #1629
Browse files Browse the repository at this point in the history
  • Loading branch information
hacketiwack committed Dec 8, 2023
1 parent 6a84498 commit e89c392
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions web-src/src/lib/GroupByList.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ export function byRating(field, { direction = 'asc', defaultValue = 0 }) {
}
}

export function byMedium(field, direction = 'asc', defaultValue = 1) {
return {
compareFn: (a, b) => {
const fieldA = a[field] || defaultValue
const fieldB = b[field] || defaultValue
const result = fieldA - fieldB
return direction === 'asc' ? result : result * -1
},

groupKeyFn: (item) => {
return item[field] || defaultValue
}
}
}

export function byYear(field, { direction = 'asc', defaultValue = '0000' }) {
return {
compareFn: (a, b) => {
Expand Down
6 changes: 5 additions & 1 deletion web-src/src/pages/PageAlbum.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<script>
import ContentWithHero from '@/templates/ContentWithHero.vue'
import CoverArtwork from '@/components/CoverArtwork.vue'
import { GroupByList } from '@/lib/GroupByList'
import { GroupByList, byMedium, noop } from '@/lib/GroupByList'
import ListTracks from '@/components/ListTracks.vue'
import ModalDialogAlbum from '@/components/ModalDialogAlbum.vue'
import webapi from '@/webapi'
Expand All @@ -63,6 +63,10 @@ const dataObject = {
set(vm, response) {
vm.album = response[0].data
vm.tracks = new GroupByList(response[1].data)
vm.tracks.group(byMedium('disc_number'))
if (vm.tracks.indexList <= 1) {
vm.tracks.group(noop())
}
}
}
Expand Down

0 comments on commit e89c392

Please sign in to comment.