import { Attachment as AttachmentI } from "revolt-api/types/Autumn"; import styles from "./Attachment.module.scss"; import classNames from "classnames"; import { useContext, useState } from "preact/hooks"; import { useIntermediate } from "../../../../context/intermediate/Intermediate"; import { AppContext } from "../../../../context/revoltjs/RevoltClient"; import AttachmentActions from "./AttachmentActions"; import { SizedGrid } from "./Grid"; import Spoiler from "./Spoiler"; import TextFile from "./TextFile"; interface Props { attachment: AttachmentI; 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_")); // only used in image attachments const [loading, setLoading] = useState(true); const url = client.generateFileURL( attachment, { width: MAX_ATTACHMENT_WIDTH * 1.5 }, true, ); switch (metadata.type) { case "Image": { return ( {filename} openScreen({ id: "image_viewer", attachment }) } onLoad={() => setLoading(false) } onMouseDown={(ev) => ev.button === 1 && window.open(url, "_blank") } /> {spoiler && } ); } case "Video": { return (
); } case "Audio": { return (
); } case "Text": { return (
); } default: { return (
); } } }