diff --git a/apps/mobile/app/components/note-history/preview.js b/apps/mobile/app/components/note-history/preview.js
index bf7637a7c..643a6b2fc 100644
--- a/apps/mobile/app/components/note-history/preview.js
+++ b/apps/mobile/app/components/note-history/preview.js
@@ -17,20 +17,18 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
-import React from "react";
+import { useThemeColors } from "@notesnook/theme";
+import React, { useState } from "react";
import { View } from "react-native";
import { db } from "../../common/database";
import Editor from "../../screens/editor";
-import EditorOverlay from "../../screens/editor/loading";
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 { useThemeColors } from "@notesnook/theme";
import { useTrashStore } from "../../stores/use-trash-store";
import { eCloseSheet, eOnLoadNote } from "../../utils/events";
-import { sleep } from "../../utils/time";
import { Dialog } from "../dialog";
import DialogHeader from "../dialog/dialog-header";
import { presentDialog } from "../dialog/functions";
@@ -40,10 +38,15 @@ import Paragraph from "../ui/typography/paragraph";
export default function NotePreview({ session, content, note }) {
const { colors } = useThemeColors();
const editorId = ":noteHistory";
+ const [loading, setLoading] = useState(false);
async function restore() {
if (note && note.type === "trash") {
await db.trash.restore(note.id);
+ console.log(
+ useEditorStore.getState()?.currentEditingNote === session?.noteId,
+ "will reload note?"
+ );
Navigation.queueRoutesForUpdate();
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
@@ -53,22 +56,26 @@ export default function NotePreview({ session, content, note }) {
eSendEvent(eCloseSheet);
return;
}
- await db.noteHistory.restore(session.id);
- if (useEditorStore.getState()?.currentEditingNote === session?.noteId) {
- if (editorController.current?.note) {
- eSendEvent(eOnLoadNote, {
- ...editorController.current?.note,
- forced: true
- });
+ setLoading(true);
+ setTimeout(async () => {
+ await db.noteHistory.restore(session.id);
+ if (useEditorStore.getState()?.currentEditingNote === session?.noteId) {
+ if (editorController.current?.note) {
+ eSendEvent(eOnLoadNote, {
+ ...editorController.current?.note.current,
+ forced: true
+ });
+ }
}
- }
- eSendEvent(eCloseSheet, "note_history");
- eSendEvent(eCloseSheet);
- Navigation.queueRoutesForUpdate();
+ setLoading(false);
+ eSendEvent(eCloseSheet, "note_history");
+ eSendEvent(eCloseSheet);
+ Navigation.queueRoutesForUpdate();
- ToastEvent.show({
- heading: "Note restored successfully",
- type: "success"
+ ToastEvent.show({
+ heading: "Note restored successfully",
+ type: "success"
+ });
});
}
@@ -146,9 +153,16 @@ export default function NotePreview({ session, content, note }) {
paddingHorizontal: 12
}}
>
-
+
.
/* eslint-disable no-case-declarations */
/* eslint-disable @typescript-eslint/no-var-requires */
-import Clipboard from "@react-native-clipboard/clipboard";
import type { Attachment } from "@notesnook/editor/dist/extensions/attachment/index";
import { getDefaultPresets } from "@notesnook/editor/dist/toolbar/tool-definitions";
+import Clipboard from "@react-native-clipboard/clipboard";
import { useCallback, useEffect, useRef } from "react";
import {
BackHandler,
@@ -43,7 +43,9 @@ import {
eUnSubscribeEvent
} from "../../../services/event-manager";
import Navigation from "../../../services/navigation";
+import SettingsService from "../../../services/settings";
import { useEditorStore } from "../../../stores/use-editor-store";
+import { useNoteStore } from "../../../stores/use-notes-store";
import { useSettingStore } from "../../../stores/use-setting-store";
import { useTagStore } from "../../../stores/use-tag-store";
import { useUserStore } from "../../../stores/use-user-store";
@@ -63,8 +65,6 @@ import { useDragState } from "../../settings/editor/state";
import { EventTypes } from "./editor-events";
import { EditorMessage, EditorProps, useEditorType } from "./types";
import { EditorEvents, editorState } from "./utils";
-import { useNoteStore } from "../../../stores/use-notes-store";
-import SettingsService from "../../../services/settings";
const publishNote = async (editor: useEditorType) => {
const user = useUserStore.getState().user;