mirror of
https://github.com/zadam/trilium.git
synced 2025-10-26 07:46:30 +01:00
chore(react/note_icon): add back filter by text
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -48,7 +48,8 @@ export default function NoteIcon() {
|
||||
}
|
||||
|
||||
function NoteIconList() {
|
||||
const [ filter, setFilter ] = useState<string>();
|
||||
const [ search, setSearch ] = useState<string>();
|
||||
const [ categoryId, setCategoryId ] = useState<number>();
|
||||
const [ iconData, setIconData ] = useState<IconData>();
|
||||
|
||||
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() {
|
||||
<FormTextBox
|
||||
type="text"
|
||||
name="icon-search"
|
||||
currentValue={filter} onChange={setFilter}
|
||||
currentValue={search} onChange={setSearch}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user