2023-01-22 06:49:22 +01:00
|
|
|
import { SimpleForm, useTranslate } from 'react-admin'
|
2022-12-18 18:12:37 +01:00
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Dialog,
|
|
|
|
DialogActions,
|
|
|
|
DialogContent,
|
|
|
|
DialogTitle,
|
|
|
|
} from '@material-ui/core'
|
|
|
|
import subsonic from '../subsonic'
|
|
|
|
import { closeDownloadMenu } from '../actions'
|
|
|
|
import { formatBytes } from '../utils'
|
2023-01-22 06:49:22 +01:00
|
|
|
import { useTranscodingOptions } from './useTranscodingOptions'
|
2022-12-18 18:12:37 +01:00
|
|
|
|
|
|
|
const DownloadMenuDialog = () => {
|
|
|
|
const { open, record, recordType } = useSelector(
|
|
|
|
(state) => state.downloadMenuDialog
|
|
|
|
)
|
|
|
|
const dispatch = useDispatch()
|
|
|
|
const translate = useTranslate()
|
|
|
|
|
2023-01-22 06:49:22 +01:00
|
|
|
const { TranscodingOptionsInput, format, maxBitRate, originalFormat } =
|
|
|
|
useTranscodingOptions()
|
2022-12-18 18:12:37 +01:00
|
|
|
|
|
|
|
const handleClose = (e) => {
|
|
|
|
dispatch(closeDownloadMenu())
|
|
|
|
e.stopPropagation()
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleDownload = (e) => {
|
|
|
|
if (record) {
|
2023-01-22 06:49:22 +01:00
|
|
|
if (originalFormat) {
|
|
|
|
subsonic.download(record.id, 'raw')
|
|
|
|
} else {
|
|
|
|
subsonic.download(record.id, format, maxBitRate?.toString())
|
|
|
|
}
|
2022-12-18 18:12:37 +01:00
|
|
|
dispatch(closeDownloadMenu())
|
|
|
|
}
|
|
|
|
e.stopPropagation()
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-01-22 06:49:22 +01:00
|
|
|
<Dialog
|
|
|
|
open={open}
|
|
|
|
onClose={handleClose}
|
|
|
|
onBackdropClick={handleClose}
|
|
|
|
aria-labelledby="download-dialog"
|
|
|
|
fullWidth={true}
|
|
|
|
maxWidth={'sm'}
|
|
|
|
>
|
|
|
|
<DialogTitle id="download-dialog">
|
|
|
|
{translate('message.downloadDialogTitle', {
|
|
|
|
resource: translate(`resources.${recordType}.name`, {
|
|
|
|
smart_count: 1,
|
|
|
|
}).toLocaleLowerCase(),
|
|
|
|
name: record?.name || record?.title,
|
|
|
|
size: formatBytes(record?.size),
|
|
|
|
})}
|
|
|
|
</DialogTitle>
|
|
|
|
<DialogContent>
|
|
|
|
<SimpleForm toolbar={null} variant={'outlined'}>
|
|
|
|
<TranscodingOptionsInput
|
|
|
|
fullWidth
|
|
|
|
label={translate('message.originalFormat')}
|
|
|
|
/>
|
|
|
|
</SimpleForm>
|
|
|
|
</DialogContent>
|
|
|
|
<DialogActions>
|
|
|
|
<Button onClick={handleDownload} color="primary">
|
|
|
|
{translate('ra.action.download')}
|
|
|
|
</Button>
|
|
|
|
<Button onClick={handleClose} color="secondary">
|
|
|
|
{translate('ra.action.close')}
|
|
|
|
</Button>
|
|
|
|
</DialogActions>
|
|
|
|
</Dialog>
|
2022-12-18 18:12:37 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DownloadMenuDialog
|