navidrome/ui/src/dialogs/ShareDialog.js

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

86 lines
2.3 KiB
JavaScript
Raw Normal View History

2023-01-20 04:52:55 +01:00
import {
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
} from '@material-ui/core'
import { SimpleForm, TextInput, useCreate, useNotify } from 'react-admin'
import { useState } from 'react'
2023-01-20 04:52:55 +01:00
import { shareUrl } from '../utils'
import { useTranscodingOptions } from './useTranscodingOptions'
2023-01-20 04:52:55 +01:00
export const ShareDialog = ({ open, onClose, ids, resource, title }) => {
2023-01-20 04:52:55 +01:00
const notify = useNotify()
const [description, setDescription] = useState('')
const { TranscodingOptionsInput, format, maxBitRate, originalFormat } =
useTranscodingOptions()
2023-01-20 04:52:55 +01:00
const [createShare] = useCreate(
'share',
{
resourceType: resource,
resourceIds: ids?.join(','),
description,
...(!originalFormat && { format }),
...(!originalFormat && { maxBitRate }),
2023-01-20 04:52:55 +01:00
},
{
onSuccess: (res) => {
const url = shareUrl(res?.data?.id)
onClose()
2023-01-20 04:52:55 +01:00
navigator.clipboard
.writeText(url)
.then(() => {
notify(`URL copied to clipboard: ${url}`, {
type: 'info',
multiLine: true,
duration: 0,
})
})
.catch((err) => {
notify(`Error copying URL ${url} to clipboard: ${err.message}`, {
type: 'warning',
multiLine: true,
duration: 0,
})
})
},
onFailure: (error) =>
notify(`Error sharing media: ${error.message}`, { type: 'warning' }),
}
)
return (
<Dialog
open={open}
onClose={onClose}
onBackdropClick={onClose}
2023-01-21 01:53:53 +01:00
aria-labelledby="share-dialog"
2023-01-20 04:52:55 +01:00
fullWidth={true}
maxWidth={'xs'}
2023-01-20 04:52:55 +01:00
>
2023-01-21 01:53:53 +01:00
<DialogTitle id="share-dialog">{title}</DialogTitle>
2023-01-20 04:52:55 +01:00
<DialogContent>
<SimpleForm toolbar={null} variant={'outlined'}>
<TextInput
source="description"
fullWidth
onChange={(event) => {
setDescription(event.target.value)
}}
/>
<TranscodingOptionsInput />
2023-01-20 04:52:55 +01:00
</SimpleForm>
</DialogContent>
<DialogActions>
<Button onClick={createShare} color="primary">
Share
</Button>
<Button onClick={onClose} color="primary">
Cancel
</Button>
</DialogActions>
</Dialog>
)
}