mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-31 15:49:38 +03:00
Use active filters when shuffling songs
This commit is contained in:
parent
c2e03c8162
commit
ca5da5b0ea
50
ui/src/common/ShuffleAllButton.js
Normal file
50
ui/src/common/ShuffleAllButton.js
Normal file
@ -0,0 +1,50 @@
|
||||
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 '../audioplayer'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
const ShuffleAllButton = ({ filters }) => {
|
||||
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: 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: {},
|
||||
}
|
||||
|
||||
export default ShuffleAllButton
|
@ -15,6 +15,7 @@ import SongContextMenu from './SongContextMenu'
|
||||
import SongTitleField from './SongTitleField'
|
||||
import QuickFilter from './QuickFilter'
|
||||
import useAlbumsPerPage from './useAlbumsPerPage'
|
||||
import ShuffleAllButton from './ShuffleAllButton'
|
||||
import { AlbumContextMenu, ArtistContextMenu } from './ContextMenus'
|
||||
|
||||
export {
|
||||
@ -40,4 +41,5 @@ export {
|
||||
SongContextMenu,
|
||||
QuickFilter,
|
||||
useAlbumsPerPage,
|
||||
ShuffleAllButton,
|
||||
}
|
||||
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user