import type { mastodon } from "masto"; import { type Component, For, createSignal, onMount } from "solid-js"; import { css } from "solid-styled"; import tootStyle from "./toot.module.css"; import MediaViewer from "./MediaViewer"; import { render } from "solid-js/web"; const MediaAttachmentGrid: Component<{ attachments: mastodon.v1.MediaAttachment[]; }> = (props) => { let rootRef: HTMLElement; const [viewerIndex, setViewerIndex] = createSignal(); const viewerOpened = () => typeof viewerIndex() !== "undefined"; const gridTemplateColumns = () => { const l = props.attachments.length; if (l < 2) { return "minmax(40px, auto)"; } if (l < 4) { return "repeat(2, minmax(40px, auto))"; } return "repeat(3, minmax(40px, auto))"; }; const openViewerFor = (index: number) => { setViewerIndex(index); const container = document.createElement("div"); container.setAttribute("role", "presentation"); document.body.appendChild(container); let dispose: () => void dispose = render(() => { return ( { setViewerIndex(undefined); dispose(); document.body.removeChild(container) }} /> ); }, container); }; css` .attachments { grid-template-columns: ${gridTemplateColumns()}; } `; return (
e.stopImmediatePropagation()} > {(item, index) => { switch (item.type) { case "image": return ( {item.description ); case "video": case "gifv": case "audio": case "unknown": return
; } }}
); }; export default MediaAttachmentGrid;