From 980f8cff7e790f53d5332413ccfaa64ede6bf0a1 Mon Sep 17 00:00:00 2001 From: thislight Date: Sat, 14 Sep 2024 20:43:44 +0800 Subject: [PATCH] MediaAttachmentGrid: fix the container not removed --- src/timelines/MediaAttachmentGrid.tsx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/timelines/MediaAttachmentGrid.tsx b/src/timelines/MediaAttachmentGrid.tsx index 9373205..d3b0058 100644 --- a/src/timelines/MediaAttachmentGrid.tsx +++ b/src/timelines/MediaAttachmentGrid.tsx @@ -1,5 +1,11 @@ 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 tootStyle from "./toot.module.css"; import MediaViewer from "./MediaViewer"; @@ -27,7 +33,15 @@ const MediaAttachmentGrid: Component<{ const container = document.createElement("div"); container.setAttribute("role", "presentation"); document.body.appendChild(container); - let dispose: () => void + + let dispose: () => void; + + const removeContainer = () => { + setViewerIndex(undefined); + document.body.removeChild(container); + dispose(); + }; + dispose = render(() => { return ( { - setViewerIndex(undefined); - dispose(); - document.body.removeChild(container) - }} + onClose={removeContainer} /> ); }, container);