2020-02-04 05:26:54 -09:00
|
|
|
import React from 'react'
|
2020-02-07 05:40:52 -09:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
useDataProvider,
|
2020-02-12 16:35:35 -09:00
|
|
|
useTranslate,
|
|
|
|
|
useUnselectAll,
|
2020-05-05 07:19:41 -08:00
|
|
|
useNotify,
|
2020-02-07 05:40:52 -09:00
|
|
|
} from 'react-admin'
|
2020-02-04 05:26:54 -09:00
|
|
|
import { useDispatch } from 'react-redux'
|
2020-03-11 15:46:46 -08:00
|
|
|
import { addTrack } from '../audioplayer'
|
2020-02-06 08:54:27 -09:00
|
|
|
import AddToQueueIcon from '@material-ui/icons/AddToQueue'
|
|
|
|
|
|
2020-02-04 05:26:54 -09:00
|
|
|
const AddToQueueButton = ({ selectedIds }) => {
|
|
|
|
|
const dispatch = useDispatch()
|
2020-02-07 05:40:52 -09:00
|
|
|
const translate = useTranslate()
|
2020-02-04 05:26:54 -09:00
|
|
|
const dataProvider = useDataProvider()
|
|
|
|
|
const unselectAll = useUnselectAll()
|
2020-05-05 07:19:41 -08:00
|
|
|
const notify = useNotify()
|
|
|
|
|
|
2020-02-04 05:26:54 -09:00
|
|
|
const addToQueue = () => {
|
2020-05-05 07:19:41 -08:00
|
|
|
dataProvider
|
|
|
|
|
.getMany('song', { ids: selectedIds })
|
|
|
|
|
.then((response) => {
|
|
|
|
|
// Add the tracks to the queue in the selection order
|
|
|
|
|
const tracks = response.data.reduce((acc, cur) => {
|
|
|
|
|
acc[cur.id] = cur
|
|
|
|
|
return acc
|
|
|
|
|
}, {})
|
|
|
|
|
selectedIds.forEach((id) => {
|
|
|
|
|
dispatch(addTrack(tracks[id]))
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
notify('ra.page.error', 'warning')
|
2020-02-04 05:26:54 -09:00
|
|
|
})
|
|
|
|
|
unselectAll('song')
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 08:54:27 -09:00
|
|
|
return (
|
2020-02-12 16:35:35 -09:00
|
|
|
<Button
|
|
|
|
|
color="secondary"
|
|
|
|
|
onClick={addToQueue}
|
2020-05-01 06:28:31 -08:00
|
|
|
label={translate('resources.song.actions.addToQueue')}
|
2020-02-12 16:35:35 -09:00
|
|
|
>
|
|
|
|
|
<AddToQueueIcon />
|
2020-02-07 07:45:56 -09:00
|
|
|
</Button>
|
2020-02-06 08:54:27 -09:00
|
|
|
)
|
2020-02-04 05:26:54 -09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default AddToQueueButton
|