Skip to content

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

fix: disable immer and fix trash restore and delete

thecodrrf19fd25f8461
diff --git a/apps/web/src/common/store.js b/apps/web/src/common/store.js
index 66b3f477e..27213323d 100644
--- a/apps/web/src/common/store.js
+++ b/apps/web/src/common/store.js
@@ -1,28 +1,28 @@
import produce, { immerable } from "immer";
import create from "zustand";
-function immer(config) {
- return function(set, get, api) {
- const obj = config(
- fn =>
- set(() =>
- produce(get(), state => {
- fn(state);
- })
- ),
- get,
- api
- );
- obj[immerable] = true;
- return obj;
- };
-}
+// function immer(config) {
+// return function (set, get, api) {
+// const obj = config(
+// (fn) =>
+// set(() =>
+// produce(get(), (state) => {
+// fn(state);
+// })
+// ),
+// get,
+// api
+// );
+// obj[immerable] = true;
+// return obj;
+// };
+// }
/**
* @returns {[import("zustand").UseStore<any>, any]}
*/
function createStore(store) {
- const [useStore, api] = create(immer(store.new.bind(store)));
+ const [useStore, api] = create(store.new.bind(store));
return [useStore, api.getState()];
}
diff --git a/apps/web/src/common/toasts.js b/apps/web/src/common/toasts.js
index dd0cea632..d1f0786c2 100644
--- a/apps/web/src/common/toasts.js
+++ b/apps/web/src/common/toasts.js
@@ -55,17 +55,15 @@ function showItemDeletedToast(item) {
var toast = showToast("success", messageText, actions);
}
-async function showPermanentDeleteToast(item, index) {
- const noun = item.type === "note" ? "Note" : "Notebook";
+async function showPermanentDeleteToast(item) {
+ const noun = item.itemType === "note" ? "Note" : "Notebook";
const messageText = `${noun} permanently deleted!`;
const timeoutId = setTimeout(() => {
- trashstore.delete(item.id, index, true);
+ trashstore.delete(item.id, true);
}, 5000);
const undoAction = async () => {
toast.hide();
- trashstore.set((state) => {
- state.trash.splice(index, 0, item);
- });
+ trashstore.refresh();
clearTimeout(timeoutId);
};
let actions = [{ text: "Undo", onClick: undoAction }];
diff --git a/apps/web/src/components/trash-item/index.js b/apps/web/src/components/trash-item/index.js
index 4d04949ee..c9e29c66b 100644
--- a/apps/web/src/components/trash-item/index.js
+++ b/apps/web/src/components/trash-item/index.js
@@ -17,7 +17,9 @@ function menuItems(item, index) {
store.restore(item.id, index);
showToast(
"success",
- `${item.type === "note" ? "Note" : "Notebook"} restored successfully!`
+ `${
+ item.itemType === "note" ? "Note" : "Notebook"
+ } restored successfully!`
);
},
},
@@ -44,7 +46,7 @@ function menuItems(item, index) {
),
}).then(async (res) => {
if (res) {
- await store.delete(item.id, index);
+ await store.delete(item.id);
showPermanentDeleteToast(item, index);
}
});
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 14ba9f899..7f07b1fc9 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -65,7 +65,7 @@ class EditorStore extends BaseStore {
let note = db.notes.note(noteId);
if (!note) return;
- note = qclone(note.data);
+ note = note.data;
noteStore.setSelectedNote(note.id);
diff --git a/apps/web/src/stores/trash-store.js b/apps/web/src/stores/trash-store.js
index f266dca17..cb1086f07 100644
--- a/apps/web/src/stores/trash-store.js
+++ b/apps/web/src/stores/trash-store.js
@@ -10,18 +10,16 @@ class TrashStore extends BaseStore {
this.set((state) => (state.trash = db.trash.all));
};
- delete = (id, index, commit = false) => {
+ delete = (id, commit = false) => {
if (!commit) {
- return this.set((state) => {
- state.trash.splice(index, 1);
- });
+ return this.set((state) => (state.trash = db.trash.all));
}
return db.trash.delete(id);
};
- restore = (id, index) => {
+ restore = (id) => {
return db.trash.restore(id).then(() => {
- this.set((state) => state.trash.splice(index, 1));
+ this.set((state) => (state.trash = db.trash.all));
appStore.refreshColors();
});
};