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
fix: duplicate notes being created
thecodrr558d9406fea6
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex 9b43cac8c..e9a076146 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -23,9 +23,9 @@ const DEFAULT_SESSION = {content: {text: "",delta: {- ops: []- }- }+ ops: [],+ },+ },};class EditorStore extends BaseStore {session = DEFAULT_SESSION;@@ -36,72 +36,72 @@ class EditorStore extends BaseStore {this.openSession(db.notes.note(id).data);};- openSession = async note => {- clearTimeout(this.session.timeout);+ openSession = async (note) => {+ clearTimeout(this.get().session.timeout);let content = {};if (!note.locked) {content = {text: note.content.text,- delta: await db.notes.note(note).delta()+ delta: await db.notes.note(note).delta(),};} else {content = await Vault.openNote(note.id);if (!content) return;}- this.set(state => {+ this.set((state) => {state.session = {...DEFAULT_SESSION,...note,- content+ content,};});noteStore.setSelectedNote(note.id);};- saveSession = oldSession => {- this.set(state => (state.session.isSaving = true));- this._saveFn(this.session.locked)(this.session).then(id => {+ saveSession = (oldSession) => {+ this.set((state) => (state.session.isSaving = true));+ this._saveFn()(this.get().session).then((id) => {if (!oldSession) {- if (oldSession.tags.length !== this.session.tags.length)+ if (oldSession.tags.length !== this.get().session.tags.length)tagStore.refresh();- if (oldSession.colors.length !== this.session.colors.length)+ if (oldSession.colors.length !== this.get().session.colors.length)appStore.refreshColors();}- if (!this.session.id) {+ if (!this.get().session.id) {noteStore.setSelectedNote(id);}- this.set(state => {+ this.set((state) => {state.session.id = id;state.session.isSaving = false;});noteStore.refresh();- saveLastOpenedNote(!this.session.locked && id);+ saveLastOpenedNote(!this.get().session.locked && id);});};newSession = (context = {}) => {- clearTimeout(this.session.timeout);- this.set(function(state) {+ clearTimeout(this.get().session.timeout);+ this.set(function (state) {state.session = {...DEFAULT_SESSION,- ...context+ ...context,};});saveLastOpenedNote();noteStore.setSelectedNote(0);};- setSession = set => {- clearTimeout(this.session.timeout);- const oldSession = { ...this.session };- this.set(state => {+ setSession = (set) => {+ clearTimeout(this.get().session.timeout);+ const oldSession = { ...this.get().session };+ this.set((state) => {state.session.state = SESSION_STATES.stale;set(state);@@ -113,15 +113,15 @@ class EditorStore extends BaseStore {};toggleLocked = () => {- if (this.session.locked) noteStore.unlock(this.session.id);- else noteStore.lock(this.session.id);+ if (this.get().session.locked) noteStore.unlock(this.get().session.id);+ else noteStore.lock(this.get().session.id);};- setColor = color => {+ setColor = (color) => {this._setTagOrColor("color", color);};- setTag = tag => {+ setTag = (tag) => {this._setTagOrColor("tag", tag);};@@ -130,15 +130,15 @@ class EditorStore extends BaseStore {* @param {Boolean} isLocked* @returns {(note: any) => Promise<string>}*/- _saveFn(isLocked) {- return isLocked+ _saveFn = () => {+ return this.get().session.locked? db.vault.save.bind(db.vault): db.notes.add.bind(db.notes);- }+ };_setTagOrColor(key, value) {const array = key === "tag" ? "tags" : "colors";- const { [array]: arr, id } = this.session;+ const { [array]: arr, id } = this.get().session;let note = db.notes.note(id);if (!note) return;@@ -146,11 +146,11 @@ class EditorStore extends BaseStore {let index = arr.indexOf(value);if (index > -1) {note[`un${key}`](value).then(() => {- this.set(state => state.session[array].splice(index, 1));+ this.set((state) => state.session[array].splice(index, 1));});} else {note[key](value).then(() => {- this.set(state => state.session[array].push(value));+ this.set((state) => state.session[array].push(value));});}}