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 }} > -