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
web: added trash setting to control delete time
alihamuhfb8df742427c
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.jsindex 3d2dc9715..52d3c15dd 100644--- a/apps/web/src/views/settings.js+++ b/apps/web/src/views/settings.js@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import { useEffect, useMemo, useState } from "react";-import { Button, Flex, Text } from "@theme-ui/components";+import { Button, Flex, Input, Text } from "@theme-ui/components";import * as Icon from "../components/icons";import { useStore as useUserStore } from "../stores/user-store";import { useStore as useNoteStore } from "../stores/note-store";@@ -149,6 +149,7 @@ function Settings() {developer: false,notifications: false,desktop: false,+ trash: false,other: true});const isVaultCreated = useAppStore((store) => store.isVaultCreated);@@ -187,6 +188,10 @@ function Settings() {"backupReminderOffset",0);+ const [trashDuration, setTrashDuration] = usePersistentState(+ "trashDuration",+ 0+ );const [debugMode, setDebugMode] = usePersistentState("debugMode", false);const [homepage, setHomepage] = usePersistentState("homepage", 0);const [backupStorageLocation, setBackupStorageLocation] = usePersistentState(@@ -779,7 +784,30 @@ function Settings() {)}</>)}-+ <Header+ title="Trash Settings"+ isOpen={groups.trash}+ testId="trash-settings"+ onClick={() => {+ setGroups((g) => ({ ...g, trash: !g.trash }));+ }}+ />+ {groups.trash && (+ <OptionsItem+ title="Trash Duration"+ tip={+ isDesktop()+ ? "Permanently delete trash after:"+ : "Wipe out trash after:"+ }+ options={["7 Days", "A Month", "A Year", "Never"]}+ premium="backups"+ selectedOption={trashDuration}+ onSelectionChanged={async (_option, index) =>+ setTrashDuration(index)+ }+ />+ )}<Headertitle="Notesnook Importer"isOpen={groups.importer}diff --git a/packages/core/collections/trash.js b/packages/core/collections/trash.jsindex 2d1169566..3f40eda0d 100644--- a/packages/core/collections/trash.js+++ b/packages/core/collections/trash.js@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import dayjs from "dayjs";+import Config from "../../../apps/web/src/utils/config";export default class Trash {/**@@ -38,10 +39,13 @@ export default class Trash {async cleanup() {const now = dayjs().unix();- for (const item of this.all) {- if (dayjs(item.dateDeleted).add(7, "days").unix() > now) continue;- await this.delete(item.id);- }+ const duration = trashDuration(Config.get("trashDuration", 0));+ if (duration)+ for (const item of this.all) {+ if (dayjs(item.dateDeleted).add(duration, "days").unix() > now)+ continue;+ await this.delete(item.id);+ }}get all() {@@ -145,3 +149,16 @@ function collectionNameFromItem(item) {return null;}}++function trashDuration(option) {+ switch (option) {+ case 0:+ return 7;+ case 1:+ return 30;+ case 2:+ return 365;+ case 3:+ return false;+ }+}