mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
fix: make tag aliases syncable
This commit is contained in:
@@ -76,7 +76,7 @@ describe.each([
|
||||
let tag = db[collection].tag(value);
|
||||
await db[collection].rename(tag.id, value + "-new");
|
||||
tag = db[collection].tag(tag.id);
|
||||
expect(tag.alias).toBe(value + "-new");
|
||||
expect(db[collection].alias(tag.id)).toBe(value + "-new");
|
||||
}));
|
||||
|
||||
test(`remove a ${action}`, () =>
|
||||
|
||||
@@ -37,6 +37,7 @@ class Settings {
|
||||
...item.groupOptions,
|
||||
...this._settings.groupOptions,
|
||||
};
|
||||
this._settings.aliases = {};
|
||||
} else {
|
||||
this._initSettings(item);
|
||||
}
|
||||
@@ -68,6 +69,15 @@ class Settings {
|
||||
);
|
||||
}
|
||||
|
||||
async setAlias(id, name) {
|
||||
this._settings.aliases[id] = name;
|
||||
await this._saveSettings();
|
||||
}
|
||||
|
||||
getAlias(id) {
|
||||
return this._settings.aliases[id];
|
||||
}
|
||||
|
||||
async pin(type, data) {
|
||||
if (type !== "notebook" && type !== "topic" && type !== "tag")
|
||||
throw new Error("This item cannot be pinned.");
|
||||
@@ -120,6 +130,7 @@ class Settings {
|
||||
id: id(),
|
||||
pins: [],
|
||||
groupOptions: {},
|
||||
aliases: {},
|
||||
dateEdited: 0,
|
||||
dateCreated: 0,
|
||||
...(settings || {}),
|
||||
|
||||
@@ -19,18 +19,18 @@ export default class Tags extends Collection {
|
||||
title: tagId,
|
||||
};
|
||||
|
||||
let id = tag.id || makeId(tag.title);
|
||||
let id = tag.id || makeId(tag.title.toLowerCase());
|
||||
let notes = tag.noteIds || [];
|
||||
|
||||
tag = {
|
||||
type: "tag",
|
||||
alias: tag.title,
|
||||
id,
|
||||
title: tag.title,
|
||||
noteIds: setManipulator.union(notes, noteIds),
|
||||
};
|
||||
|
||||
await this._collection.addItem(tag);
|
||||
await this._db.settings.setAlias(tag.id, tag.title);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,17 @@ export default class Tags extends Collection {
|
||||
console.error(`No tag found. Tag id:`, tagId);
|
||||
return;
|
||||
}
|
||||
tag.alias = newName;
|
||||
await this._collection.updateItem(tag);
|
||||
await this._db.settings.setAlias(tagId, newName);
|
||||
}
|
||||
|
||||
alias(tagId) {
|
||||
let tag = this.tag(tagId);
|
||||
if (!tag) {
|
||||
console.error(`No tag found. Tag id:`, tagId);
|
||||
return;
|
||||
}
|
||||
const alias = this._db.settings.getAlias(tagId);
|
||||
return alias || tag.alias || tag.title;
|
||||
}
|
||||
|
||||
get raw() {
|
||||
|
||||
Reference in New Issue
Block a user