import { Attachment as AttachmentRJS } from "revolt.js/dist/api/objects"; import styles from "./Attachment.module.scss"; import classNames from "classnames"; import { Text } from "preact-i18n"; import { useContext, useState } from "preact/hooks"; import { useIntermediate } from "../../../../context/intermediate/Intermediate"; import { AppContext } from "../../../../context/revoltjs/RevoltClient"; import { MessageAreaWidthContext } from "../../../../pages/channels/messaging/MessageArea"; import AttachmentActions from "./AttachmentActions"; import TextFile from "./TextFile"; 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 (