add Play next & Add to queue to album page

This commit is contained in:
Thomas Amland 2021-03-14 12:38:14 +01:00
parent 4100572b54
commit f89f6b36c8
3 changed files with 33 additions and 12 deletions

View File

@ -36,10 +36,10 @@
return this.$api.star('track', this.track.id) return this.$api.star('track', this.track.id)
}, },
setNextInQueue() { setNextInQueue() {
return this.$store.dispatch('player/setNextInQueue', this.track) return this.$store.dispatch('player/setNextInQueue', [this.track])
}, },
addToQueue() { addToQueue() {
return this.$store.dispatch('player/addToQueue', this.track) return this.$store.dispatch('player/addToQueue', [this.track])
}, },
} }
}) })

View File

@ -22,6 +22,17 @@
<b-button variant="secondary" class="mr-2" @click="toggleStar"> <b-button variant="secondary" class="mr-2" @click="toggleStar">
<Icon :icon="album.starred ? 'star-fill' : 'star'" /> <Icon :icon="album.starred ? 'star-fill' : 'star'" />
</b-button> </b-button>
<b-dropdown variant="secondary" boundary="window" no-caret toggle-class="px-1">
<template #button-content>
<Icon icon="three-dots-vertical" />
</template>
<b-dropdown-item-btn @click="setNextInQueue">
Play next
</b-dropdown-item-btn>
<b-dropdown-item-btn @click="addToQueue">
Add to queue
</b-dropdown-item-btn>
</b-dropdown>
</div> </div>
</div> </div>
</div> </div>
@ -59,13 +70,23 @@
}, },
methods: { methods: {
play() { play() {
if (this.album?.tracks) { if (this.album) {
return this.$store.dispatch('player/playTrackList', { return this.$store.dispatch('player/playTrackList', {
index: 0, index: 0,
tracks: this.album.tracks, tracks: this.album.tracks,
}) })
} }
}, },
setNextInQueue() {
if (this.album) {
return this.$store.dispatch('player/setNextInQueue', this.album.tracks)
}
},
addToQueue() {
if (this.album) {
return this.$store.dispatch('player/addToQueue', this.album.tracks)
}
},
toggleStar() { toggleStar() {
if (this.album) { if (this.album) {
const value = !this.album.starred const value = !this.album.starred
@ -74,7 +95,7 @@
? this.$api.starAlbum(this.album.id) ? this.$api.starAlbum(this.album.id)
: this.$api.unstarAlbum(this.album.id) : this.$api.unstarAlbum(this.album.id)
} }
} },
} }
}) })
</script> </script>

View File

@ -92,8 +92,8 @@ export const playerModule: Module<State, any> = {
}) })
} }
}, },
addToQueue(state, track) { addToQueue(state, tracks) {
state.queue.push(track) state.queue.push(...tracks)
}, },
removeFromQueue(state, index) { removeFromQueue(state, index) {
state.queue.splice(index, 1) state.queue.splice(index, 1)
@ -101,8 +101,8 @@ export const playerModule: Module<State, any> = {
state.queueIndex-- state.queueIndex--
} }
}, },
setNextInQueue(state, track) { setNextInQueue(state, tracks) {
state.queue.splice(state.queueIndex + 1, 0, track) state.queue.splice(state.queueIndex + 1, 0, ...tracks)
}, },
setCurrentTime(state, value: any) { setCurrentTime(state, value: any) {
state.currentTime = value state.currentTime = value
@ -190,11 +190,11 @@ export const playerModule: Module<State, any> = {
commit('setMute', !state.mute) commit('setMute', !state.mute)
audio.volume = state.mute ? 0.0 : state.volume audio.volume = state.mute ? 0.0 : state.volume
}, },
addToQueue({ commit }, track) { addToQueue({ state, commit }, tracks) {
commit('addToQueue', track) commit('addToQueue', state.shuffle ? shuffle([...tracks]) : tracks)
}, },
setNextInQueue({ commit }, track) { setNextInQueue({ state, commit }, tracks) {
commit('setNextInQueue', track) commit('setNextInQueue', state.shuffle ? shuffle([...tracks]) : tracks)
}, },
setVolume({ commit }, value) { setVolume({ commit }, value) {
audio.volume = value audio.volume = value