A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: add clear trash option in Trash properties
Ammar Ahmedcb5a7904d38f
diff --git a/apps/mobile/app/components/sheets/menu-item-properties/index.tsx b/apps/mobile/app/components/sheets/menu-item-properties/index.tsxindex 88c73678a..5d73269a8 100644--- a/apps/mobile/app/components/sheets/menu-item-properties/index.tsx+++ b/apps/mobile/app/components/sheets/menu-item-properties/index.tsx@@ -28,7 +28,7 @@ import {ToastManager} from "../../../services/event-manager";import SettingsService from "../../../services/settings";-import { eCloseSheet } from "../../../utils/events";+import { eAfterSync, eCloseSheet } from "../../../utils/events";import { SideMenuItem } from "../../../utils/menu-items";import { AppFontSize } from "../../../utils/size";import { DefaultAppStyles } from "../../../utils/styles";@@ -37,12 +37,17 @@ import AppIcon from "../../ui/AppIcon";import { Pressable } from "../../ui/pressable";import Paragraph from "../../ui/typography/paragraph";import PaywallSheet from "../paywall";+import { presentDialog } from "../../dialog/functions";+import { db } from "../../../common/database";+import { useTrashStore } from "../../../stores/use-trash-store";export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {const { colors } = useThemeColors();const featuresAvailable = useAreFeaturesAvailable(["customHomepage","customizableSidebar"]);+ const trash = useTrashStore((state) => state.items);+return !featuresAvailable ? null : (<Viewstyle={{@@ -100,7 +105,37 @@ export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {},icon: "sort-ascending",locked: !featuresAvailable?.customizableSidebar.isAllowed- }+ },+ ...(item.id === "Trash"+ ? [+ {+ title: strings.clearTrash(),+ onPress: async () => {+ if (!trash || trash?.length === 0) return;+ eSendEvent(eCloseSheet);+ setTimeout(() => {+ presentDialog({+ title: strings.clearTrashConfirm(),+ paragraph: strings.clearTrashDesc(),+ positiveText: strings.clear(),+ positivePress: async () => {+ await db.trash.clear();+ useTrashStore.getState().clear();+ eSendEvent(eAfterSync);+ ToastManager.show({+ message: strings.trashCleared(),+ type: "success"+ });+ return true;+ }+ });+ }, 500);+ },+ icon: "delete-sweep-outline",+ disabled: !trash || trash?.length === 0+ }+ ]+ : [])].map((item) => (<Pressablekey={item.title}@@ -112,7 +147,7 @@ export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {gap: DefaultAppStyles.GAP_SMALL,borderRadius: 0,paddingHorizontal: DefaultAppStyles.GAP,- opacity: item.locked ? 0.6 : 1+ opacity: item.disabled || item.locked ? 0.6 : 1}}onPress={() => {item.onPress();diff --git a/apps/mobile/app/hooks/use-actions.tsx b/apps/mobile/app/hooks/use-actions.tsxindex 25e6c0afa..fb24369d0 100644--- a/apps/mobile/app/hooks/use-actions.tsx+++ b/apps/mobile/app/hooks/use-actions.tsx@@ -382,6 +382,16 @@ export const useActions = ({}const deleteItem = async () => {+ if (isPublished) {+ ToastManager.show({+ heading: strings.notePublished(),+ message: strings.unpublishToDelete(),+ type: "error",+ context: "local"+ });+ return;+ }+close();await sleep(300);@@ -1237,7 +1247,8 @@ export const useActions = ({: strings.moveToTrash(),icon: "delete-outline",type: "error",- onPress: deleteItem+ onPress: deleteItem,+ locked: isPublished});}diff --git a/apps/mobile/app/screens/trash/index.tsx b/apps/mobile/app/screens/trash/index.tsxindex c060312f8..5d6cda5a4 100644--- a/apps/mobile/app/screens/trash/index.tsx+++ b/apps/mobile/app/screens/trash/index.tsx@@ -36,7 +36,7 @@ import { strings } from "@notesnook/intl";const onPressFloatingButton = () => {presentDialog({title: strings.clearTrash(),- paragraph: strings.clearTrashConfirm(),+ paragraph: strings.clearTrashDesc(),positiveText: strings.clear(),negativeText: strings.cancel(),positivePress: async () => {@@ -58,8 +58,8 @@ const PLACEHOLDER_DATA = (trashCleanupInterval = 7) => ({trashCleanupInterval === -1? strings.noTrashCleanupInterval(): trashCleanupInterval === 1- ? strings.trashCleanupIntervalTextDaily()- : strings.trashCleanupIntervalTextDays(trashCleanupInterval),+ ? strings.trashCleanupIntervalTextDaily()+ : strings.trashCleanupIntervalTextDays(trashCleanupInterval),loading: strings.loadingTrash()});@@ -107,6 +107,7 @@ export const Trash = ({ navigation, route }: NavigationProps<"Trash">) => {{trash && trash?.placeholders?.length !== 0 ? (<FloatingButtononPress={onPressFloatingButton}+ testID="trash-clear"alwaysVisible={true}/>) : null}diff --git a/apps/mobile/app/utils/functions.ts b/apps/mobile/app/utils/functions.tsindex f6f7aca97..21c4b3e56 100644--- a/apps/mobile/app/utils/functions.ts+++ b/apps/mobile/app/utils/functions.ts@@ -34,6 +34,7 @@ import { useRelationStore } from "../stores/use-relation-store";import { useTagStore } from "../stores/use-tag-store";import { eUpdateNoteInEditor } from "./events";import { unlockVault } from "./unlock-vault";+import { useTrashStore } from "../stores/use-trash-store";export const valueLimiter = (value: number, min: number, max: number) => {return value < min ? min : value > max ? max : value;@@ -210,6 +211,7 @@ export const deleteItems = async (if (type === "notebook") {useNotebookStore.getState().refresh();}+ useTrashStore.getState().refresh();useMenuStore.getState().setMenuPins();};diff --git a/apps/mobile/e2e/tests/trash.e2e.ts b/apps/mobile/e2e/tests/trash.e2e.tsnew file mode 100644index 000000000..a55ced0eb--- /dev/null+++ b/apps/mobile/e2e/tests/trash.e2e.ts@@ -0,0 +1,53 @@+import { notesnook } from "../test.ids";+import { TestBuilder } from "./utils";++describe("TRASH TESTS", () => {+ it("Move a note to trash", async () => {+ await TestBuilder.create()+ .prepare()+ .createNote("Test", "Test note item")+ .tapById(notesnook.listitem.menu)+ .tapById("icon-trash")+ .navigate("Trash")+ .wait(500)+ .isVisibleByText("Test")+ .run();+ });++ it("Permanently remove a note from trash", async () => {+ await TestBuilder.create()+ .prepare()+ .createNote("Test", "Test note item")+ .tapById(notesnook.listitem.menu)+ .tapById("icon-trash")+ .navigate("Trash")+ .wait(500)+ .isVisibleByText("Test")+ .tapById("trash-clear")+ .tapByText("Clear")+ .wait(100)+ .isNotVisibleByText("Test")+ .navigate("Notes")+ .isNotVisibleByText("Test")+ .run();+ });++ it("Clear all notes from side menu", async () => {+ await TestBuilder.create()+ .prepare()+ .createNote("Test", "Test note item")+ .tapById(notesnook.listitem.menu)+ .tapById("icon-trash")+ .navigate("Trash")+ .wait(500)+ .isVisibleByText("Test")+ .openSideMenu()+ .longPressByText("Trash")+ .tapByText("Clear trash")+ .wait(500)+ .tapByText("Clear")+ .tapByText("Trash")+ .isNotVisibleByText("Test")+ .run();+ });+});diff --git a/apps/mobile/fonts/MaterialCommunityIcons.ttf b/apps/mobile/fonts/MaterialCommunityIcons.ttfindex f0059a990..3a5471b8e 100644Binary files a/apps/mobile/fonts/MaterialCommunityIcons.ttf and b/apps/mobile/fonts/MaterialCommunityIcons.ttf differdiff --git a/apps/mobile/scripts/optimize-fonts.mjs b/apps/mobile/scripts/optimize-fonts.mjsindex 8b40705e7..e6263126a 100644--- a/apps/mobile/scripts/optimize-fonts.mjs+++ b/apps/mobile/scripts/optimize-fonts.mjs@@ -121,7 +121,8 @@ const EXTRA_ICON_NAMES = ["calendar-today","bomb","bomb-off",- "cancel"+ "cancel",+ "delete-sweep-outline"];const __filename = fileURLToPath(import.meta.url);