Files
notesnook/apps/mobile/app/components/note-history/preview.js

123 lines
3.5 KiB
JavaScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
Copyright (C) 2022 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/>.
*/
2022-08-30 16:13:11 +05:00
2022-08-29 16:19:17 +05:00
import React from "react";
import { View } from "react-native";
2022-08-29 16:19:17 +05:00
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 { useThemeStore } from "../../stores/use-theme-store";
import { eCloseProgressDialog, eOnLoadNote } from "../../utils/events";
import DialogHeader from "../dialog/dialog-header";
import { Button } from "../ui/button";
import Paragraph from "../ui/typography/paragraph";
2021-12-14 12:33:39 +05:00
2022-01-22 12:57:05 +05:00
export default function NotePreview({ session, content }) {
const colors = useThemeStore((state) => state.colors);
const editorId = ":noteHistory";
2021-12-14 12:33:39 +05:00
async function restore() {
await db.noteHistory.restore(session.id);
if (useEditorStore.getState()?.currentEditingNote === session?.noteId) {
if (editorController.current?.note) {
eSendEvent(eOnLoadNote, {
...editorController.current?.note,
forced: true
});
}
}
eSendEvent(eCloseProgressDialog, "note_history");
2021-12-14 12:33:39 +05:00
eSendEvent(eCloseProgressDialog);
2022-04-24 05:59:14 +05:00
Navigation.queueRoutesForUpdate(
"Notes",
"Favorites",
"ColoredNotes",
"TaggedNotes",
"TopicNotes"
2022-04-24 05:59:14 +05:00
);
2021-12-14 12:33:39 +05:00
ToastEvent.show({
heading: "Note restored successfully",
type: "success"
2021-12-14 12:33:39 +05:00
});
}
return (
<View
style={{
2022-01-05 20:16:52 +05:00
height: session.locked ? null : 600,
width: "100%"
2022-01-22 12:57:05 +05:00
}}
>
2021-12-22 13:59:58 +05:00
<DialogHeader padding={12} title={session.session} />
2021-12-29 13:13:37 +05:00
{!session.locked ? (
2022-06-30 09:45:28 +05:00
<>
<EditorOverlay editorId={editorId} />
<Editor
noHeader
noToolbar
readonly
editorId={editorId}
onLoad={() => {
const note = db.notes.note(session.noteId)?.data;
eSendEvent(eOnLoadNote + editorId, {
...note,
content: {
...content,
isPreview: true
}
});
2022-06-30 09:45:28 +05:00
}}
/>
</>
2021-12-29 13:13:37 +05:00
) : (
<View
style={{
width: "100%",
2021-12-29 13:13:37 +05:00
height: 100,
justifyContent: "center",
alignItems: "center"
2022-01-22 12:57:05 +05:00
}}
>
<Paragraph color={colors.icon}>
Preview not available, content is encrypted.
</Paragraph>
2021-12-29 13:13:37 +05:00
</View>
)}
2021-12-14 12:33:39 +05:00
<View
style={{
paddingHorizontal: 12
2022-01-22 12:57:05 +05:00
}}
>
<Button
onPress={restore}
title="Restore this version"
type="accent"
width="100%"
/>
2021-12-14 12:33:39 +05:00
</View>
</View>
);
}