Refactor album actions, simplify usage
This commit is contained in:
@@ -21,14 +21,11 @@ export const AlbumActions = ({
|
||||
const dispatch = useDispatch()
|
||||
const translate = useTranslate()
|
||||
|
||||
// Filter out tracks from other albums (cached by ReactAdmin)
|
||||
const filteredData = ids.reduce((acc, id) => ({ ...acc, [id]: data[id] }), {})
|
||||
|
||||
return (
|
||||
<TopToolbar className={className} {...sanitizeListRestProps(rest)}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
dispatch(playAlbum(ids[0], filteredData))
|
||||
dispatch(playAlbum(data, ids))
|
||||
}}
|
||||
label={translate('resources.album.actions.playAll')}
|
||||
>
|
||||
@@ -36,7 +33,7 @@ export const AlbumActions = ({
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
dispatch(shuffleAlbum(filteredData))
|
||||
dispatch(shuffleAlbum(data, ids))
|
||||
}}
|
||||
label={translate('resources.album.actions.shuffle')}
|
||||
>
|
||||
|
||||
@@ -25,11 +25,11 @@ const AlbumContextMenu = ({ record, color }) => {
|
||||
const options = {
|
||||
play: {
|
||||
label: translate('resources.album.actions.playAll'),
|
||||
action: (data, id) => playAlbum(id, data),
|
||||
action: (data) => playAlbum(data),
|
||||
},
|
||||
addToQueue: {
|
||||
label: translate('resources.album.actions.addToQueue'),
|
||||
action: (data) => addTracks(Object.values(data)),
|
||||
action: (data) => addTracks(data),
|
||||
},
|
||||
shuffle: {
|
||||
label: translate('resources.album.actions.shuffle'),
|
||||
@@ -63,7 +63,7 @@ const AlbumContextMenu = ({ record, color }) => {
|
||||
(acc, cur) => ({ ...acc, [cur.id]: cur }),
|
||||
{}
|
||||
)
|
||||
dispatch(options[key].action(adata, response.data[0].id))
|
||||
dispatch(options[key].action(adata))
|
||||
})
|
||||
.catch(() => {
|
||||
notify('ra.page.error', 'warning')
|
||||
|
||||
@@ -108,7 +108,7 @@ const AlbumSongs = (props) => {
|
||||
) : (
|
||||
<Datagrid
|
||||
expand={!isXsmall && <SongDetails />}
|
||||
rowClick={(id) => dispatch(playAlbum(id, data))}
|
||||
rowClick={(id) => dispatch(playAlbum(data, ids, id))}
|
||||
{...controllerProps}
|
||||
hasBulkActions={hasBulkActions}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user