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