Skip to content

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

mobile: add trash interval settings

ammarahm-ed65dea70ae5da
diff --git a/apps/mobile/app/screens/settings/components.tsx b/apps/mobile/app/screens/settings/components.tsx
index 4e8071a7a..da09823b2 100644
--- a/apps/mobile/app/screens/settings/components.tsx
+++ b/apps/mobile/app/screens/settings/components.tsx
@@ -25,6 +25,7 @@ import { ConfigureToolbar } from "./editor/configure-toolbar";
import { Licenses } from "./licenses";
import SoundPicker from "./sound-picker";
import { Subscription } from "./subscription";
+import { TrashIntervalSelector } from "./trash-interval-selector";
export const components: { [name: string]: ReactElement } = {
colorpicker: <AccentColorPicker />,
homeselector: <HomagePageSelector />,
@@ -33,5 +34,6 @@ export const components: { [name: string]: ReactElement } = {
configuretoolbar: <ConfigureToolbar />,
"debug-logs": <DebugLogs />,
"sound-picker": <SoundPicker />,
- licenses: <Licenses />
+ licenses: <Licenses />,
+ "trash-interval-selector": <TrashIntervalSelector />
};
diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsx
index cf74e30a0..31bd30887 100644
--- a/apps/mobile/app/screens/settings/settings-data.tsx
+++ b/apps/mobile/app/screens/settings/settings-data.tsx
@@ -523,6 +523,14 @@ export const settingsGroups: SettingSection[] = [
name: "Homepage",
description: "Default screen to open on app startup",
component: "homeselector"
+ },
+ {
+ id: "clear-trash-interval",
+ type: "component",
+ name: "Clear trash interval",
+ description:
+ "Select the duration after which trash items will be cleared",
+ component: "trash-interval-selector"
}
]
}
diff --git a/apps/mobile/app/screens/settings/trash-interval-selector.jsx b/apps/mobile/app/screens/settings/trash-interval-selector.jsx
new file mode 100644
index 000000000..8bab61b4e
--- /dev/null
+++ b/apps/mobile/app/screens/settings/trash-interval-selector.jsx
@@ -0,0 +1,110 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import React, { useRef, useState } from "react";
+import { View } from "react-native";
+import Menu, { MenuItem } from "react-native-reanimated-material-menu";
+import Icon from "react-native-vector-icons/MaterialCommunityIcons";
+import { db } from "../../common/database";
+import { PressableButton } from "../../components/ui/pressable";
+import Paragraph from "../../components/ui/typography/paragraph";
+import PremiumService from "../../services/premium";
+import { useThemeStore } from "../../stores/use-theme-store";
+import { SIZE } from "../../utils/size";
+
+export const TrashIntervalSelector = () => {
+ const colors = useThemeStore((state) => state.colors);
+ const [trashInterval, setTrashInterval] = useState(
+ db.settings.getTrashCleanupInterval()
+ );
+ console.log(db.settings.getTrashCleanupInterval());
+ const menuRef = useRef();
+ const [width, setWidth] = useState(0);
+ return (
+ <View
+ onLayout={(event) => {
+ setWidth(event.nativeEvent.layout.width);
+ }}
+ style={{
+ width: "100%"
+ }}
+ >
+ <Menu
+ ref={menuRef}
+ animationDuration={200}
+ style={{
+ borderRadius: 5,
+ backgroundColor: colors.bg,
+ width: width,
+ marginTop: 60
+ }}
+ onRequestClose={() => {
+ menuRef.current?.hide();
+ }}
+ anchor={
+ <PressableButton
+ onPress={async () => {
+ await PremiumService.verify(menuRef.current?.show);
+ }}
+ type="grayBg"
+ customStyle={{
+ flexDirection: "row",
+ alignItems: "center",
+ marginTop: 10,
+ width: "100%",
+ justifyContent: "space-between",
+ padding: 12
+ }}
+ >
+ <Paragraph>
+ {trashInterval === -1 ? "Never" : trashInterval + " days"}
+ </Paragraph>
+ <Icon color={colors.icon} name="menu-down" size={SIZE.md} />
+ </PressableButton>
+ }
+ >
+ {[-1, 7, 30, 365].map(
+ (item) =>
+ item.name !== "Monographs" && (
+ <MenuItem
+ key={item.name}
+ onPress={async () => {
+ menuRef.current?.hide();
+ setTrashInterval(item);
+ db.settings.setTrashCleanupInterval(item);
+ }}
+ style={{
+ backgroundColor:
+ trashInterval === item ? colors.nav : "transparent",
+ width: "100%",
+ maxWidth: width
+ }}
+ textStyle={{
+ fontSize: SIZE.md,
+ color: trashInterval === item ? colors.accent : colors.pri
+ }}
+ >
+ {item === -1 ? "Never" : item + " days"}
+ </MenuItem>
+ )
+ )}
+ </Menu>
+ </View>
+ );
+};