2024-01-09 13:30:05 +01:00
|
|
|
import { Button } from '@material-tailwind/react'
|
2023-11-03 15:02:48 +01:00
|
|
|
import { Entity } from 'megalodon'
|
2023-11-26 16:54:29 +01:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { FaEyeSlash } from 'react-icons/fa6'
|
2024-01-30 16:51:36 +01:00
|
|
|
import { FormattedMessage, useIntl } from 'react-intl'
|
2023-11-03 15:02:48 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
media: Array<Entity.Attachment>
|
2023-11-26 16:54:29 +01:00
|
|
|
sensitive: boolean
|
2023-12-02 11:26:45 +01:00
|
|
|
openMedia: (media: Entity.Attachment) => void
|
2023-11-03 15:02:48 +01:00
|
|
|
}
|
|
|
|
export default function Media(props: Props) {
|
2023-11-26 16:54:29 +01:00
|
|
|
const [sensitive, setSensitive] = useState(props.sensitive)
|
2024-01-30 16:51:36 +01:00
|
|
|
const { formatMessage } = useIntl()
|
2023-11-26 16:54:29 +01:00
|
|
|
|
2023-11-28 16:07:21 +01:00
|
|
|
if (props.media.length > 0) {
|
|
|
|
return (
|
|
|
|
<div className="relative">
|
|
|
|
{sensitive ? (
|
2024-01-09 13:30:05 +01:00
|
|
|
<Button size="sm" onClick={() => setSensitive(false)} variant="outlined" className="my-1" color="blue-gray">
|
2023-11-28 16:07:21 +01:00
|
|
|
<FormattedMessage id="timeline.status.cw" />
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<>
|
2024-01-30 16:51:36 +01:00
|
|
|
<button
|
|
|
|
className="absolute bg-gray-600 text-gray-200 top-1 left-1 p-1 rounded"
|
|
|
|
onClick={() => setSensitive(true)}
|
|
|
|
title={formatMessage({ id: 'timeline.status.hide_media' })}
|
|
|
|
>
|
2023-11-28 16:07:21 +01:00
|
|
|
<FaEyeSlash />
|
|
|
|
</button>
|
|
|
|
<div className="mt-2 flex flex-wrap gap-2">
|
|
|
|
{props.media.map((media, key) => (
|
|
|
|
<div key={key}>
|
2023-12-02 11:26:45 +01:00
|
|
|
<Attachment attachment={media} openMedia={() => props.openMedia(media)} />
|
2023-11-28 16:07:21 +01:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
2023-11-26 16:54:29 +01:00
|
|
|
</div>
|
2023-11-28 16:07:21 +01:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
2023-11-03 15:02:48 +01:00
|
|
|
}
|
2023-11-26 16:54:29 +01:00
|
|
|
|
|
|
|
type AttachmentProps = {
|
|
|
|
attachment: Entity.Attachment
|
2023-12-02 11:26:45 +01:00
|
|
|
openMedia: () => void
|
2023-11-26 16:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function Attachment(props: AttachmentProps) {
|
2023-11-28 16:07:21 +01:00
|
|
|
return (
|
|
|
|
<img
|
|
|
|
src={props.attachment.preview_url}
|
|
|
|
className="mb-2 max-w-full cursor-pointer"
|
|
|
|
style={{ height: '144px' }}
|
|
|
|
alt={props.attachment.description}
|
|
|
|
title={props.attachment.description}
|
2023-12-02 11:26:45 +01:00
|
|
|
onClick={props.openMedia}
|
2023-11-28 16:07:21 +01:00
|
|
|
/>
|
|
|
|
)
|
2023-11-26 16:54:29 +01:00
|
|
|
}
|