feat: add isPinned method in settings

This commit is contained in:
thecodrr
2020-11-25 20:52:54 +05:00
parent 3733ad8904
commit fe5eb08079

View File

@@ -16,6 +16,7 @@ class Settings {
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.");
if (this.isPinned(data.id)) return;
this._settings.pins.push({ type, data }); this._settings.pins.push({ type, data });
await this._db.context.write("settings", this._settings); await this._db.context.write("settings", this._settings);
} }
@@ -27,6 +28,10 @@ class Settings {
await this._db.context.write("settings", this._settings); await this._db.context.write("settings", this._settings);
} }
isPinned(id) {
return this.Settings.pins.findIndex((v) => v.data.id === id) > -1;
}
get pins() { get pins() {
return this._settings.pins.map((pin) => { return this._settings.pins.map((pin) => {
if (pin.type === "notebook") { if (pin.type === "notebook") {