feat: add the remainder of the album to the queue when clicking on an album's track

This commit is contained in:
Deluan
2020-02-07 17:36:50 -05:00
parent 52cd17963f
commit 6ce4811460
2 changed files with 31 additions and 6 deletions
+24 -4
View File
@@ -5,9 +5,9 @@ const PLAYER_ADD_TRACK = 'PLAYER_ADD_TRACK'
const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
const PLAYER_PLAY_ALBUM = 'PLAYER_PLAY_ALBUM'
const mapToAudioLists = (item) => ({
id: item.id,
name: item.title,
singer: item.artist,
cover: subsonicUrl('getCoverArt', item.id, 'size=300'),
@@ -25,6 +25,12 @@ const setTrack = (data) => ({
data
})
const playAlbum = (id, data) => ({
type: PLAYER_PLAY_ALBUM,
data,
id
})
const syncQueue = (data) => ({
type: PLAYER_SYNC_QUEUE,
data
@@ -37,11 +43,13 @@ const scrobble = (id) => ({
const playQueueReducer = (
previousState = { queue: [], clear: true },
{ type, data }
payload
) => {
let queue
const { type, data } = payload
switch (type) {
case PLAYER_ADD_TRACK:
const queue = previousState.queue
queue = previousState.queue
queue.push(mapToAudioLists(data))
return { queue, clear: false }
case PLAYER_SET_TRACK:
@@ -56,9 +64,21 @@ const playQueueReducer = (
}
})
return { queue: newQueue, clear: false }
case PLAYER_PLAY_ALBUM:
queue = []
let match = false
Object.keys(data).forEach((id) => {
if (id === payload.id) {
match = true
}
if (match) {
queue.push(mapToAudioLists(data[id]))
}
})
return { queue, clear: true }
default:
return previousState
}
}
export { addTrack, setTrack, syncQueue, scrobble, playQueueReducer }
export { addTrack, setTrack, playAlbum, syncQueue, scrobble, playQueueReducer }