MediaAttachmentGrid: fix the container not removed
This commit is contained in:
		
							parent
							
								
									d1cf97fe74
								
							
						
					
					
						commit
						972b2eca8b
					
				
					 1 changed files with 17 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -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 (
 | 
			
		||||
        <MediaViewer
 | 
			
		||||
| 
						 | 
				
			
			@ -35,11 +49,7 @@ const MediaAttachmentGrid: Component<{
 | 
			
		|||
          index={viewerIndex() || 0}
 | 
			
		||||
          onIndexUpdated={setViewerIndex}
 | 
			
		||||
          media={props.attachments}
 | 
			
		||||
          onClose={() => {
 | 
			
		||||
            setViewerIndex(undefined);
 | 
			
		||||
            dispose();
 | 
			
		||||
            document.body.removeChild(container)
 | 
			
		||||
          }}
 | 
			
		||||
          onClose={removeContainer}
 | 
			
		||||
        />
 | 
			
		||||
      );
 | 
			
		||||
    }, container);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue