Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: resolve potential zustand store related bugs

thecodrr49bdd1a836c5
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index 023cb176e..ced87a3a9 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -21,15 +21,15 @@ class AppStore extends BaseStore {
};
refreshColors = () => {
- this.set(state => (state.colors = db.colors.all));
+ this.set((state) => (state.colors = db.colors.all));
};
toggleFocusMode = () => {
- this.set(state => (state.isFocusMode = !state.isFocusMode));
+ this.set((state) => (state.isFocusMode = !state.isFocusMode));
};
toggleSideMenu = () => {
- this.set(state => (state.isSideMenuOpen = !state.isSideMenuOpen));
+ this.set((state) => (state.isSideMenuOpen = !state.isSideMenuOpen));
};
}
diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.js
index 310c0984d..362dc4204 100644
--- a/apps/web/src/stores/note-store.js
+++ b/apps/web/src/stores/note-store.js
@@ -8,26 +8,26 @@ class NoteStore extends BaseStore {
notes = {
items: [],
groupCounts: [],
- groups: []
+ groups: [],
};
context = undefined;
selectedNote = 0;
- setSelectedNote = id => {
- this.set(state => (state.selectedNote = id));
+ setSelectedNote = (id) => {
+ this.set((state) => (state.selectedNote = id));
};
refresh = () => {
- if (this.context) this.refreshContext();
- else this.set(state => (state.notes = db.notes.group(undefined, true)));
+ if (this.get().context) this.refreshContext();
+ else this.set((state) => (state.notes = db.notes.group(undefined, true)));
};
refreshContext = () => {
- if (!this.context) return;
+ if (!this.get().context) return;
this.setContext(this.context);
};
- setContext = context => {
+ setContext = (context) => {
let notes = [];
switch (context.type) {
case "tag":
@@ -47,35 +47,35 @@ class NoteStore extends BaseStore {
default:
return;
}
- this.set(state => (state.context = { ...context, notes }));
+ this.set((state) => (state.context = { ...context, notes }));
};
- delete = async id => {
+ delete = async (id) => {
await db.notes.delete(id);
this.refreshContext();
this.refresh();
- const { session, newSession } = editorStore;
+ const { session, newSession } = editorStore.get();
if (session.id === id) {
newSession();
}
};
- pin = async note => {
+ pin = async (note) => {
await db.notes.note(note).pin();
this.refresh();
this._syncEditor(note.id, "pinned");
};
- favorite = async note => {
+ favorite = async (note) => {
await db.notes.note(note).favorite();
this._setValue(note.id, "favorite", !note.favorite);
};
- unlock = id => {
+ unlock = (id) => {
Vault.unlockNote(id, () => this._setValue(id, "locked", false));
};
- lock = id => {
+ lock = (id) => {
Vault.lockNote(id, () => this._setValue(id, "locked", true));
};
@@ -83,10 +83,10 @@ class NoteStore extends BaseStore {
* @private
*/
_setValue = (noteId, prop, value) => {
- this.set(state => {
+ this.set((state) => {
const { context, notes } = state;
const arr = !context ? notes.items : context.notes;
- let index = arr.findIndex(note => note.id === noteId);
+ let index = arr.findIndex((note) => note.id === noteId);
if (index < 0) return;
arr[index][prop] = value;
@@ -98,9 +98,9 @@ class NoteStore extends BaseStore {
* @private
*/
_syncEditor = (noteId, action) => {
- const { session, setSession } = editorStore;
+ const { session, setSession } = editorStore.get();
if (session.id === noteId) {
- setSession(state => (state.session[action] = !state.session[action]));
+ setSession((state) => (state.session[action] = !state.session[action]));
}
};
}
diff --git a/apps/web/src/stores/selection-store.js b/apps/web/src/stores/selection-store.js
index 221b1e734..4bedaef05 100644
--- a/apps/web/src/stores/selection-store.js
+++ b/apps/web/src/stores/selection-store.js
@@ -6,8 +6,8 @@ class SelectionStore extends BaseStore {
shouldSelectAll = false;
isSelectionMode = false;
- toggleSelectionMode = toggleState => {
- this.set(state => {
+ toggleSelectionMode = (toggleState) => {
+ this.set((state) => {
const isSelectionMode =
toggleState !== undefined ? toggleState : !state.isSelectionMode;
state.isSelectionMode = isSelectionMode;
@@ -16,27 +16,27 @@ class SelectionStore extends BaseStore {
});
};
- selectItem = item => {
- const index = this.selectedItems.findIndex(v => item.id === v.id);
- this.set(state => {
+ selectItem = (item) => {
+ const index = this.get().selectedItems.findIndex((v) => item.id === v.id);
+ this.set((state) => {
if (index >= 0) {
state.selectedItems.splice(index, 1);
} else {
state.selectedItems.push(item);
}
});
- if (this.selectedItems.length <= 0) {
+ if (this.get().selectedItems.length <= 0) {
this.toggleSelectionMode();
}
};
setSelectedItems(items) {
- this.set(state => (state.selectedItems = items));
+ this.set((state) => (state.selectedItems = items));
}
selectAll() {
- if (!this.isSelectionMode) return;
- this.set(state => (state.shouldSelectAll = true));
+ if (!this.get().isSelectionMode) return;
+ this.set((state) => (state.shouldSelectAll = true));
}
}