2022-06-30 09:45:28 +05:00
|
|
|
import React from 'react';
|
|
|
|
|
import { View } from 'react-native';
|
|
|
|
|
import Editor from '../../screens/editor';
|
|
|
|
|
import EditorOverlay from '../../screens/editor/loading';
|
2022-03-26 20:46:21 +05:00
|
|
|
import { editorController } from '../../screens/editor/tiptap/utils';
|
2022-02-28 23:25:18 +05:00
|
|
|
import { eSendEvent, ToastEvent } from '../../services/event-manager';
|
|
|
|
|
import Navigation from '../../services/navigation';
|
2022-05-20 12:40:14 +05:00
|
|
|
import { useEditorStore } from '../../stores/use-editor-store';
|
|
|
|
|
import { useThemeStore } from '../../stores/use-theme-store';
|
2022-01-22 12:57:05 +05:00
|
|
|
import { db } from '../../utils/database';
|
2022-02-28 13:48:59 +05:00
|
|
|
import { eCloseProgressDialog, eOnLoadNote } from '../../utils/events';
|
|
|
|
|
import DialogHeader from '../dialog/dialog-header';
|
2022-03-26 20:46:21 +05:00
|
|
|
import { Button } from '../ui/button';
|
2022-02-28 13:48:59 +05:00
|
|
|
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 }) {
|
2022-02-28 23:25:18 +05:00
|
|
|
const colors = useThemeStore(state => state.colors);
|
2022-06-30 09:45:28 +05:00
|
|
|
const editorId = ':noteHistory';
|
2021-12-14 12:33:39 +05:00
|
|
|
|
|
|
|
|
async function restore() {
|
|
|
|
|
await db.noteHistory.restore(session.id);
|
2021-12-23 12:21:30 +05:00
|
|
|
if (useEditorStore.getState()?.currentEditingNote === session?.noteId) {
|
2022-03-26 20:46:21 +05:00
|
|
|
if (editorController.current?.note) {
|
|
|
|
|
eSendEvent(eOnLoadNote, { ...editorController.current?.note, forced: true });
|
2021-12-23 12:21:30 +05:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-14 12:33:39 +05:00
|
|
|
eSendEvent(eCloseProgressDialog, 'note_history');
|
|
|
|
|
eSendEvent(eCloseProgressDialog);
|
2022-04-24 05:59:14 +05:00
|
|
|
Navigation.queueRoutesForUpdate(
|
|
|
|
|
'Notes',
|
|
|
|
|
'Favorites',
|
|
|
|
|
'ColoredNotes',
|
|
|
|
|
'TaggedNotes',
|
|
|
|
|
'TopicNotes'
|
|
|
|
|
);
|
2021-12-23 12:21:30 +05:00
|
|
|
|
2021-12-14 12:33:39 +05:00
|
|
|
ToastEvent.show({
|
|
|
|
|
heading: 'Note restored successfully',
|
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2022-01-05 20:16:52 +05:00
|
|
|
height: session.locked ? null : 600,
|
2021-12-14 12:33:39 +05:00
|
|
|
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 });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2021-12-29 13:13:37 +05:00
|
|
|
) : (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|