Add option to shuffle playlist
This commit is contained in:
@@ -48,7 +48,9 @@ const shuffle = (data) => {
|
|||||||
;[ids[i], ids[j]] = [ids[j], ids[i]]
|
;[ids[i], ids[j]] = [ids[j], ids[i]]
|
||||||
}
|
}
|
||||||
const shuffled = {}
|
const shuffled = {}
|
||||||
ids.forEach((id) => (shuffled[id] = data[id]))
|
// The "_" is to force the object key to be a string, so it keeps the order when adding to object
|
||||||
|
// or else the keys will always be in the same (numerically) order
|
||||||
|
ids.forEach((id) => (shuffled['_' + id] = data[id]))
|
||||||
return shuffled
|
return shuffled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import {
|
|||||||
useTranslate,
|
useTranslate,
|
||||||
} from 'react-admin'
|
} from 'react-admin'
|
||||||
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
||||||
|
import ShuffleIcon from '@material-ui/icons/Shuffle'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { playTracks } from '../audioplayer'
|
import { playTracks, shuffleTracks } from '../audioplayer'
|
||||||
|
|
||||||
const PlaylistActions = ({
|
const PlaylistActions = ({
|
||||||
className,
|
className,
|
||||||
@@ -30,6 +31,14 @@ const PlaylistActions = ({
|
|||||||
>
|
>
|
||||||
<PlayArrowIcon />
|
<PlayArrowIcon />
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
dispatch(shuffleTracks(data, ids))
|
||||||
|
}}
|
||||||
|
label={translate('resources.album.actions.shuffle')}
|
||||||
|
>
|
||||||
|
<ShuffleIcon />
|
||||||
|
</Button>
|
||||||
</TopToolbar>
|
</TopToolbar>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user