this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix event listener cleanup

Juliet 72a586ce 387c2ad8

+10 -9
+10 -9
src/components/navbar.tsx
··· 1 1 import { Did, Handle } from "@atcute/lexicons"; 2 2 import { A, Params, useLocation } from "@solidjs/router"; 3 - import { createEffect, createSignal, onMount, Show } from "solid-js"; 3 + import { createEffect, createSignal, onCleanup, onMount, Show } from "solid-js"; 4 4 import { didDocCache, labelerCache, validateHandle } from "../utils/api"; 5 5 import { addToClipboard } from "../utils/copy"; 6 6 import Tooltip from "./tooltip"; ··· 34 34 const [showHandle, setShowHandle] = createSignal(localStorage.showHandle === "true"); 35 35 const [showCopyMenu, setShowCopyMenu] = createSignal(false); 36 36 const [copyMenu, setCopyMenu] = createSignal<HTMLDivElement>(); 37 - const [menuButton, setMenuButton] = createSignal<HTMLButtonElement>(); 37 + const [copyButton, setCopyButton] = createSignal<HTMLButtonElement>(); 38 38 39 39 createEffect(() => { 40 40 if (cid() !== undefined) setFullCid(false); ··· 54 54 } 55 55 }); 56 56 57 - onMount(() => 58 - window.addEventListener("click", (ev) => { 59 - if (!menuButton()?.contains(ev.target as Node) && !copyMenu()?.contains(ev.target as Node)) 60 - setShowCopyMenu(false); 61 - }), 62 - ); 57 + const clickEvent = (event: MouseEvent) => { 58 + const target = event.target as Node; 59 + if (!copyButton()?.contains(target) && !copyMenu()?.contains(target)) setShowCopyMenu(false); 60 + }; 61 + 62 + onMount(() => window.addEventListener("click", clickEvent)); 63 + onCleanup(() => window.removeEventListener("click", clickEvent)); 63 64 64 65 const CopyButton = (props: { copyContent: string; label: string }) => { 65 66 return ( ··· 100 101 <div class="relative"> 101 102 <button 102 103 class="flex items-center rounded p-0.5 hover:bg-neutral-200 active:bg-neutral-200 dark:hover:bg-neutral-700 dark:active:bg-neutral-700" 103 - ref={setMenuButton} 104 + ref={setCopyButton} 104 105 onClick={() => setShowCopyMenu(!showCopyMenu())} 105 106 > 106 107 <span class="iconify lucide--copy text-base"></span>