mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-02 00:21:14 +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 SongTitleField from './SongTitleField'
|
||||||
import QuickFilter from './QuickFilter'
|
import QuickFilter from './QuickFilter'
|
||||||
import useAlbumsPerPage from './useAlbumsPerPage'
|
import useAlbumsPerPage from './useAlbumsPerPage'
|
||||||
|
import ShuffleAllButton from './ShuffleAllButton'
|
||||||
import { AlbumContextMenu, ArtistContextMenu } from './ContextMenus'
|
import { AlbumContextMenu, ArtistContextMenu } from './ContextMenus'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -40,4 +41,5 @@ export {
|
|||||||
SongContextMenu,
|
SongContextMenu,
|
||||||
QuickFilter,
|
QuickFilter,
|
||||||
useAlbumsPerPage,
|
useAlbumsPerPage,
|
||||||
|
ShuffleAllButton,
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,6 @@
|
|||||||
import React, { cloneElement } from 'react'
|
import React, { cloneElement } from 'react'
|
||||||
import { useDispatch } from 'react-redux'
|
import { sanitizeListRestProps, TopToolbar } from 'react-admin'
|
||||||
import {
|
import { ShuffleAllButton } from '../common'
|
||||||
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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SongListActions = ({
|
export const SongListActions = ({
|
||||||
currentSort,
|
currentSort,
|
||||||
@ -74,7 +30,7 @@ export const SongListActions = ({
|
|||||||
filterValues,
|
filterValues,
|
||||||
context: 'button',
|
context: 'button',
|
||||||
})}
|
})}
|
||||||
<ShuffleAllButton />
|
<ShuffleAllButton filters={filterValues} />
|
||||||
</TopToolbar>
|
</TopToolbar>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user