mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 14:39:34 +01:00
fix: attach alias with tag for sorting/grouping
This commit is contained in:
@@ -6,7 +6,9 @@ import setManipulator from "../utils/set";
|
|||||||
|
|
||||||
export default class Tags extends Collection {
|
export default class Tags extends Collection {
|
||||||
tag(id) {
|
tag(id) {
|
||||||
const tagItem = this.all.find((t) => t.id === id || t.title === id);
|
const tagItem = this._collection
|
||||||
|
.getItems()
|
||||||
|
.find((t) => t.id === id || t.title === id);
|
||||||
return tagItem;
|
return tagItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +65,11 @@ export default class Tags extends Collection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get all() {
|
get all() {
|
||||||
return this._collection.getItems();
|
return this._collection.getItems(undefined, (item) => {
|
||||||
|
const alias = this.alias(item.id);
|
||||||
|
if (alias) item.alias = alias;
|
||||||
|
return item;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(tagId) {
|
async remove(tagId) {
|
||||||
|
|||||||
@@ -47,11 +47,12 @@ export default class CachedCollection extends IndexedCollection {
|
|||||||
return Array.from(this.map.values());
|
return Array.from(this.map.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
getItems(sortFn = (u) => u.dateCreated) {
|
getItems(sortFn = (u) => u.dateCreated, manipulate = (item) => item) {
|
||||||
let items = [];
|
let items = [];
|
||||||
this.map.forEach((value) => {
|
this.map.forEach((value) => {
|
||||||
if (!value || value.deleted || !value.id) return;
|
if (!value || value.deleted || !value.id) return;
|
||||||
items[items.length] = value;
|
value = manipulate ? manipulate(value) : value;
|
||||||
|
items.push(value);
|
||||||
});
|
});
|
||||||
return sort(items).desc(sortFn);
|
return sort(items).desc(sortFn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,14 +13,15 @@ const getSortSelectors = (options) => [
|
|||||||
{ desc: (t) => t.pinned },
|
{ desc: (t) => t.pinned },
|
||||||
{
|
{
|
||||||
[options.sortDirection]: (item) => {
|
[options.sortDirection]: (item) => {
|
||||||
if (options.sortBy === "title") return getFirstCharacter(item);
|
if (options.sortBy === "title")
|
||||||
|
return getFirstCharacter(item.alias || item.title);
|
||||||
return item[options.sortBy];
|
return item[options.sortBy];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const KEY_SELECTORS = {
|
const KEY_SELECTORS = {
|
||||||
abc: (item) => getFirstCharacter(item),
|
abc: (item) => getFirstCharacter(item.alias || item.title),
|
||||||
month: (item, groupBy) => dayjs(item[groupBy]).format("MMMM"),
|
month: (item, groupBy) => dayjs(item[groupBy]).format("MMMM"),
|
||||||
week: (item, groupBy) => getWeekGroupFromTimestamp(item[groupBy]),
|
week: (item, groupBy) => getWeekGroupFromTimestamp(item[groupBy]),
|
||||||
year: (item, groupBy) => dayjs(item[groupBy]).year(),
|
year: (item, groupBy) => dayjs(item[groupBy]).year(),
|
||||||
@@ -73,8 +74,9 @@ export function groupArray(
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFirstCharacter(item) {
|
function getFirstCharacter(str) {
|
||||||
const title = item.title && item.title.trim();
|
if (!str) return "-";
|
||||||
if (!title || title.length <= 0) return "-";
|
str = str.trim();
|
||||||
return title[0].toUpperCase();
|
if (str.length <= 0) return "-";
|
||||||
|
return str[0].toUpperCase();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user