Skip to content

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

mobile: impl preview for trashed notes

ammarahm-edb2b64a172fe2
diff --git a/apps/mobile/app/components/list-items/note/wrapper.js b/apps/mobile/app/components/list-items/note/wrapper.js
index 549ea55cb..47759133b 100644
--- a/apps/mobile/app/components/list-items/note/wrapper.js
+++ b/apps/mobile/app/components/list-items/note/wrapper.js
@@ -27,6 +27,7 @@ import { DDS } from "../../../services/device-detection";
import {
eSendEvent,
openVault,
+ presentSheet,
ToastEvent
} from "../../../services/event-manager";
import Navigation from "../../../services/navigation";
@@ -36,6 +37,7 @@ import { eOnLoadNote, eShowMergeDialog } from "../../../utils/events";
import { tabBarRef } from "../../../utils/global-refs";
import { presentDialog } from "../../dialog/functions";
import SelectionWrapper from "../selection-wrapper";
+import NotePreview from "../../note-history/preview";
const present = () =>
presentDialog({
@@ -84,39 +86,11 @@ export const openNote = async (item, isTrash, setSelectedItem) => {
return;
}
if (isTrash) {
- presentDialog({
- title: `Restore ${item.itemType}`,
- paragraph: `Restore or delete ${item.itemType} forever`,
- positiveText: "Restore",
- negativeText: "Delete",
- positivePress: async () => {
- await db.trash.restore(item.id);
- Navigation.queueRoutesForUpdate(
- "Tags",
- "Notes",
- "Notebooks",
- "Favorites",
- "Trash",
- "TaggedNotes",
- "ColoredNotes",
- "TopicNotes"
- );
- useSelectionStore.getState().setSelectionMode(false);
- ToastEvent.show({
- heading: "Restore successful",
- type: "success"
- });
- },
- onClose: async () => {
- await db.trash.delete(item.id);
- useTrashStore.getState().setTrash();
- useSelectionStore.getState().setSelectionMode(false);
- ToastEvent.show({
- heading: "Permanantly deleted items",
- type: "success",
- context: "local"
- });
- }
+ const content = await db.content.get(item.contentId);
+ presentSheet({
+ component: (
+ <NotePreview note={item} content={{ type: "tiptap", data: content }} />
+ )
});
} else {
useEditorStore.getState().setReadonly(_note?.readonly);
diff --git a/apps/mobile/app/components/note-history/preview.js b/apps/mobile/app/components/note-history/preview.js
index f3bf82dcc..bc6517aec 100644
--- a/apps/mobile/app/components/note-history/preview.js
+++ b/apps/mobile/app/components/note-history/preview.js
@@ -26,18 +26,42 @@ import { editorController } from "../../screens/editor/tiptap/utils";
import { eSendEvent, ToastEvent } from "../../services/event-manager";
import Navigation from "../../services/navigation";
import { useEditorStore } from "../../stores/use-editor-store";
+import { useSelectionStore } from "../../stores/use-selection-store";
import { useThemeStore } from "../../stores/use-theme-store";
+import { useTrashStore } from "../../stores/use-trash-store";
import { eCloseProgressDialog, eOnLoadNote } from "../../utils/events";
import { sleep } from "../../utils/time";
+import { Dialog } from "../dialog";
import DialogHeader from "../dialog/dialog-header";
+import { presentDialog } from "../dialog/functions";
import { Button } from "../ui/button";
import Paragraph from "../ui/typography/paragraph";
-export default function NotePreview({ session, content }) {
+export default function NotePreview({ session, content, note }) {
const colors = useThemeStore((state) => state.colors);
const editorId = ":noteHistory";
async function restore() {
+ if (note && note.type === "trash") {
+ await db.trash.restore(note.id);
+ Navigation.queueRoutesForUpdate(
+ "Tags",
+ "Notes",
+ "Notebooks",
+ "Favorites",
+ "Trash",
+ "TaggedNotes",
+ "ColoredNotes",
+ "TopicNotes"
+ );
+ useSelectionStore.getState().setSelectionMode(false);
+ ToastEvent.show({
+ heading: "Restore successful",
+ type: "success"
+ });
+ eSendEvent(eCloseProgressDialog);
+ return;
+ }
await db.noteHistory.restore(session.id);
if (useEditorStore.getState()?.currentEditingNote === session?.noteId) {
if (editorController.current?.note) {
@@ -63,15 +87,38 @@ export default function NotePreview({ session, content }) {
});
}
+ const deleteNote = async () => {
+ presentDialog({
+ title: `Delete note permanently`,
+ paragraph: `Are you sure you want to delete this note from trash permanentaly`,
+ positiveText: "Delete",
+ negativeText: "Cancel",
+ context:"local",
+ positivePress: async () => {
+ await db.trash.delete(note.id);
+ useTrashStore.getState().setTrash();
+ useSelectionStore.getState().setSelectionMode(false);
+ ToastEvent.show({
+ heading: "Permanantly deleted items",
+ type: "success",
+ context: "local"
+ });
+ eSendEvent(eCloseProgressDialog);
+ },
+ positiveType:"error"
+ });
+ };
+
return (
<View
style={{
- height: session.locked ? null : 600,
+ height: note?.locked || session?.locked ? null : 600,
width: "100%"
}}
>
- <DialogHeader padding={12} title={session.session} />
- {!session.locked ? (
+ <Dialog context="local" />
+ <DialogHeader padding={12} title={note?.title || session?.session} />
+ {!session?.locked && !note?.locked ? (
<View
style={{
flex: 1
@@ -84,10 +131,10 @@ export default function NotePreview({ session, content }) {
readonly
editorId={editorId}
onLoad={async () => {
- const note = db.notes.note(session.noteId)?.data;
- await sleep(300);
+ const _note = note || db.notes.note(session?.noteId)?.data;
+ await sleep(1000);
eSendEvent(eOnLoadNote + editorId, {
- ...note,
+ ..._note,
content: {
...content,
isPreview: true
@@ -116,11 +163,15 @@ export default function NotePreview({ session, content }) {
paddingHorizontal: 12
}}
>
+ <Button onPress={restore} title="Restore" type="accent" width="100%" />
<Button
- onPress={restore}
- title="Restore this version"
- type="accent"
+ onPress={deleteNote}
+ title="Delete permanently"
+ type="error"
width="100%"
+ style={{
+ marginTop: 12
+ }}
/>
</View>
</View>
diff --git a/apps/mobile/package-lock.json b/apps/mobile/package-lock.json
index 837fc35d6..11d947104 100644
--- a/apps/mobile/package-lock.json
+++ b/apps/mobile/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@notesnook/mobile",
- "version": "2.2.4",
+ "version": "2.2.5",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@notesnook/mobile",
- "version": "2.2.4",
+ "version": "2.2.5",
"license": "GPL-3.0-or-later",
"workspaces": [
"native/",
@@ -71,7 +71,7 @@
"@sayem314/react-native-keep-awake": "^1.0.4",
"deprecated-react-native-prop-types": "^2.3.0",
"react": "18.0.0",
- "react-native": "0.69.4",
+ "react-native": "0.69.7",
"react-native-background-actions": "^2.6.6",
"react-native-begin-background-task": "https://github.com/blockfirm/react-native-begin-background-task.git",
"react-native-bootsplash": "^4.1.4",
@@ -17869,9 +17869,9 @@
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
},
"node_modules/react-native": {
- "version": "0.69.4",
- "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.69.4.tgz",
- "integrity": "sha512-rqNMialM/T4pHRKWqTIpOxA65B/9kUjtnepxwJqvsdCeMP9Q2YdSx4VASFR9RoEFYcPRU41yGf6EKrChNfns3g==",
+ "version": "0.69.7",
+ "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.69.7.tgz",
+ "integrity": "sha512-T3z2utgRcE/+mMML3Wg4vvpnFoGWJcqWskq+8vdFS4ASM1zYg5Hab5vPlKZp9uncD8weYiGsYwkWXzrvZrsayQ==",
"dependencies": {
"@jest/create-cache-key-function": "^27.0.1",
"@react-native-community/cli": "^8.0.4",
@@ -17894,9 +17894,9 @@
"mkdirp": "^0.5.1",
"nullthrows": "^1.1.1",
"pretty-format": "^26.5.2",
- "promise": "^8.0.3",
+ "promise": "^8.2.0",
"react-devtools-core": "4.24.0",
- "react-native-codegen": "^0.69.1",
+ "react-native-codegen": "^0.69.2",
"react-native-gradle-plugin": "^0.0.7",
"react-refresh": "^0.4.0",
"react-shallow-renderer": "16.15.0",
@@ -24290,7 +24290,7 @@
"metro-react-native-babel-preset": "^0.70.3",
"pixelmatch": "^5.3.0",
"react": "18.0.0",
- "react-native": "0.69.4",
+ "react-native": "0.69.7",
"react-native-actions-shortcuts": "^1.0.1",
"react-native-background-actions": "^2.6.6",
"react-native-begin-background-task": "https://github.com/blockfirm/react-native-begin-background-task.git",
@@ -34696,9 +34696,9 @@
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
},
"react-native": {
- "version": "0.69.4",
- "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.69.4.tgz",
- "integrity": "sha512-rqNMialM/T4pHRKWqTIpOxA65B/9kUjtnepxwJqvsdCeMP9Q2YdSx4VASFR9RoEFYcPRU41yGf6EKrChNfns3g==",
+ "version": "0.69.7",
+ "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.69.7.tgz",
+ "integrity": "sha512-T3z2utgRcE/+mMML3Wg4vvpnFoGWJcqWskq+8vdFS4ASM1zYg5Hab5vPlKZp9uncD8weYiGsYwkWXzrvZrsayQ==",
"requires": {
"@jest/create-cache-key-function": "^27.0.1",
"@react-native-community/cli": "^8.0.4",
@@ -34721,9 +34721,9 @@
"mkdirp": "^0.5.1",
"nullthrows": "^1.1.1",
"pretty-format": "^26.5.2",
- "promise": "^8.0.3",
+ "promise": "^8.2.0",
"react-devtools-core": "4.24.0",
- "react-native-codegen": "^0.69.1",
+ "react-native-codegen": "^0.69.2",
"react-native-gradle-plugin": "^0.0.7",
"react-refresh": "^0.4.0",
"react-shallow-renderer": "16.15.0",