A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: remove pins from settings
Abdullah Attaef552f8b3866
diff --git a/packages/core/__tests__/settings.test.js b/packages/core/__tests__/settings.test.jsindex 9589eacf7..e65ec3413 100644--- a/packages/core/__tests__/settings.test.js+++ b/packages/core/__tests__/settings.test.js@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { databaseTest, notebookTest, StorageInterface } from "./utils";+import { databaseTest, StorageInterface } from "./utils";beforeEach(() => {StorageInterface.clear();@@ -35,7 +35,7 @@ test("settings' dateModified should update after merge conflict resolve", () =>databaseTest().then(async (db) => {await db.storage.write("lastSynced", 0);const beforeDateModified = (db.settings._settings.dateModified = 1);- await db.settings.merge({ pins: [], groupOptions: {}, aliases: {} });+ await db.settings.merge({ groupOptions: {}, aliases: {} });const afterDateModified = db.settings._settings.dateModified;expect(afterDateModified).toBeGreaterThan(beforeDateModified);}));@@ -44,7 +44,6 @@ test("tag alias should update if aliases in settings update", () =>databaseTest().then(async (db) => {const tag = await db.tags.add("hello");await db.settings.merge({- pins: [],groupOptions: {},aliases: {[tag.id]: "hello232"@@ -73,54 +72,3 @@ test("save toolbar config", () =>await db.settings.setToolbarConfig("mobile", toolbarConfig);expect(db.settings.getToolbarConfig("mobile")).toMatchObject(toolbarConfig);}));--test("pinning an invalid item should throw", () =>- databaseTest().then(async (db) => {- await expect(() => db.settings.pin("lolo", {})).rejects.toThrow(- /item cannot be pinned/i- );- }));--test("pin a notebook", () =>- notebookTest().then(async ({ db, id }) => {- await db.settings.pin("notebook", { id });- expect(db.settings.pins).toHaveLength(1);- expect(db.settings.pins[0].id).toBe(id);- }));--test("pin an already pinned notebook", () =>- notebookTest().then(async ({ db, id }) => {- await db.settings.pin("notebook", { id });- await db.settings.pin("notebook", { id });-- expect(db.settings.pins).toHaveLength(1);- expect(db.settings.pins[0].id).toBe(id);- }));--test("pin a topic", () =>- notebookTest().then(async ({ db, id }) => {- const notebook = db.notebooks.notebook(id)._notebook;- const topic = notebook.topics[0];- await db.settings.pin("topic", { id: topic.id, notebookId: id });- expect(db.settings.pins).toHaveLength(1);- expect(db.settings.pins[0].id).toBe(topic.id);- }));--test("pin a tag", () =>- databaseTest().then(async (db) => {- const tag = await db.tags.add("HELLO!");- await db.settings.pin("tag", { id: tag.id });- expect(db.settings.pins).toHaveLength(1);- expect(db.settings.pins[0].id).toBe(tag.id);- }));--test("unpin a pinned item", () =>- databaseTest().then(async (db) => {- const tag = await db.tags.add("HELLO!");- await db.settings.pin("tag", { id: tag.id });- expect(db.settings.pins).toHaveLength(1);- expect(db.settings.pins[0].id).toBe(tag.id);-- await db.settings.unpin(tag.id);- expect(db.settings.pins).toHaveLength(0);- }));diff --git a/packages/core/api/settings.js b/packages/core/api/settings.jsindex 8338788f0..a936166ef 100644--- a/packages/core/api/settings.js+++ b/packages/core/api/settings.js@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { EV, EVENTS } from "../common";import id from "../utils/id";import "../types";-import setManipulator from "../utils/set";class Settings {/**@@ -49,11 +48,6 @@ class Settings {async merge(item) {if (this._settings.dateModified > (await this._db.lastSynced())) {this._settings.id = item.id;- this._settings.pins = setManipulator.union(- this._settings.pins,- item.pins,- (p) => p.data.id- );this._settings.groupOptions = {...this._settings.groupOptions,...item.groupOptions@@ -131,55 +125,10 @@ class Settings {return this._settings.aliases[id];}- async pin(type, data) {- if (type !== "notebook" && type !== "topic" && type !== "tag")- throw new Error("This item cannot be pinned.");- if (this.isPinned(data.id)) return;- this._settings.pins.push({ type, data });-- await this._saveSettings();- }-- async unpin(id) {- const index = this._settings.pins.findIndex((i) => i.data.id === id);- if (index <= -1) return;- this._settings.pins.splice(index, 1);-- await this._saveSettings();- }-- isPinned(id) {- return !!this._settings.pins.find((v) => v.data.id === id);- }-- get pins() {- return this._settings.pins.reduce((prev, pin) => {- if (!pin || !pin.data) return;-- let item = null;- if (pin.type === "notebook") {- const notebook = this._db.notebooks.notebook(pin.data.id);- item = notebook ? notebook.data : null;- } else if (pin.type === "topic") {- const notebook = this._db.notebooks.notebook(pin.data.notebookId);- if (notebook) {- const topic = notebook.topics.topic(pin.data.id);- if (topic) item = topic._topic;- }- } else if (pin.type === "tag") {- item = this._db.tags.tag(pin.data.id);- }- if (item) prev.push(item);- else this.unpin(pin.data.id); // TODO risky.- return prev;- }, []);- }-_initSettings(settings) {this._settings = {type: "settings",id: id(),- pins: [],groupOptions: {},toolbarConfig: {},aliases: {},