import TextFile from "./TextFile"; import { Text } from "preact-i18n"; import classNames from "classnames"; import styles from "./Attachment.module.scss"; import AttachmentActions from "./AttachmentActions"; import { useContext, useState } from "preact/hooks"; import { AppContext } from "../../../../context/revoltjs/RevoltClient"; import { Attachment as AttachmentRJS } from "revolt.js/dist/api/objects"; import { useIntermediate } from "../../../../context/intermediate/Intermediate"; import { MessageAreaWidthContext } from "../../../../pages/channels/messaging/MessageArea"; interface Props { attachment: AttachmentRJS; hasContent: boolean; } const MAX_ATTACHMENT_WIDTH = 480; export default function Attachment({ attachment, hasContent }: Props) { const client = useContext(AppContext); const { openScreen } = useIntermediate(); const { filename, metadata } = attachment; const [ spoiler, setSpoiler ] = useState(filename.startsWith("SPOILER_")); const [ loaded, setLoaded ] = useState(false) const url = client.generateFileURL(attachment, { width: MAX_ATTACHMENT_WIDTH * 1.5 }, true); switch (metadata.type) { case "Image": { return (
spoiler && setSpoiler(false)} > {spoiler && (
)} {filename} openScreen({ id: "image_viewer", attachment }) } onMouseDown={ev => ev.button === 1 && window.open(url, "_blank") } onLoad={() => setLoaded(true)} />
); } case "Audio": { return (
); } case "Video": { return (
spoiler && setSpoiler(false)}> {spoiler && (
)}
); } case 'Text': { return (
); } default: { return (
); } } }