Compare commits

...

2 Commits

Author SHA1 Message Date
Ammar Ahmed
f32ef8a49a mobile: test 2024-11-06 13:51:44 +05:00
01zulfi
606df2b851 web: fix restore notebooks over limit for free users (#6812)
Signed-off-by: Zulfiqar Ali <85733202+01zulfi@users.noreply.github.com>
2024-11-06 13:37:46 +05:00
6 changed files with 27 additions and 5 deletions

View File

@@ -40,7 +40,8 @@ function showItemDeletedToast(item) {
toast.hide();
let trashItem = db.trash.all.find((i) => i.id === item.id);
if (!trashItem) return;
await db.trash.restore(trashItem.id);
const restored = await db.trash.restore(trashItem.id);
if (restored === false) return;
nbstore.refresh();
notestore.refresh();
};

View File

@@ -83,7 +83,6 @@ const menuItems: (item: TrashItemType, ids?: string[]) => MenuItem[] = (
icon: Restore.path,
onClick: async () => {
await store.restore(...ids);
showToast("success", strings.action("item", ids.length, "restored"));
},
multiSelect: true
},

View File

@@ -24,6 +24,8 @@ import { store as appStore } from "./app-store";
import { store as noteStore } from "./note-store";
import { store as notebookStore } from "./notebook-store";
import { TrashItem, VirtualizedGrouping } from "@notesnook/core";
import { showToast } from "../utils/toast";
import { strings } from "@notesnook/intl";
class TrashStore extends BaseStore<TrashStore> {
trash: VirtualizedGrouping<TrashItem> | undefined = undefined;
@@ -41,7 +43,9 @@ class TrashStore extends BaseStore<TrashStore> {
};
restore = async (...ids: string[]) => {
await db.trash.restore(...ids);
const restored = await db.trash.restore(...ids);
if (restored === false) return;
showToast("success", strings.action("item", ids.length, "restored"));
await this.get().refresh();
await appStore.refreshNavItems();
await noteStore.refresh();

View File

@@ -25,7 +25,11 @@ import { SQLCollection } from "../database/sql-collection.js";
import { isFalse } from "../database/index.js";
import { sql } from "@streetwriters/kysely";
import { deleteItems } from "../utils/array.js";
import { CHECK_IDS, checkIsUserPremium } from "../common.js";
import {
CHECK_IDS,
checkIsUserPremium,
FREE_NOTEBOOKS_LIMIT
} from "../common.js";
export class Notebooks implements ICollection {
name = "notebooks";
@@ -62,7 +66,7 @@ export class Notebooks implements ICollection {
if (
!oldNotebook &&
(await this.all.count()) >= 20 &&
(await this.all.count()) >= FREE_NOTEBOOKS_LIMIT &&
!(await checkIsUserPremium(CHECK_IDS.notebookAdd))
)
return;

View File

@@ -29,6 +29,11 @@ import {
} from "../utils/grouping.js";
import { sql } from "@streetwriters/kysely";
import { MAX_SQL_PARAMETERS } from "../database/sql-collection.js";
import {
CHECK_IDS,
checkIsUserPremium,
FREE_NOTEBOOKS_LIMIT
} from "../common.js";
export default class Trash {
collections = ["notes", "notebooks"] as const;
@@ -192,6 +197,13 @@ export default class Trash {
}
if (notebookIds.length > 0) {
const notebooksLimitReached =
(await this.db.notebooks.all.count()) + notebookIds.length >
FREE_NOTEBOOKS_LIMIT;
const isUserPremium = await checkIsUserPremium(CHECK_IDS.notebookAdd);
if (notebooksLimitReached && !isUserPremium) {
return false;
}
const ids = [...notebookIds, ...(await this.subNotebooks(notebookIds))];
await this.db.notebooks.collection.update(ids, {
type: "notebook",

View File

@@ -142,3 +142,5 @@ export const DATE_FORMATS = [
export const TIME_FORMATS = ["12-hour", "24-hour"];
export const CURRENT_DATABASE_VERSION = 6.1;
export const FREE_NOTEBOOKS_LIMIT = 20;