2020-05-17 14:55:17 -08:00
|
|
|
import React from 'react'
|
|
|
|
|
import { Button, useTranslate, useUnselectAll } from 'react-admin'
|
|
|
|
|
import { Menu } from '@material-ui/core'
|
2020-05-15 16:47:15 -08:00
|
|
|
import PlaylistAddIcon from '@material-ui/icons/PlaylistAdd'
|
2020-05-17 14:55:17 -08:00
|
|
|
import { AddToPlaylistMenu } from '../common'
|
2020-05-15 16:47:15 -08:00
|
|
|
|
2020-05-18 09:05:54 -08:00
|
|
|
const AddToPlaylistButton = ({ resource, selectedIds, onAddToPlaylist }) => {
|
2020-05-17 14:55:17 -08:00
|
|
|
const [anchorEl, setAnchorEl] = React.useState(null)
|
2020-05-15 16:47:15 -08:00
|
|
|
const translate = useTranslate()
|
|
|
|
|
const unselectAll = useUnselectAll()
|
|
|
|
|
|
2020-05-17 14:55:17 -08:00
|
|
|
const handleClick = (event) => {
|
|
|
|
|
setAnchorEl(event.currentTarget)
|
2020-05-15 16:47:15 -08:00
|
|
|
}
|
|
|
|
|
|
2020-05-17 14:55:17 -08:00
|
|
|
const handleClose = () => {
|
|
|
|
|
setAnchorEl(null)
|
2020-05-15 16:47:15 -08:00
|
|
|
unselectAll(resource)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Button
|
2020-05-17 14:55:17 -08:00
|
|
|
aria-controls="simple-menu"
|
|
|
|
|
aria-haspopup="true"
|
|
|
|
|
onClick={handleClick}
|
2020-05-15 16:47:15 -08:00
|
|
|
color="secondary"
|
|
|
|
|
label={translate('resources.song.actions.addToPlaylist')}
|
|
|
|
|
>
|
|
|
|
|
<PlaylistAddIcon />
|
|
|
|
|
</Button>
|
2020-05-17 14:55:17 -08:00
|
|
|
<Menu
|
|
|
|
|
id="simple-menu"
|
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
keepMounted
|
|
|
|
|
open={Boolean(anchorEl)}
|
2020-05-15 16:47:15 -08:00
|
|
|
onClose={handleClose}
|
2020-05-17 14:55:17 -08:00
|
|
|
>
|
|
|
|
|
<AddToPlaylistMenu
|
|
|
|
|
selectedIds={selectedIds}
|
|
|
|
|
menuOpen={Boolean(anchorEl)}
|
2020-05-18 08:10:54 -08:00
|
|
|
onClose={handleClose}
|
2020-05-18 09:05:54 -08:00
|
|
|
onItemAdded={onAddToPlaylist}
|
2020-05-17 14:55:17 -08:00
|
|
|
/>
|
|
|
|
|
</Menu>
|
2020-05-15 16:47:15 -08:00
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default AddToPlaylistButton
|