mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 03:59:05 +01:00
chore(react/note_icon): sort by count
This commit is contained in:
parent
ef018e22d6
commit
b20ffdf7db
@ -25,21 +25,6 @@ export default class NoteIconWidget extends NoteContextAwareWidget {
|
||||
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) {
|
||||
@ -81,19 +66,6 @@ export default class NoteIconWidget extends NoteContextAwareWidget {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@ -56,11 +56,11 @@ function NoteIconList() {
|
||||
|
||||
useEffect(() => {
|
||||
async function loadIcons() {
|
||||
const iconToCount = await getIconToCountMap();
|
||||
if (!fullIconData) {
|
||||
fullIconData = (await import("./icon_list.js")).default;
|
||||
}
|
||||
|
||||
// Filter by text and/or category.
|
||||
let icons: Icon[] = fullIconData.icons;
|
||||
if (search || categoryId) {
|
||||
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({
|
||||
iconToCount,
|
||||
icons,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user