mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
fix merge editor
This commit is contained in:
@@ -30,6 +30,7 @@ import {updateEvent} from '../DialogManager/recievers';
|
|||||||
import Paragraph from '../Typography/Paragraph';
|
import Paragraph from '../Typography/Paragraph';
|
||||||
import KeepAwake from '@sayem314/react-native-keep-awake';
|
import KeepAwake from '@sayem314/react-native-keep-awake';
|
||||||
import {timeConverter} from '../../utils/TimeUtils';
|
import {timeConverter} from '../../utils/TimeUtils';
|
||||||
|
import tiny from '../../views/Editor/tiny/tiny';
|
||||||
|
|
||||||
const {Value, timing} = Animated;
|
const {Value, timing} = Animated;
|
||||||
|
|
||||||
@@ -87,6 +88,7 @@ function closeEditorAnimation(heightToAnimate, heightToExtend = null, insets) {
|
|||||||
let primaryData = null;
|
let primaryData = null;
|
||||||
|
|
||||||
let secondaryData = null;
|
let secondaryData = null;
|
||||||
|
|
||||||
const MergeEditor = () => {
|
const MergeEditor = () => {
|
||||||
const [state, dispatch] = useTracked();
|
const [state, dispatch] = useTracked();
|
||||||
const {colors} = state;
|
const {colors} = state;
|
||||||
@@ -99,36 +101,19 @@ const MergeEditor = () => {
|
|||||||
const [dialogVisible, setDialogVisible] = useState(false);
|
const [dialogVisible, setDialogVisible] = useState(false);
|
||||||
|
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
const postMessageToPrimaryWebView = (message) =>
|
|
||||||
primaryWebView.current?.postMessage(JSON.stringify(message));
|
|
||||||
|
|
||||||
const postMessageToSecondaryWebView = (message) =>
|
|
||||||
secondaryWebView.current?.postMessage(JSON.stringify(message));
|
|
||||||
|
|
||||||
const onPrimaryWebViewLoad = () => {
|
const onPrimaryWebViewLoad = () => {
|
||||||
postMessageToPrimaryWebView({
|
tiny.call(primaryWebView, tiny.html(primaryData.data), true);
|
||||||
type: 'delta',
|
let theme = {...colors};
|
||||||
value: primaryData.data,
|
theme.factor = normalize(1);
|
||||||
});
|
tiny.call(primaryWebView, tiny.updateTheme(JSON.stringify(theme)), true);
|
||||||
let c = {...colors};
|
|
||||||
c.factor = normalize(1);
|
|
||||||
postMessageToPrimaryWebView({
|
|
||||||
type: 'theme',
|
|
||||||
value: c,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSecondaryWebViewLoad = () => {
|
const onSecondaryWebViewLoad = () => {
|
||||||
postMessageToSecondaryWebView({
|
tiny.call(secondaryWebView, tiny.html(secondaryData.data), true);
|
||||||
type: 'delta',
|
let theme = {...colors};
|
||||||
value: secondaryData.data,
|
theme.factor = normalize(1);
|
||||||
});
|
tiny.call(secondaryWebView, tiny.updateTheme(JSON.stringify(theme)), true);
|
||||||
let c = {...colors};
|
|
||||||
c.factor = normalize(1);
|
|
||||||
postMessageToSecondaryWebView({
|
|
||||||
type: 'theme',
|
|
||||||
value: c,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const _onShouldStartLoadWithRequest = (request) => {
|
const _onShouldStartLoadWithRequest = (request) => {
|
||||||
@@ -144,8 +129,11 @@ const MergeEditor = () => {
|
|||||||
if (evt.nativeEvent.data !== '') {
|
if (evt.nativeEvent.data !== '') {
|
||||||
let data = JSON.parse(evt.nativeEvent.data);
|
let data = JSON.parse(evt.nativeEvent.data);
|
||||||
|
|
||||||
if (data.type === 'delta') {
|
if (data.type === 'tiny') {
|
||||||
primaryData = data.data;
|
primaryData = {
|
||||||
|
type: 'tiny',
|
||||||
|
data: data.value,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -153,8 +141,11 @@ const MergeEditor = () => {
|
|||||||
const onMessageFromSecondaryWebView = (evt) => {
|
const onMessageFromSecondaryWebView = (evt) => {
|
||||||
if (evt.nativeEvent.data === '') {
|
if (evt.nativeEvent.data === '') {
|
||||||
let data = JSON.parse(evt.nativeEvent.data);
|
let data = JSON.parse(evt.nativeEvent.data);
|
||||||
if (data.type === 'delta') {
|
if (data.type === 'tiny') {
|
||||||
secondaryData = data.data;
|
secondaryData = {
|
||||||
|
type: 'tiny',
|
||||||
|
data: data.value,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -214,7 +205,7 @@ const MergeEditor = () => {
|
|||||||
let noteData = await db.content.raw(note.contentId);
|
let noteData = await db.content.raw(note.contentId);
|
||||||
|
|
||||||
switch (noteData.type) {
|
switch (noteData.type) {
|
||||||
case 'delta':
|
case 'tiny':
|
||||||
primaryData = noteData;
|
primaryData = noteData;
|
||||||
secondaryData = noteData.conflicted;
|
secondaryData = noteData.conflicted;
|
||||||
}
|
}
|
||||||
@@ -465,7 +456,7 @@ const MergeEditor = () => {
|
|||||||
<Animated.View
|
<Animated.View
|
||||||
style={{
|
style={{
|
||||||
height: firstWebViewHeight,
|
height: firstWebViewHeight,
|
||||||
backgroundColor:colors.bg
|
backgroundColor: colors.bg,
|
||||||
}}>
|
}}>
|
||||||
<WebView
|
<WebView
|
||||||
onLoad={onPrimaryWebViewLoad}
|
onLoad={onPrimaryWebViewLoad}
|
||||||
@@ -473,7 +464,7 @@ const MergeEditor = () => {
|
|||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
backgroundColor:'transparent'
|
backgroundColor: 'transparent',
|
||||||
}}
|
}}
|
||||||
injectedJavaScript={Platform.OS === 'ios' ? injectedJS : null}
|
injectedJavaScript={Platform.OS === 'ios' ? injectedJS : null}
|
||||||
onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}
|
onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}
|
||||||
@@ -616,7 +607,7 @@ const MergeEditor = () => {
|
|||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
backgroundColor:'transparent'
|
backgroundColor: 'transparent',
|
||||||
}}
|
}}
|
||||||
injectedJavaScript={Platform.OS === 'ios' ? injectedJS : null}
|
injectedJavaScript={Platform.OS === 'ios' ? injectedJS : null}
|
||||||
onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}
|
onShouldStartLoadWithRequest={_onShouldStartLoadWithRequest}
|
||||||
|
|||||||
Reference in New Issue
Block a user