Use active filters when shuffling songs

This commit is contained in:
Deluan
2020-08-14 14:10:39 -04:00
parent c2e03c8162
commit ca5da5b0ea
3 changed files with 55 additions and 47 deletions
+3 -47
View File
@@ -1,50 +1,6 @@
import React, { cloneElement } from 'react'
import { useDispatch } from 'react-redux'
import {
Button,
sanitizeListRestProps,
TopToolbar,
useDataProvider,
useTranslate,
useNotify,
} from 'react-admin'
import ShuffleIcon from '@material-ui/icons/Shuffle'
import { playTracks } from '../audioplayer'
const ShuffleAllButton = () => {
const translate = useTranslate()
const dataProvider = useDataProvider()
const dispatch = useDispatch()
const notify = useNotify()
const handleOnClick = () => {
dataProvider
.getList('song', {
pagination: { page: 1, perPage: 200 },
sort: { field: 'random', order: 'ASC' },
filter: {},
})
.then((res) => {
const data = {}
res.data.forEach((song) => {
data[song.id] = song
})
dispatch(playTracks(data))
})
.catch(() => {
notify('ra.page.error', 'warning')
})
}
return (
<Button
onClick={handleOnClick}
label={translate('resources.song.actions.shuffleAll')}
>
<ShuffleIcon />
</Button>
)
}
import { sanitizeListRestProps, TopToolbar } from 'react-admin'
import { ShuffleAllButton } from '../common'
export const SongListActions = ({
currentSort,
@@ -74,7 +30,7 @@ export const SongListActions = ({
filterValues,
context: 'button',
})}
<ShuffleAllButton />
<ShuffleAllButton filters={filterValues} />
</TopToolbar>
)
}