2025-06-09 13:06:10 -08:00
|
|
|
import React from 'react'
|
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
import { useDispatch } from 'react-redux'
|
2025-11-21 18:23:38 -09:00
|
|
|
import { useMediaQuery, CircularProgress } from '@material-ui/core'
|
2025-06-09 13:06:10 -08:00
|
|
|
import { makeStyles } from '@material-ui/core/styles'
|
|
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
TopToolbar,
|
|
|
|
|
sanitizeListRestProps,
|
|
|
|
|
useDataProvider,
|
|
|
|
|
useNotify,
|
|
|
|
|
useTranslate,
|
|
|
|
|
} from 'react-admin'
|
|
|
|
|
import ShuffleIcon from '@material-ui/icons/Shuffle'
|
2025-06-09 15:07:42 -08:00
|
|
|
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
2025-06-09 13:06:10 -08:00
|
|
|
import { IoIosRadio } from 'react-icons/io'
|
2026-01-25 12:16:43 -09:00
|
|
|
import { playShuffle, playTopSongs } from './actions.js'
|
|
|
|
|
import { playSimilar } from '../common/playbackActions.js'
|
2025-06-09 13:06:10 -08:00
|
|
|
|
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
|
|
|
toolbar: {
|
|
|
|
|
minHeight: 'auto',
|
|
|
|
|
padding: '0 !important',
|
|
|
|
|
background: 'transparent',
|
|
|
|
|
boxShadow: 'none',
|
|
|
|
|
'& .MuiToolbar-root': {
|
|
|
|
|
minHeight: 'auto',
|
|
|
|
|
padding: '0 !important',
|
|
|
|
|
background: 'transparent',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
button: {
|
|
|
|
|
[theme.breakpoints.down('xs')]: {
|
|
|
|
|
minWidth: 'auto',
|
|
|
|
|
padding: '8px 12px',
|
|
|
|
|
fontSize: '0.75rem',
|
|
|
|
|
'& .MuiButton-startIcon': {
|
|
|
|
|
marginRight: '4px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
radioIcon: {
|
|
|
|
|
[theme.breakpoints.down('xs')]: {
|
|
|
|
|
fontSize: '1.5rem',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
|
2025-11-21 18:23:38 -09:00
|
|
|
const LoadingButton = ({ loading, icon, ...rest }) => (
|
|
|
|
|
<Button {...rest}>
|
|
|
|
|
{loading ? <CircularProgress size={20} color="inherit" /> : icon}
|
|
|
|
|
</Button>
|
|
|
|
|
)
|
|
|
|
|
|
2025-06-09 13:06:10 -08:00
|
|
|
const ArtistActions = ({ className, record, ...rest }) => {
|
|
|
|
|
const dispatch = useDispatch()
|
|
|
|
|
const translate = useTranslate()
|
|
|
|
|
const dataProvider = useDataProvider()
|
|
|
|
|
const notify = useNotify()
|
|
|
|
|
const classes = useStyles()
|
|
|
|
|
const isMobile = useMediaQuery((theme) => theme.breakpoints.down('xs'))
|
2025-11-21 18:23:38 -09:00
|
|
|
const [loadingAction, setLoadingAction] = React.useState(null)
|
|
|
|
|
const isLoading = !!loadingAction
|
2025-06-09 13:06:10 -08:00
|
|
|
|
2025-06-09 15:07:42 -08:00
|
|
|
const handlePlay = React.useCallback(async () => {
|
2025-11-21 18:23:38 -09:00
|
|
|
setLoadingAction('play')
|
2025-06-09 13:06:10 -08:00
|
|
|
try {
|
2025-06-09 15:07:42 -08:00
|
|
|
await playTopSongs(dispatch, notify, record.name)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
|
console.error('Error fetching top songs for artist:', e)
|
|
|
|
|
notify('ra.page.error', 'warning')
|
2025-11-21 18:23:38 -09:00
|
|
|
} finally {
|
|
|
|
|
setLoadingAction(null)
|
2025-06-09 15:07:42 -08:00
|
|
|
}
|
|
|
|
|
}, [dispatch, notify, record])
|
2025-06-09 13:06:10 -08:00
|
|
|
|
2025-06-09 15:07:42 -08:00
|
|
|
const handleShuffle = React.useCallback(async () => {
|
2025-11-21 18:23:38 -09:00
|
|
|
setLoadingAction('shuffle')
|
2025-06-09 15:07:42 -08:00
|
|
|
try {
|
|
|
|
|
await playShuffle(dataProvider, dispatch, record.id)
|
2025-06-09 13:06:10 -08:00
|
|
|
} catch (e) {
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
|
console.error('Error fetching songs for shuffle:', e)
|
|
|
|
|
notify('ra.page.error', 'warning')
|
2025-11-21 18:23:38 -09:00
|
|
|
} finally {
|
|
|
|
|
setLoadingAction(null)
|
2025-06-09 13:06:10 -08:00
|
|
|
}
|
|
|
|
|
}, [dataProvider, dispatch, record, notify])
|
|
|
|
|
|
|
|
|
|
const handleRadio = React.useCallback(async () => {
|
2025-11-21 18:23:38 -09:00
|
|
|
setLoadingAction('radio')
|
2025-06-09 13:06:10 -08:00
|
|
|
try {
|
|
|
|
|
await playSimilar(dispatch, notify, record.id)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
|
console.error('Error starting radio for artist:', e)
|
|
|
|
|
notify('ra.page.error', 'warning')
|
2025-11-21 18:23:38 -09:00
|
|
|
} finally {
|
|
|
|
|
setLoadingAction(null)
|
2025-06-09 13:06:10 -08:00
|
|
|
}
|
|
|
|
|
}, [dispatch, notify, record])
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<TopToolbar
|
|
|
|
|
className={`${className} ${classes.toolbar}`}
|
|
|
|
|
{...sanitizeListRestProps(rest)}
|
|
|
|
|
>
|
2025-11-21 18:23:38 -09:00
|
|
|
<LoadingButton
|
2025-06-09 15:07:42 -08:00
|
|
|
onClick={handlePlay}
|
|
|
|
|
label={translate('resources.artist.actions.topSongs')}
|
|
|
|
|
className={classes.button}
|
|
|
|
|
size={isMobile ? 'small' : 'medium'}
|
2025-11-21 18:23:38 -09:00
|
|
|
disabled={isLoading}
|
|
|
|
|
loading={loadingAction === 'play'}
|
|
|
|
|
icon={<PlayArrowIcon />}
|
|
|
|
|
/>
|
|
|
|
|
<LoadingButton
|
2025-06-09 13:06:10 -08:00
|
|
|
onClick={handleShuffle}
|
|
|
|
|
label={translate('resources.artist.actions.shuffle')}
|
|
|
|
|
className={classes.button}
|
|
|
|
|
size={isMobile ? 'small' : 'medium'}
|
2025-11-21 18:23:38 -09:00
|
|
|
disabled={isLoading}
|
|
|
|
|
loading={loadingAction === 'shuffle'}
|
|
|
|
|
icon={<ShuffleIcon />}
|
|
|
|
|
/>
|
|
|
|
|
<LoadingButton
|
2025-06-09 13:06:10 -08:00
|
|
|
onClick={handleRadio}
|
|
|
|
|
label={translate('resources.artist.actions.radio')}
|
|
|
|
|
className={classes.button}
|
|
|
|
|
size={isMobile ? 'small' : 'medium'}
|
2025-11-21 18:23:38 -09:00
|
|
|
disabled={isLoading}
|
|
|
|
|
loading={loadingAction === 'radio'}
|
|
|
|
|
icon={<IoIosRadio className={classes.radioIcon} />}
|
|
|
|
|
/>
|
2025-06-09 13:06:10 -08:00
|
|
|
</TopToolbar>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArtistActions.propTypes = {
|
|
|
|
|
className: PropTypes.string,
|
|
|
|
|
record: PropTypes.object.isRequired,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArtistActions.defaultProps = {
|
|
|
|
|
className: '',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ArtistActions
|