chore(react/note_icon): sort by count

This commit is contained in:
Elian Doran 2025-08-21 15:05:55 +03:00
parent ef018e22d6
commit b20ffdf7db
No known key found for this signature in database
2 changed files with 12 additions and 29 deletions

View File

@ -25,21 +25,6 @@ export default class NoteIconWidget extends NoteContextAwareWidget {
await attributeService.setLabel(this.noteId, this.note.hasOwnedLabel("workspace") ? "workspaceIconClass" : "iconClass", clazz); await attributeService.setLabel(this.noteId, this.note.hasOwnedLabel("workspace") ? "workspaceIconClass" : "iconClass", clazz);
} }
}); });
this.$iconSearch = this.$widget.find("input[name='icon-search']");
this.$iconSearch.on("input", () => this.renderDropdown());
this.$widget.on("show.bs.dropdown", async () => {
const { categories } = (await import("./icon_list.js")).default;
this.$iconCategory.empty();
for (const category of categories) {
this.$iconCategory.append($("<option>").text(category.name).attr("value", category.id));
}
this.$iconSearch.val("");
});
} }
async refreshWithNote(note: FNote) { async refreshWithNote(note: FNote) {
@ -81,19 +66,6 @@ export default class NoteIconWidget extends NoteContextAwareWidget {
const search = String(this.$iconSearch.val())?.trim()?.toLowerCase(); const search = String(this.$iconSearch.val())?.trim()?.toLowerCase();
if (iconToCount) {
filteredIcons.sort((a, b) => {
const countA = iconToCount[a.className ?? ""] || 0;
const countB = iconToCount[b.className ?? ""] || 0;
return countB - countA;
});
}
for (const icon of filteredIcons) {
this.$iconList.append(this.renderIcon(icon));
}
this.$iconSearch.focus(); this.$iconSearch.focus();
} }

View File

@ -56,11 +56,11 @@ function NoteIconList() {
useEffect(() => { useEffect(() => {
async function loadIcons() { async function loadIcons() {
const iconToCount = await getIconToCountMap();
if (!fullIconData) { if (!fullIconData) {
fullIconData = (await import("./icon_list.js")).default; fullIconData = (await import("./icon_list.js")).default;
} }
// Filter by text and/or category.
let icons: Icon[] = fullIconData.icons; let icons: Icon[] = fullIconData.icons;
if (search || categoryId) { if (search || categoryId) {
icons = icons.filter((icon) => { icons = icons.filter((icon) => {
@ -78,6 +78,17 @@ function NoteIconList() {
}); });
} }
// Sort by count.
const iconToCount = await getIconToCountMap();
if (iconToCount) {
icons.sort((a, b) => {
const countA = iconToCount[a.className ?? ""] || 0;
const countB = iconToCount[b.className ?? ""] || 0;
return countB - countA;
});
}
setIconData({ setIconData({
iconToCount, iconToCount,
icons, icons,