Skip to content

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

web: add limit on notebook restoration

Abdullah Atta1a2a1da0866e
diff --git a/apps/web/src/common/multi-select.ts b/apps/web/src/common/multi-select.ts
index 38d4deef7..f816aa34a 100644
--- a/apps/web/src/common/multi-select.ts
+++ b/apps/web/src/common/multi-select.ts
@@ -34,6 +34,8 @@ import {
showMultiPermanentDeleteConfirmation
} from "../dialogs/confirm";
import { strings } from "@notesnook/intl";
+import { isFeatureAvailable } from "@notesnook/common";
+import { showFeatureNotAllowedToast } from "./toasts";
async function moveNotesToTrash(ids: string[], confirm = true) {
if (confirm && !(await showMultiDeleteConfirmation(ids.length))) return;
@@ -183,6 +185,13 @@ async function deleteTags(ids: string[]) {
async function restoreItemsFromTrash(ids: string[]) {
if (!ids.length) return;
+ const notebookIds = ids.filter((id) => db.trash.cache.notebooks.includes(id));
+ const result = await isFeatureAvailable(
+ "notebooks",
+ (await db.notebooks.all.count()) + notebookIds.length
+ );
+ if (!result.isAllowed) return showFeatureNotAllowedToast(result);
+
await TaskManager.startTask({
type: "status",
id: "restoreItems",
diff --git a/apps/web/src/stores/trash-store.ts b/apps/web/src/stores/trash-store.ts
index 22dcdaacd..1a805dc62 100644
--- a/apps/web/src/stores/trash-store.ts
+++ b/apps/web/src/stores/trash-store.ts
@@ -43,8 +43,7 @@ class TrashStore extends BaseStore<TrashStore> {
};
restore = async (...ids: string[]) => {
- const restored = await db.trash.restore(...ids);
- if (restored === false) return;
+ await db.trash.restore(...ids);
showToast("success", strings.actions.restored.item(ids.length));
await this.get().refresh();
await appStore.refreshNavItems();