2020-08-21 09:28:20 -08:00
|
|
|
import React from 'react'
|
2020-09-06 07:54:30 -08:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-21 09:28:20 -08:00
|
|
|
import { useDispatch } from 'react-redux'
|
2020-02-12 16:35:35 -09:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
sanitizeListRestProps,
|
|
|
|
|
TopToolbar,
|
|
|
|
|
useTranslate,
|
|
|
|
|
} from 'react-admin'
|
|
|
|
|
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
|
|
|
|
import ShuffleIcon from '@material-ui/icons/Shuffle'
|
2020-08-05 11:25:59 -08:00
|
|
|
import CloudDownloadOutlinedIcon from '@material-ui/icons/CloudDownloadOutlined'
|
2020-09-21 16:10:52 -08:00
|
|
|
import { RiPlayListAddFill, RiPlayList2Fill } from 'react-icons/ri'
|
|
|
|
|
import { playNext, addTracks, playTracks, shuffleTracks } from '../audioplayer'
|
2020-08-05 10:57:59 -08:00
|
|
|
import subsonic from '../subsonic'
|
2020-02-12 16:35:35 -09:00
|
|
|
|
2020-09-06 07:54:30 -08:00
|
|
|
const AlbumActions = ({ className, ids, data, record, ...rest }) => {
|
2020-02-12 16:35:35 -09:00
|
|
|
const dispatch = useDispatch()
|
2020-02-14 05:14:50 -09:00
|
|
|
const translate = useTranslate()
|
2020-02-12 16:35:35 -09:00
|
|
|
|
2020-09-06 07:44:15 -08:00
|
|
|
const handlePlay = React.useCallback(() => {
|
|
|
|
|
dispatch(playTracks(data, ids))
|
|
|
|
|
}, [dispatch, data, ids])
|
|
|
|
|
|
2020-09-21 16:10:52 -08:00
|
|
|
const handlePlayNext = React.useCallback(() => {
|
|
|
|
|
dispatch(playNext(data, ids))
|
|
|
|
|
}, [dispatch, data, ids])
|
|
|
|
|
|
2020-09-06 07:44:15 -08:00
|
|
|
const handlePlayLater = React.useCallback(() => {
|
|
|
|
|
dispatch(addTracks(data, ids))
|
|
|
|
|
}, [dispatch, data, ids])
|
|
|
|
|
|
|
|
|
|
const handleShuffle = React.useCallback(() => {
|
|
|
|
|
dispatch(shuffleTracks(data, ids))
|
|
|
|
|
}, [dispatch, data, ids])
|
|
|
|
|
|
|
|
|
|
const handleDownload = React.useCallback(() => {
|
2020-09-06 07:54:30 -08:00
|
|
|
subsonic.download(record.id)
|
|
|
|
|
}, [record])
|
2020-09-06 07:44:15 -08:00
|
|
|
|
2020-02-12 16:35:35 -09:00
|
|
|
return (
|
|
|
|
|
<TopToolbar className={className} {...sanitizeListRestProps(rest)}>
|
|
|
|
|
<Button
|
2020-09-06 07:44:15 -08:00
|
|
|
onClick={handlePlay}
|
2020-02-14 05:14:50 -09:00
|
|
|
label={translate('resources.album.actions.playAll')}
|
2020-02-12 16:35:35 -09:00
|
|
|
>
|
|
|
|
|
<PlayArrowIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
2020-09-06 07:44:15 -08:00
|
|
|
onClick={handleShuffle}
|
2020-02-14 05:14:50 -09:00
|
|
|
label={translate('resources.album.actions.shuffle')}
|
2020-02-12 16:35:35 -09:00
|
|
|
>
|
|
|
|
|
<ShuffleIcon />
|
|
|
|
|
</Button>
|
2020-09-21 16:10:52 -08:00
|
|
|
<Button
|
|
|
|
|
onClick={handlePlayNext}
|
|
|
|
|
label={translate('resources.album.actions.playNext')}
|
|
|
|
|
>
|
|
|
|
|
<RiPlayList2Fill />
|
|
|
|
|
</Button>
|
2020-08-05 10:57:59 -08:00
|
|
|
<Button
|
2020-09-06 07:44:15 -08:00
|
|
|
onClick={handlePlayLater}
|
|
|
|
|
label={translate('resources.album.actions.addToQueue')}
|
2020-08-05 10:57:59 -08:00
|
|
|
>
|
2020-09-21 16:10:52 -08:00
|
|
|
<RiPlayListAddFill />
|
2020-08-05 10:57:59 -08:00
|
|
|
</Button>
|
2020-09-05 04:59:06 -08:00
|
|
|
<Button
|
2020-09-06 07:44:15 -08:00
|
|
|
onClick={handleDownload}
|
|
|
|
|
label={translate('resources.album.actions.download')}
|
2020-09-05 04:59:06 -08:00
|
|
|
>
|
2020-09-06 07:44:15 -08:00
|
|
|
<CloudDownloadOutlinedIcon />
|
2020-09-05 04:59:06 -08:00
|
|
|
</Button>
|
2020-02-12 16:35:35 -09:00
|
|
|
</TopToolbar>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-06 07:54:30 -08:00
|
|
|
AlbumActions.propTypes = {
|
|
|
|
|
record: PropTypes.object.isRequired,
|
|
|
|
|
selectedIds: PropTypes.arrayOf(PropTypes.number),
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 16:35:35 -09:00
|
|
|
AlbumActions.defaultProps = {
|
2020-09-06 07:54:30 -08:00
|
|
|
record: {},
|
2020-02-12 16:35:35 -09:00
|
|
|
selectedIds: [],
|
|
|
|
|
onUnselectItems: () => null,
|
|
|
|
|
}
|
2020-05-15 09:48:33 -08:00
|
|
|
|
|
|
|
|
export default AlbumActions
|