Files
navidrome/ui/src/common/ShuffleAllButton.jsx
T
Deluan Quintão 70f536e04d fix(ui): skip missing files in bulk operations (#3807)
* fix(ui): skip missing files when adding to playqueue

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(ui): skip missing files when adding to playlists

* fix(ui): skip missing files when shuffling songs

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
2025-03-11 20:19:46 -04:00

50 lines
1.2 KiB
React

import React from 'react'
import { Button, useDataProvider, useNotify, useTranslate } from 'react-admin'
import { useDispatch } from 'react-redux'
import ShuffleIcon from '@material-ui/icons/Shuffle'
import { playTracks } from '../actions'
import PropTypes from 'prop-types'
export const ShuffleAllButton = ({ filters }) => {
const translate = useTranslate()
const dataProvider = useDataProvider()
const dispatch = useDispatch()
const notify = useNotify()
filters = { ...filters, missing: false }
const handleOnClick = () => {
dataProvider
.getList('song', {
pagination: { page: 1, perPage: 500 },
sort: { field: 'random', order: 'ASC' },
filter: filters,
})
.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>
)
}
ShuffleAllButton.propTypes = {
filters: PropTypes.object,
}
ShuffleAllButton.defaultProps = {
filters: {},
}