mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 22:35:50 +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 categoryId = parseInt(String(this.$iconCategory.find("option:selected")?.val()));
|
||||||
const search = String(this.$iconSearch.val())?.trim()?.toLowerCase();
|
const search = String(this.$iconSearch.val())?.trim()?.toLowerCase();
|
||||||
|
|
||||||
const filteredIcons = icons.filter((icon) => {
|
const filteredIcons = icons.filter
|
||||||
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (iconToCount) {
|
if (iconToCount) {
|
||||||
filteredIcons.sort((a, b) => {
|
filteredIcons.sort((a, b) => {
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ export default function NoteIcon() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function NoteIconList() {
|
function NoteIconList() {
|
||||||
const [ filter, setFilter ] = useState<string>();
|
const [ search, setSearch ] = useState<string>();
|
||||||
|
const [ categoryId, setCategoryId ] = useState<number>();
|
||||||
const [ iconData, setIconData ] = useState<IconData>();
|
const [ iconData, setIconData ] = useState<IconData>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -58,14 +59,31 @@ function NoteIconList() {
|
|||||||
fullIconData = (await import("./icon_list.js")).default;
|
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({
|
setIconData({
|
||||||
iconToCount,
|
iconToCount,
|
||||||
icons: fullIconData.icons
|
icons
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
loadIcons();
|
loadIcons();
|
||||||
}, []);
|
}, [ search, categoryId ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -76,7 +94,7 @@ function NoteIconList() {
|
|||||||
<FormTextBox
|
<FormTextBox
|
||||||
type="text"
|
type="text"
|
||||||
name="icon-search"
|
name="icon-search"
|
||||||
currentValue={filter} onChange={setFilter}
|
currentValue={search} onChange={setSearch}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user