mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 12:12:54 +01:00
fix: disable immer and fix trash restore and delete
This commit is contained in:
@@ -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()];
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user