diff --git a/apps/client/src/widgets/note_icon.ts.bak b/apps/client/src/widgets/note_icon.ts.bak index 8418405ff..e71a6b83c 100644 --- a/apps/client/src/widgets/note_icon.ts.bak +++ b/apps/client/src/widgets/note_icon.ts.bak @@ -26,10 +26,6 @@ export default class NoteIconWidget extends NoteContextAwareWidget { } }); - this.$iconCategory = this.$widget.find("select[name='icon-category']"); - this.$iconCategory.on("change", () => this.renderDropdown()); - this.$iconCategory.on("click", (e) => e.stopPropagation()); - this.$iconSearch = this.$widget.find("input[name='icon-search']"); this.$iconSearch.on("input", () => this.renderDropdown()); @@ -43,8 +39,6 @@ export default class NoteIconWidget extends NoteContextAwareWidget { } this.$iconSearch.val(""); - - this.renderDropdown(); }); } @@ -85,11 +79,8 @@ export default class NoteIconWidget extends NoteContextAwareWidget { ); } - const categoryId = parseInt(String(this.$iconCategory.find("option:selected")?.val())); const search = String(this.$iconSearch.val())?.trim()?.toLowerCase(); - const filteredIcons = icons.filter - if (iconToCount) { filteredIcons.sort((a, b) => { const countA = iconToCount[a.className ?? ""] || 0; diff --git a/apps/client/src/widgets/react/Dropdown.tsx b/apps/client/src/widgets/react/Dropdown.tsx index 1d64d40fd..7fd39c141 100644 --- a/apps/client/src/widgets/react/Dropdown.tsx +++ b/apps/client/src/widgets/react/Dropdown.tsx @@ -1,7 +1,7 @@ import { Dropdown as BootstrapDropdown } from "bootstrap"; import { ComponentChildren } from "preact"; import { CSSProperties } from "preact/compat"; -import { useEffect, useRef } from "preact/hooks"; +import { useCallback, useEffect, useRef, useState } from "preact/hooks"; import { useUniqueName } from "./hooks"; interface DropdownProps { @@ -18,6 +18,8 @@ export default function Dropdown({ className, buttonClassName, isStatic, childre const dropdownRef = useRef(null); const triggerRef = useRef(null); + const [ shown, setShown ] = useState(false); + useEffect(() => { if (!triggerRef.current) return; @@ -25,19 +27,25 @@ export default function Dropdown({ className, buttonClassName, isStatic, childre return () => dropdown.dispose(); }, []); // Add dependency array + const onShown = useCallback(() => { + setShown(true); + }, []) + + const onHidden = useCallback(() => { + setShown(false); + }, []); + useEffect(() => { if (!dropdownRef.current) return; - const handleHide = () => { - // Remove console.log from production code - }; - const $dropdown = $(dropdownRef.current); - $dropdown.on("hide.bs.dropdown", handleHide); + $dropdown.on("show.bs.dropdown", onShown); + $dropdown.on("hide.bs.dropdown", onHidden); // Add proper cleanup return () => { - $dropdown.off("hide.bs.dropdown", handleHide); + $dropdown.off("show.bs.dropdown", onShown); + $dropdown.off("hide.bs.dropdown", onHidden); }; }, []); // Add dependency array @@ -62,7 +70,7 @@ export default function Dropdown({ className, buttonClassName, isStatic, childre style={dropdownContainerStyle} aria-labelledby={ariaId} > - {children} + {shown && children} )