import { Attachment as AttachmentRJS } from "revolt.js/dist/api/objects"; 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: 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 url = client.generateFileURL( attachment, { width: MAX_ATTACHMENT_WIDTH * 1.5 }, true, ); switch (metadata.type) { case "Image": { return ( {filename} openScreen({ id: "image_viewer", attachment }) } onMouseDown={(ev) => ev.button === 1 && window.open(url, "_blank") } /> {spoiler && } ); } case "Video": { return (
); } case "Audio": { return (
); } case "Text": { return (
); } default: { return (
); } } }