2021-07-08 09:34:21 +05:00
|
|
|
import KeepAwake from '@sayem314/react-native-keep-awake';
|
2021-10-18 15:01:22 +05:00
|
|
|
import {EV, EVENTS} from 'notes-core/common';
|
2020-09-09 11:10:35 +05:00
|
|
|
import React, {createRef, useEffect, useState} from 'react';
|
2021-10-06 10:29:07 +05:00
|
|
|
import {Modal, SafeAreaView, Text, View} from 'react-native';
|
|
|
|
|
import Animated from 'react-native-reanimated';
|
2020-11-29 12:21:36 +05:00
|
|
|
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
2020-03-26 13:39:04 +05:00
|
|
|
import WebView from 'react-native-webview';
|
2020-09-09 11:10:35 +05:00
|
|
|
import {useTracked} from '../../provider';
|
2020-11-29 12:21:36 +05:00
|
|
|
import {DDS} from '../../services/DeviceDetection';
|
2020-03-26 15:50:10 +05:00
|
|
|
import {
|
2020-09-09 11:10:35 +05:00
|
|
|
eSendEvent,
|
2020-03-26 15:50:10 +05:00
|
|
|
eSubscribeEvent,
|
2021-10-06 10:29:07 +05:00
|
|
|
eUnSubscribeEvent
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../services/EventManager';
|
2021-07-08 09:34:21 +05:00
|
|
|
import Navigation from '../../services/Navigation';
|
|
|
|
|
import Sync from '../../services/Sync';
|
|
|
|
|
import {dHeight} from '../../utils';
|
2021-10-02 10:26:29 +05:00
|
|
|
import {db} from '../../utils/database';
|
2021-07-08 09:34:21 +05:00
|
|
|
import diff from '../../utils/differ';
|
2020-03-26 15:50:10 +05:00
|
|
|
import {
|
|
|
|
|
eApplyChanges,
|
|
|
|
|
eShowMergeDialog,
|
2021-10-06 10:29:07 +05:00
|
|
|
refreshNotesPage
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../utils/Events';
|
2021-07-08 09:34:21 +05:00
|
|
|
import {openLinkInBrowser} from '../../utils/functions';
|
2020-11-30 16:16:03 +05:00
|
|
|
import {normalize, SIZE} from '../../utils/SizeUtils';
|
2021-07-08 09:34:21 +05:00
|
|
|
import {timeConverter} from '../../utils/TimeUtils';
|
|
|
|
|
import {
|
|
|
|
|
getNote,
|
|
|
|
|
sourceUri,
|
2021-10-06 10:29:07 +05:00
|
|
|
updateNoteInEditor
|
2021-07-08 09:34:21 +05:00
|
|
|
} from '../../views/Editor/Functions';
|
2021-10-06 10:29:07 +05:00
|
|
|
import {ActionIcon} from '../ActionIcon';
|
2020-09-09 11:10:35 +05:00
|
|
|
import {Button} from '../Button';
|
2020-11-29 13:23:46 +05:00
|
|
|
import BaseDialog from '../Dialog/base-dialog';
|
|
|
|
|
import DialogButtons from '../Dialog/dialog-buttons';
|
|
|
|
|
import DialogContainer from '../Dialog/dialog-container';
|
|
|
|
|
import DialogHeader from '../Dialog/dialog-header';
|
2021-11-08 15:06:46 +05:00
|
|
|
import Seperator from '../Seperator';
|
2020-11-20 01:23:05 +05:00
|
|
|
import Paragraph from '../Typography/Paragraph';
|
2020-03-26 13:39:04 +05:00
|
|
|
|
|
|
|
|
const primaryWebView = createRef();
|
|
|
|
|
const secondaryWebView = createRef();
|
2020-03-26 15:42:37 +05:00
|
|
|
let note = null;
|
2020-11-29 12:21:36 +05:00
|
|
|
let primaryData = null;
|
|
|
|
|
let secondaryData = null;
|
2021-02-09 12:01:19 +05:00
|
|
|
|
2021-10-06 10:29:07 +05:00
|
|
|
function onMediaLoaded({hash, src}) {
|
2021-10-18 15:01:22 +05:00
|
|
|
console.log('on media download complete');
|
2021-10-06 10:29:07 +05:00
|
|
|
let inject = `
|
|
|
|
|
(function(){
|
|
|
|
|
const elements = document.querySelectorAll("img[data-hash=${hash}]");
|
|
|
|
|
if (!elements || !elements.length) return;
|
|
|
|
|
for (let element of elements) element.setAttribute("src", "${src}");
|
|
|
|
|
})();`;
|
|
|
|
|
primaryWebView.current?.injectJavaScript(inject);
|
|
|
|
|
secondaryWebView.current?.injectJavaScript(inject);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 13:39:04 +05:00
|
|
|
const MergeEditor = () => {
|
|
|
|
|
const [state, dispatch] = useTracked();
|
2020-09-09 11:10:35 +05:00
|
|
|
const {colors} = state;
|
2020-03-26 15:42:37 +05:00
|
|
|
const [visible, setVisible] = useState(false);
|
2020-03-26 13:39:04 +05:00
|
|
|
const [primary, setPrimary] = useState(true);
|
|
|
|
|
const [secondary, setSecondary] = useState(true);
|
|
|
|
|
const [keepContentFrom, setKeepContentFrom] = useState(null);
|
|
|
|
|
const [copyToSave, setCopyToSave] = useState(null);
|
|
|
|
|
const [disardedContent, setDiscardedContent] = useState(null);
|
2020-11-29 13:23:46 +05:00
|
|
|
const [dialogVisible, setDialogVisible] = useState(false);
|
2021-10-06 10:29:07 +05:00
|
|
|
const [loadingAttachments, setLoadingAttachments] = useState(false);
|
2020-11-29 12:21:36 +05:00
|
|
|
const insets = useSafeAreaInsets();
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2021-10-06 10:29:07 +05:00
|
|
|
const onPrimaryWebViewLoad = async () => {
|
|
|
|
|
let content = await db.content.insertPlaceholders(
|
|
|
|
|
primaryData,
|
|
|
|
|
'placeholder.svg'
|
|
|
|
|
);
|
|
|
|
|
postMessage(primaryWebView, 'htmldiff', content.data);
|
2021-02-09 12:01:19 +05:00
|
|
|
let theme = {...colors};
|
|
|
|
|
theme.factor = normalize(1);
|
2021-07-08 09:34:21 +05:00
|
|
|
postMessage(primaryWebView, 'theme', JSON.stringify(theme));
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
2021-10-06 10:29:07 +05:00
|
|
|
const onSecondaryWebViewLoad = async () => {
|
|
|
|
|
let content = await db.content.insertPlaceholders(
|
|
|
|
|
secondaryData,
|
|
|
|
|
'placeholder.svg'
|
|
|
|
|
);
|
|
|
|
|
postMessage(secondaryWebView, 'htmldiff', content?.data);
|
2021-02-09 12:01:19 +05:00
|
|
|
let theme = {...colors};
|
|
|
|
|
theme.factor = normalize(1);
|
2021-07-08 09:34:21 +05:00
|
|
|
postMessage(secondaryWebView, 'theme', JSON.stringify(theme));
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
2021-04-06 10:58:49 +05:00
|
|
|
function postMessage(webview, type, value = null) {
|
|
|
|
|
let message = {
|
2021-07-08 09:34:21 +05:00
|
|
|
type: type,
|
2021-10-06 10:29:07 +05:00
|
|
|
value
|
2021-04-06 10:58:49 +05:00
|
|
|
};
|
|
|
|
|
webview.current?.postMessage(JSON.stringify(message));
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-08 09:34:21 +05:00
|
|
|
const _onShouldStartLoadWithRequest = request => {
|
2021-02-10 10:09:48 +05:00
|
|
|
if (request.url.includes('http')) {
|
|
|
|
|
openLinkInBrowser(request.url, colors)
|
2021-07-08 09:34:21 +05:00
|
|
|
.catch(e =>
|
2021-02-20 15:03:02 +05:00
|
|
|
ToastEvent.show({
|
|
|
|
|
title: 'Failed to open link',
|
|
|
|
|
message: e.message,
|
|
|
|
|
type: 'success',
|
2021-10-06 10:29:07 +05:00
|
|
|
context: 'local'
|
|
|
|
|
})
|
2021-02-20 15:03:02 +05:00
|
|
|
)
|
2021-07-08 09:34:21 +05:00
|
|
|
.then(r => {
|
2021-02-20 15:03:02 +05:00
|
|
|
console.log('closed');
|
|
|
|
|
});
|
2021-02-10 10:09:48 +05:00
|
|
|
|
2020-03-26 13:39:04 +05:00
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-26 15:42:37 +05:00
|
|
|
const applyChanges = async () => {
|
2021-10-06 10:29:07 +05:00
|
|
|
let content = keepContentFrom === 'primary' ? primaryData : secondaryData;
|
|
|
|
|
let keepCopy =
|
|
|
|
|
copyToSave === 'primary'
|
|
|
|
|
? primaryData
|
|
|
|
|
: copyToSave === 'secondary'
|
|
|
|
|
? secondaryData
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
await db.notes.add({
|
|
|
|
|
content: {
|
|
|
|
|
data: content.data,
|
|
|
|
|
type: content.type,
|
|
|
|
|
dateEdited: content.dateEdited,
|
|
|
|
|
remote: true,
|
2021-10-18 15:01:22 +05:00
|
|
|
dateResolved: secondaryData.dateEdited
|
2021-10-06 10:29:07 +05:00
|
|
|
},
|
|
|
|
|
id: note.id,
|
|
|
|
|
conflicted: false
|
|
|
|
|
});
|
|
|
|
|
if (keepCopy) {
|
2020-03-26 15:42:37 +05:00
|
|
|
await db.notes.add({
|
|
|
|
|
content: {
|
2021-10-06 10:29:07 +05:00
|
|
|
data: keepCopy.data,
|
|
|
|
|
type: keepCopy.type
|
2020-03-26 15:42:37 +05:00
|
|
|
},
|
2021-10-06 10:29:07 +05:00
|
|
|
id: null
|
2020-03-26 15:42:37 +05:00
|
|
|
});
|
|
|
|
|
}
|
2020-03-26 15:50:10 +05:00
|
|
|
eSendEvent(refreshNotesPage);
|
2021-06-02 17:34:39 +05:00
|
|
|
Navigation.setRoutesToUpdate([
|
|
|
|
|
Navigation.routeNames.NotesPage,
|
|
|
|
|
Navigation.routeNames.Favorites,
|
2021-10-06 10:29:07 +05:00
|
|
|
Navigation.routeNames.Notes
|
2021-06-02 17:34:39 +05:00
|
|
|
]);
|
2021-07-03 12:47:19 +05:00
|
|
|
if (getNote()?.id === note.id) {
|
|
|
|
|
updateNoteInEditor();
|
|
|
|
|
}
|
2020-03-26 15:42:37 +05:00
|
|
|
close();
|
2021-05-25 22:14:06 +05:00
|
|
|
await Sync.run();
|
2020-03-26 15:42:37 +05:00
|
|
|
};
|
|
|
|
|
|
2021-07-08 09:34:21 +05:00
|
|
|
const show = async item => {
|
2020-03-26 15:42:37 +05:00
|
|
|
note = item;
|
2021-10-06 10:29:07 +05:00
|
|
|
let content = await db.content.raw(note.contentId);
|
2021-10-18 15:01:22 +05:00
|
|
|
switch (content.type) {
|
2021-07-08 09:34:21 +05:00
|
|
|
case 'tiny':
|
2021-10-06 10:29:07 +05:00
|
|
|
primaryData = content;
|
|
|
|
|
secondaryData = content.conflicted;
|
2021-07-08 09:34:21 +05:00
|
|
|
}
|
2020-04-11 11:11:42 +05:00
|
|
|
setVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eApplyChanges, applyChanges);
|
2020-03-26 15:42:37 +05:00
|
|
|
eSubscribeEvent(eShowMergeDialog, show);
|
2020-03-26 13:39:04 +05:00
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eApplyChanges, applyChanges);
|
2020-03-26 15:42:37 +05:00
|
|
|
eUnSubscribeEvent(eShowMergeDialog, show);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
2020-09-09 11:10:35 +05:00
|
|
|
}, []);
|
2020-03-26 13:39:04 +05:00
|
|
|
|
|
|
|
|
const onPressKeepFromPrimaryWebView = () => {
|
|
|
|
|
if (keepContentFrom == 'primary') {
|
|
|
|
|
setKeepContentFrom(null);
|
|
|
|
|
} else {
|
|
|
|
|
setKeepContentFrom('primary');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressSaveCopyFromPrimaryWebView = () => {
|
|
|
|
|
setCopyToSave('primary');
|
2020-11-29 13:23:46 +05:00
|
|
|
setDialogVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressKeepFromSecondaryWebView = () => {
|
|
|
|
|
if (keepContentFrom == 'secondary') {
|
|
|
|
|
setKeepContentFrom(null);
|
|
|
|
|
} else {
|
|
|
|
|
setKeepContentFrom('secondary');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressSaveCopyFromSecondaryWebView = () => {
|
|
|
|
|
setCopyToSave('secondary');
|
2020-11-29 13:23:46 +05:00
|
|
|
setDialogVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressDiscardFromPrimaryWebView = () => {
|
|
|
|
|
setDiscardedContent('primary');
|
2020-11-29 13:23:46 +05:00
|
|
|
setDialogVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPressDiscardFromSecondaryWebView = () => {
|
|
|
|
|
setDiscardedContent('secondary');
|
2020-11-29 13:23:46 +05:00
|
|
|
setDialogVisible(true);
|
2020-03-26 13:39:04 +05:00
|
|
|
};
|
|
|
|
|
|
2020-03-26 15:42:37 +05:00
|
|
|
const close = () => {
|
2021-10-18 15:01:22 +05:00
|
|
|
|
|
|
|
|
db.fs.cancel(primaryData?.noteId);
|
|
|
|
|
|
|
|
|
|
EV.unsubscribe(EVENTS.mediaAttachmentDownloaded, onMediaLoaded);
|
2020-03-26 15:42:37 +05:00
|
|
|
setVisible(false);
|
|
|
|
|
setPrimary(true);
|
|
|
|
|
setSecondary(true);
|
|
|
|
|
setCopyToSave(null);
|
|
|
|
|
setDiscardedContent(null);
|
|
|
|
|
setKeepContentFrom(null);
|
2020-12-27 13:51:09 +05:00
|
|
|
setDialogVisible(false);
|
2020-11-29 12:21:36 +05:00
|
|
|
primaryData = null;
|
|
|
|
|
secondaryData = null;
|
2020-03-26 15:42:37 +05:00
|
|
|
primaryText = null;
|
|
|
|
|
secondaryText = null;
|
|
|
|
|
note = null;
|
2021-10-06 10:29:07 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onLoadImages = async () => {
|
|
|
|
|
try {
|
|
|
|
|
setLoadingAttachments(true);
|
2021-10-18 15:01:22 +05:00
|
|
|
EV.subscribe(EVENTS.mediaAttachmentDownloaded, onMediaLoaded);
|
2021-10-06 10:29:07 +05:00
|
|
|
await db.content.downloadMedia(primaryData.data.noteId, primaryData);
|
|
|
|
|
await db.content.downloadMedia(primaryData.data.noteId, secondaryData);
|
2021-10-18 15:01:22 +05:00
|
|
|
EV.unsubscribe(EVENTS.mediaAttachmentDownloaded, onMediaLoaded);
|
2021-10-06 10:29:07 +05:00
|
|
|
setLoadingAttachments(false);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
setLoadingAttachments(false);
|
|
|
|
|
eUnSubscribeEvent(EVENTS.mediaAttachmentDownloaded, onMediaLoaded);
|
|
|
|
|
}
|
2020-03-26 15:42:37 +05:00
|
|
|
};
|
|
|
|
|
|
2020-11-23 12:32:33 +05:00
|
|
|
return !visible ? null : (
|
2020-11-29 12:21:36 +05:00
|
|
|
<Modal
|
|
|
|
|
statusBarTranslucent
|
|
|
|
|
transparent={false}
|
|
|
|
|
animationType="slide"
|
2021-07-08 09:34:21 +05:00
|
|
|
onRequestClose={() => {
|
|
|
|
|
close();
|
2021-04-19 10:58:32 +05:00
|
|
|
}}
|
2020-11-29 12:21:36 +05:00
|
|
|
visible={true}>
|
2020-09-09 11:10:35 +05:00
|
|
|
<SafeAreaView
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
2021-01-20 10:54:06 +05:00
|
|
|
backgroundColor: colors.bg,
|
2021-10-06 10:29:07 +05:00
|
|
|
paddingTop: insets.top
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2021-01-03 12:40:59 +05:00
|
|
|
<KeepAwake />
|
2020-11-29 13:23:46 +05:00
|
|
|
{dialogVisible && (
|
|
|
|
|
<BaseDialog visible={true}>
|
|
|
|
|
<DialogContainer>
|
|
|
|
|
<DialogHeader
|
|
|
|
|
title="Apply Changes"
|
|
|
|
|
paragraph="Apply selected changes to note?"
|
2021-11-08 15:06:46 +05:00
|
|
|
padding={12}
|
2020-11-29 13:23:46 +05:00
|
|
|
/>
|
2021-11-08 15:06:46 +05:00
|
|
|
<Seperator/>
|
2020-11-29 13:23:46 +05:00
|
|
|
<DialogButtons
|
|
|
|
|
positiveTitle="Apply"
|
|
|
|
|
negativeTitle="Cancel"
|
|
|
|
|
onPressNegative={() => setDialogVisible(false)}
|
|
|
|
|
onPressPositive={applyChanges}
|
|
|
|
|
/>
|
|
|
|
|
</DialogContainer>
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
)}
|
|
|
|
|
|
2020-03-26 13:39:04 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
height: '100%',
|
2020-03-26 13:39:04 +05:00
|
|
|
width: '100%',
|
2021-10-06 10:29:07 +05:00
|
|
|
backgroundColor: DDS.isLargeTablet() ? 'rgba(0,0,0,0.3)' : null
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
width: '100%',
|
|
|
|
|
height: 50,
|
2020-03-26 13:39:04 +05:00
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
2020-09-09 11:10:35 +05:00
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingHorizontal: 12,
|
2021-10-06 10:29:07 +05:00
|
|
|
paddingLeft: 6
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2020-09-09 11:10:35 +05:00
|
|
|
<View
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'space-between',
|
2021-10-06 10:29:07 +05:00
|
|
|
flexShrink: 1
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2021-10-06 10:29:07 +05:00
|
|
|
<ActionIcon
|
2020-09-09 11:10:35 +05:00
|
|
|
onPress={close}
|
2021-01-20 10:54:06 +05:00
|
|
|
color={colors.pri}
|
2020-11-29 12:21:36 +05:00
|
|
|
name="arrow-left"
|
2020-09-09 11:10:35 +05:00
|
|
|
/>
|
2021-10-06 10:29:07 +05:00
|
|
|
<Paragraph
|
|
|
|
|
style={{flexWrap: 'wrap'}}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
size={SIZE.xs}>
|
|
|
|
|
<Text style={{color: colors.accent, fontWeight: 'bold'}}>
|
|
|
|
|
(This Device)
|
|
|
|
|
</Text>
|
|
|
|
|
{'\n'}
|
|
|
|
|
{timeConverter(primaryData?.dateEdited)}
|
|
|
|
|
</Paragraph>
|
2020-09-09 11:10:35 +05:00
|
|
|
</View>
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
2021-10-06 10:29:07 +05:00
|
|
|
justifyContent: 'flex-end'
|
2020-09-09 11:10:35 +05:00
|
|
|
}}>
|
|
|
|
|
{keepContentFrom === 'secondary' ? (
|
|
|
|
|
<Button
|
|
|
|
|
onPress={onPressSaveCopyFromPrimaryWebView}
|
2021-10-06 10:29:07 +05:00
|
|
|
title="Save a copy"
|
|
|
|
|
type="grayBg"
|
|
|
|
|
height={30}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 12
|
|
|
|
|
}}
|
2021-12-16 10:20:34 +05:00
|
|
|
fontSize={SIZE.xs}
|
2020-09-09 11:10:35 +05:00
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
<View style={{width: 10}} />
|
|
|
|
|
{keepContentFrom === 'secondary' ? (
|
|
|
|
|
<Button
|
|
|
|
|
title="Discard"
|
2021-01-05 10:20:16 +05:00
|
|
|
type="accent"
|
|
|
|
|
accentColor="red"
|
2021-10-06 10:29:07 +05:00
|
|
|
height={30}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 12
|
|
|
|
|
}}
|
2021-12-16 10:20:34 +05:00
|
|
|
fontSize={SIZE.xs}
|
2021-01-05 10:20:16 +05:00
|
|
|
accentText="light"
|
2020-09-09 11:10:35 +05:00
|
|
|
color={colors.errorText}
|
|
|
|
|
onPress={onPressDiscardFromPrimaryWebView}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
{keepContentFrom === 'secondary' ? null : (
|
2021-01-13 16:32:35 +05:00
|
|
|
<>
|
|
|
|
|
<Button
|
2021-10-06 10:29:07 +05:00
|
|
|
type="grayBg"
|
|
|
|
|
title="Load images"
|
|
|
|
|
onPress={onLoadImages}
|
|
|
|
|
height={30}
|
|
|
|
|
loading={loadingAttachments}
|
|
|
|
|
fontSize={SIZE.xs}
|
|
|
|
|
icon="download"
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
minWidth: 60
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
height={30}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
minWidth: 60,
|
|
|
|
|
marginLeft: 10
|
|
|
|
|
}}
|
|
|
|
|
type="accent"
|
2021-12-16 10:20:34 +05:00
|
|
|
fontSize={SIZE.xs}
|
2021-01-13 16:32:35 +05:00
|
|
|
title={keepContentFrom === 'primary' ? 'Undo' : 'Keep'}
|
|
|
|
|
onPress={onPressKeepFromPrimaryWebView}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2020-09-09 11:10:35 +05:00
|
|
|
)}
|
|
|
|
|
</View>
|
2020-03-26 13:39:04 +05:00
|
|
|
</View>
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
<Animated.View
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
2021-10-06 10:29:07 +05:00
|
|
|
height: dHeight / 2 - (50 + insets.top / 2),
|
2021-02-09 12:01:19 +05:00
|
|
|
backgroundColor: colors.bg,
|
2021-10-06 10:29:07 +05:00
|
|
|
borderBottomWidth: 1,
|
|
|
|
|
borderBottomColor: colors.nav
|
2020-09-09 11:10:35 +05:00
|
|
|
}}>
|
|
|
|
|
<WebView
|
|
|
|
|
onLoad={onPrimaryWebViewLoad}
|
|
|
|
|
ref={primaryWebView}
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
2021-10-06 10:29:07 +05:00
|
|
|
backgroundColor: 'transparent'
|
2020-09-09 11:10:35 +05:00
|
|
|
}}
|
|
|
|
|
onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}
|
|
|
|
|
cacheMode="LOAD_DEFAULT"
|
|
|
|
|
domStorageEnabled={true}
|
2021-05-20 11:05:03 +05:00
|
|
|
scrollEnabled={true}
|
2020-09-09 11:10:35 +05:00
|
|
|
bounces={false}
|
|
|
|
|
allowFileAccess={true}
|
|
|
|
|
scalesPageToFit={true}
|
|
|
|
|
allowingReadAccessToURL={Platform.OS === 'android' ? true : null}
|
|
|
|
|
allowFileAccessFromFileURLs={true}
|
|
|
|
|
allowUniversalAccessFromFileURLs={true}
|
|
|
|
|
originWhitelist={['*']}
|
|
|
|
|
javaScriptEnabled={true}
|
|
|
|
|
cacheEnabled={true}
|
2021-07-08 09:34:21 +05:00
|
|
|
source={{
|
2021-10-30 14:01:21 +05:00
|
|
|
uri: sourceUri + 'plaineditor.html'
|
2021-07-08 09:34:21 +05:00
|
|
|
}}
|
2020-09-09 11:10:35 +05:00
|
|
|
/>
|
|
|
|
|
</Animated.View>
|
2020-03-26 13:39:04 +05:00
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-09 11:10:35 +05:00
|
|
|
width: '100%',
|
|
|
|
|
height: 50,
|
2020-03-26 13:39:04 +05:00
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
2020-09-09 11:10:35 +05:00
|
|
|
alignItems: 'center',
|
2021-10-06 10:29:07 +05:00
|
|
|
paddingHorizontal: 12
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2020-09-09 11:10:35 +05:00
|
|
|
<View
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'space-between',
|
2021-10-06 10:29:07 +05:00
|
|
|
flexShrink: 1
|
2020-03-26 13:39:04 +05:00
|
|
|
}}>
|
2021-10-06 10:29:07 +05:00
|
|
|
<Paragraph
|
|
|
|
|
style={{flexWrap: 'wrap'}}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
size={SIZE.xs}>
|
|
|
|
|
<Text style={{color: 'red', fontWeight: 'bold'}}>
|
|
|
|
|
(Incoming)
|
|
|
|
|
</Text>
|
|
|
|
|
{'\n'}
|
|
|
|
|
{timeConverter(secondaryData?.dateEdited)}
|
|
|
|
|
</Paragraph>
|
2020-09-09 11:10:35 +05:00
|
|
|
</View>
|
2020-03-26 13:39:04 +05:00
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
2021-10-06 10:29:07 +05:00
|
|
|
justifyContent: 'flex-end'
|
2020-09-09 11:10:35 +05:00
|
|
|
}}>
|
|
|
|
|
{keepContentFrom === 'primary' ? (
|
|
|
|
|
<Button
|
2021-10-06 10:29:07 +05:00
|
|
|
height={30}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
minWidth: 60
|
|
|
|
|
}}
|
|
|
|
|
type="accent"
|
2021-12-16 10:20:34 +05:00
|
|
|
fontSize={SIZE.xs}
|
2020-09-09 11:10:35 +05:00
|
|
|
onPress={onPressSaveCopyFromSecondaryWebView}
|
2021-10-06 10:29:07 +05:00
|
|
|
title="Save a copy"
|
2020-09-09 11:10:35 +05:00
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
<View style={{width: 10}} />
|
|
|
|
|
{keepContentFrom === 'primary' ? (
|
|
|
|
|
<Button
|
|
|
|
|
title="Discard"
|
2021-01-05 10:20:16 +05:00
|
|
|
type="accent"
|
2021-10-06 10:29:07 +05:00
|
|
|
height={30}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
minWidth: 60
|
|
|
|
|
}}
|
2021-12-16 10:20:34 +05:00
|
|
|
fontSize={SIZE.xs}
|
2021-01-05 10:20:16 +05:00
|
|
|
accentColor="red"
|
|
|
|
|
accentText="light"
|
2020-09-09 11:10:35 +05:00
|
|
|
onPress={onPressDiscardFromSecondaryWebView}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2021-01-13 16:32:35 +05:00
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
{keepContentFrom === 'primary' ? null : (
|
2021-01-13 16:32:35 +05:00
|
|
|
<>
|
|
|
|
|
<Button
|
2021-10-06 10:29:07 +05:00
|
|
|
type="grayBg"
|
|
|
|
|
title="Load images"
|
|
|
|
|
height={30}
|
|
|
|
|
loading={loadingAttachments}
|
|
|
|
|
fontSize={SIZE.xs}
|
|
|
|
|
icon="download"
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
minWidth: 60
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
height={30}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
minWidth: 60,
|
|
|
|
|
marginLeft: 10
|
|
|
|
|
}}
|
|
|
|
|
type="accent"
|
2021-12-16 10:20:34 +05:00
|
|
|
fontSize={SIZE.xs}
|
2021-01-13 16:32:35 +05:00
|
|
|
title={keepContentFrom === 'secondary' ? 'Undo' : 'Keep'}
|
|
|
|
|
onPress={onPressKeepFromSecondaryWebView}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2020-09-09 11:10:35 +05:00
|
|
|
)}
|
|
|
|
|
</View>
|
2020-03-26 13:39:04 +05:00
|
|
|
</View>
|
|
|
|
|
|
2020-09-09 11:10:35 +05:00
|
|
|
<Animated.View
|
2020-03-26 13:39:04 +05:00
|
|
|
style={{
|
2021-10-06 10:29:07 +05:00
|
|
|
height: dHeight / 2 - (50 + insets.top / 2),
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
borderRadius: 10
|
2020-09-09 11:10:35 +05:00
|
|
|
}}>
|
|
|
|
|
<WebView
|
|
|
|
|
onLoad={onSecondaryWebViewLoad}
|
|
|
|
|
ref={secondaryWebView}
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
2021-10-06 10:29:07 +05:00
|
|
|
backgroundColor: 'transparent'
|
2020-09-09 11:10:35 +05:00
|
|
|
}}
|
|
|
|
|
onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}
|
|
|
|
|
cacheMode="LOAD_DEFAULT"
|
|
|
|
|
domStorageEnabled={true}
|
2021-05-20 11:05:03 +05:00
|
|
|
scrollEnabled={true}
|
2020-09-09 11:10:35 +05:00
|
|
|
bounces={false}
|
|
|
|
|
allowFileAccess={true}
|
|
|
|
|
scalesPageToFit={true}
|
|
|
|
|
allowingReadAccessToURL={Platform.OS === 'android' ? true : null}
|
|
|
|
|
allowFileAccessFromFileURLs={true}
|
|
|
|
|
allowUniversalAccessFromFileURLs={true}
|
|
|
|
|
originWhitelist={['*']}
|
|
|
|
|
javaScriptEnabled={true}
|
|
|
|
|
cacheEnabled={true}
|
2021-07-08 09:34:21 +05:00
|
|
|
source={{
|
2021-10-30 14:01:21 +05:00
|
|
|
uri: sourceUri + 'plaineditor.html'
|
2021-07-08 09:34:21 +05:00
|
|
|
}}
|
2020-09-09 11:10:35 +05:00
|
|
|
/>
|
|
|
|
|
</Animated.View>
|
|
|
|
|
</View>
|
|
|
|
|
</SafeAreaView>
|
2020-03-26 13:39:04 +05:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default MergeEditor;
|