quintodrome/ui/src/common/AddToPlaylistButton.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1,023 B
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
import { useDispatch } from 'react-redux'
import { Button, useTranslate, useUnselectAll } from 'react-admin'
2020-05-15 16:47:15 -08:00
import PlaylistAddIcon from '@material-ui/icons/PlaylistAdd'
import { openAddToPlaylist } from '../actions'
2020-05-15 16:47:15 -08:00
export const AddToPlaylistButton = ({ resource, selectedIds, className }) => {
2020-05-15 16:47:15 -08:00
const translate = useTranslate()
const dispatch = useDispatch()
2020-05-15 16:47:15 -08:00
const unselectAll = useUnselectAll()
const handleClick = () => {
dispatch(
openAddToPlaylist({
selectedIds,
onSuccess: () => unselectAll(resource),
}),
)
2020-05-15 16:47:15 -08:00
}
return (
<Button
aria-controls="simple-menu"
aria-haspopup="true"
onClick={handleClick}
className={className}
label={translate('resources.song.actions.addToPlaylist')}
>
<PlaylistAddIcon />
</Button>
2020-05-15 16:47:15 -08:00
)
}
AddToPlaylistButton.propTypes = {
resource: PropTypes.string.isRequired,
selectedIds: PropTypes.arrayOf(PropTypes.string).isRequired,
}