From d1cf97fe7488d7f5ca66121694cb6e73a225846f Mon Sep 17 00:00:00 2001 From: thislight Date: Sat, 14 Sep 2024 20:21:19 +0800 Subject: [PATCH] MediaAttachmentGrid: lazily created viewer The reworked viewer presentation process delay the creation of the viewer until the user interaction, to reduce the DOM created during viewing the list. --- src/timelines/MediaAttachmentGrid.tsx | 29 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/timelines/MediaAttachmentGrid.tsx b/src/timelines/MediaAttachmentGrid.tsx index 2d07752..9373205 100644 --- a/src/timelines/MediaAttachmentGrid.tsx +++ b/src/timelines/MediaAttachmentGrid.tsx @@ -1,8 +1,9 @@ import type { mastodon } from "masto"; -import { type Component, For, createSignal } from "solid-js"; +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[]; @@ -23,6 +24,25 @@ const MediaAttachmentGrid: Component<{ 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` @@ -56,13 +76,6 @@ const MediaAttachmentGrid: Component<{ } }} - setViewerIndex(undefined)} - /> ); };