MediaAttachmentGrid: fix the container not removed
All checks were successful
/ depoly (push) Successful in 1m5s

This commit is contained in:
thislight 2024-09-14 20:43:44 +08:00
parent e8a4e382ba
commit 980f8cff7e
No known key found for this signature in database
GPG key ID: A50F9451AC56A63E

View file

@ -1,5 +1,11 @@
import type { mastodon } from "masto"; import type { mastodon } from "masto";
import { type Component, For, createSignal, onMount } from "solid-js"; import {
type Component,
For,
createSignal,
onCleanup,
onMount,
} from "solid-js";
import { css } from "solid-styled"; import { css } from "solid-styled";
import tootStyle from "./toot.module.css"; import tootStyle from "./toot.module.css";
import MediaViewer from "./MediaViewer"; import MediaViewer from "./MediaViewer";
@ -27,7 +33,15 @@ const MediaAttachmentGrid: Component<{
const container = document.createElement("div"); const container = document.createElement("div");
container.setAttribute("role", "presentation"); container.setAttribute("role", "presentation");
document.body.appendChild(container); document.body.appendChild(container);
let dispose: () => void
let dispose: () => void;
const removeContainer = () => {
setViewerIndex(undefined);
document.body.removeChild(container);
dispose();
};
dispose = render(() => { dispose = render(() => {
return ( return (
<MediaViewer <MediaViewer
@ -35,11 +49,7 @@ const MediaAttachmentGrid: Component<{
index={viewerIndex() || 0} index={viewerIndex() || 0}
onIndexUpdated={setViewerIndex} onIndexUpdated={setViewerIndex}
media={props.attachments} media={props.attachments}
onClose={() => { onClose={removeContainer}
setViewerIndex(undefined);
dispose();
document.body.removeChild(container)
}}
/> />
); );
}, container); }, container);