Change addTrack action to addTracks, supporting multiple tracks to be added to the queue in one call

This commit is contained in:
Deluan
2020-05-05 12:07:50 -04:00
parent 5495451448
commit 23836d7c3c
4 changed files with 23 additions and 15 deletions
+4 -5
View File
@@ -7,7 +7,7 @@ import {
useNotify,
} from 'react-admin'
import { useDispatch } from 'react-redux'
import { addTrack } from '../audioplayer'
import { addTracks } from '../audioplayer'
import AddToQueueIcon from '@material-ui/icons/AddToQueue'
const AddToQueueButton = ({ selectedIds }) => {
@@ -21,14 +21,13 @@ const AddToQueueButton = ({ selectedIds }) => {
dataProvider
.getMany('song', { ids: selectedIds })
.then((response) => {
// Add the tracks to the queue in the selection order
// Add tracks to a map for easy lookup by ID, needed for the next step
const tracks = response.data.reduce((acc, cur) => {
acc[cur.id] = cur
return acc
}, {})
selectedIds.forEach((id) => {
dispatch(addTrack(tracks[id]))
})
// Add the tracks to the queue in the selection order
dispatch(addTracks(selectedIds.map((id) => tracks[id])))
})
.catch(() => {
notify('ra.page.error', 'warning')