diff --git a/apps/client/src/widgets/note_icon.ts.bak b/apps/client/src/widgets/note_icon.ts.bak index 50a846bc3..8418405ff 100644 --- a/apps/client/src/widgets/note_icon.ts.bak +++ b/apps/client/src/widgets/note_icon.ts.bak @@ -88,19 +88,7 @@ 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((icon) => { - if (categoryId && icon.category_id !== categoryId) { - return false; - } - - if (search) { - if (!icon.name.includes(search) && !icon.term?.find((t) => t.includes(search))) { - return false; - } - } - - return true; - }); + const filteredIcons = icons.filter if (iconToCount) { filteredIcons.sort((a, b) => { diff --git a/apps/client/src/widgets/note_icon.tsx b/apps/client/src/widgets/note_icon.tsx index 7d11bf341..c37064355 100644 --- a/apps/client/src/widgets/note_icon.tsx +++ b/apps/client/src/widgets/note_icon.tsx @@ -48,7 +48,8 @@ export default function NoteIcon() { } function NoteIconList() { - const [ filter, setFilter ] = useState(); + const [ search, setSearch ] = useState(); + const [ categoryId, setCategoryId ] = useState(); const [ iconData, setIconData ] = useState(); useEffect(() => { @@ -58,14 +59,31 @@ function NoteIconList() { fullIconData = (await import("./icon_list.js")).default; } + let icons: Icon[] = fullIconData.icons; + if (search || categoryId) { + icons = icons.filter((icon) => { + if (categoryId && icon.category_id !== categoryId) { + return false; + } + + if (search) { + if (!icon.name.includes(search) && !icon.term?.find((t) => t.includes(search))) { + return false; + } + } + + return true; + }); + } + setIconData({ iconToCount, - icons: fullIconData.icons + icons }) } loadIcons(); - }, []); + }, [ search, categoryId ]); return ( <> @@ -76,7 +94,7 @@ function NoteIconList() {