2024-01-09 13:30:05 +01:00
|
|
|
import { Button, Dialog, DialogBody, DialogHeader, Textarea, Typography } from '@material-tailwind/react'
|
2023-12-29 04:37:04 +01:00
|
|
|
import { Entity, MegalodonInterface } from 'megalodon'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import { FormattedMessage } from 'react-intl'
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
media: Entity.Attachment | undefined
|
|
|
|
close: () => void
|
|
|
|
client: MegalodonInterface
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function EditMedia(props: Props) {
|
|
|
|
const [description, setDescription] = useState('')
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (props.media) {
|
|
|
|
const f = async () => {
|
|
|
|
const res = await props.client.getMedia(props.media.id)
|
|
|
|
if (res.data.description) {
|
|
|
|
setDescription(res.data.description)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
}, [props.media, props.client])
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
if (!props.media || !props.client) return
|
|
|
|
await props.client.updateMedia(props.media.id, {
|
|
|
|
description: description
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const onClose = () => {
|
|
|
|
setDescription('')
|
|
|
|
props.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-01-09 13:30:05 +01:00
|
|
|
<Dialog open={props.media !== undefined} handler={onClose} size="xl">
|
2023-12-29 04:37:04 +01:00
|
|
|
{props.media && (
|
|
|
|
<>
|
2024-01-09 13:30:05 +01:00
|
|
|
<DialogHeader>
|
2023-12-29 04:37:04 +01:00
|
|
|
<FormattedMessage id="compose.edit_media.title" />
|
2024-01-09 13:30:05 +01:00
|
|
|
</DialogHeader>
|
|
|
|
<DialogBody className="max-h-full max-w-full">
|
2023-12-29 04:37:04 +01:00
|
|
|
<div className="flex gap-2">
|
|
|
|
<div className="w-1/4">
|
2024-01-09 13:30:05 +01:00
|
|
|
<Typography>
|
2023-12-29 04:37:04 +01:00
|
|
|
<FormattedMessage id="compose.edit_media.label" />
|
2024-01-09 13:30:05 +01:00
|
|
|
</Typography>
|
2023-12-29 04:37:04 +01:00
|
|
|
<Textarea id="description" rows={4} value={description} onChange={ev => setDescription(ev.target.value)} />
|
2024-01-09 13:30:05 +01:00
|
|
|
<Button className="mt-2" onClick={submit}>
|
2023-12-29 04:37:04 +01:00
|
|
|
<FormattedMessage id="compose.edit_media.submit" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<div className="w-3/4">
|
|
|
|
<img src={props.media.preview_url} className="object-cover m-auto" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-09 13:30:05 +01:00
|
|
|
</DialogBody>
|
2023-12-29 04:37:04 +01:00
|
|
|
</>
|
|
|
|
)}
|
2024-01-09 13:30:05 +01:00
|
|
|
<></>
|
|
|
|
</Dialog>
|
2023-12-29 04:37:04 +01:00
|
|
|
)
|
|
|
|
}
|