fix merge dialog applyChanges not working

This commit is contained in:
ammarahm-ed
2020-11-29 13:23:46 +05:00
parent 9cfcea0b4e
commit c0cbf32a57
2 changed files with 40 additions and 14 deletions

View File

@@ -12,17 +12,20 @@ import {
eSubscribeEvent, eSubscribeEvent,
eUnSubscribeEvent, eUnSubscribeEvent,
} from '../../services/EventManager'; } from '../../services/EventManager';
import {dHeight} from '../../utils'; import {dHeight, getElevation} from '../../utils';
import {db} from '../../utils/DB'; import {db} from '../../utils/DB';
import { import {
eApplyChanges, eApplyChanges,
eShowMergeDialog, eShowMergeDialog,
refreshNotesPage, refreshNotesPage,
} from '../../utils/Events'; } from '../../utils/Events';
import {normalize, SIZE} from '../../utils/SizeUtils'; import {normalize, ph, pv, SIZE} from '../../utils/SizeUtils';
import {Button} from '../Button'; import {Button} from '../Button';
import {simpleDialogEvent, updateEvent} from '../DialogManager/recievers'; import BaseDialog from '../Dialog/base-dialog';
import {TEMPLATE_APPLY_CHANGES} from '../DialogManager/Templates'; import DialogButtons from '../Dialog/dialog-buttons';
import DialogContainer from '../Dialog/dialog-container';
import DialogHeader from '../Dialog/dialog-header';
import {updateEvent} from '../DialogManager/recievers';
import Paragraph from '../Typography/Paragraph'; import Paragraph from '../Typography/Paragraph';
const {Value, timing} = Animated; const {Value, timing} = Animated;
@@ -90,6 +93,7 @@ const MergeEditor = () => {
const [keepContentFrom, setKeepContentFrom] = useState(null); const [keepContentFrom, setKeepContentFrom] = useState(null);
const [copyToSave, setCopyToSave] = useState(null); const [copyToSave, setCopyToSave] = useState(null);
const [disardedContent, setDiscardedContent] = useState(null); const [disardedContent, setDiscardedContent] = useState(null);
const [dialogVisible, setDialogVisible] = useState(false);
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
const postMessageToPrimaryWebView = (message) => const postMessageToPrimaryWebView = (message) =>
@@ -157,6 +161,7 @@ const MergeEditor = () => {
}; };
const applyChanges = async () => { const applyChanges = async () => {
console.log(keepContentFrom, copyToSave);
if (keepContentFrom === 'primary') { if (keepContentFrom === 'primary') {
await db.notes.add({ await db.notes.add({
content: { content: {
@@ -205,15 +210,15 @@ const MergeEditor = () => {
const show = async (item) => { const show = async (item) => {
note = item; note = item;
db.content; db.content;
let note = await db.content.raw(note.contentId); let noteData = await db.content.raw(note.contentId);
switch (note.type) { switch (noteData.type) {
case 'delta': case 'delta':
primaryData = note; primaryData = noteData;
secondaryData = note; secondaryData = noteData;
} }
setVisible(true); setVisible(true);
firstWebViewHeight.setValue((dHeight / 2) - (50 + insets.top / 2)); firstWebViewHeight.setValue(dHeight / 2 - (50 + insets.top / 2));
secondWebViewHeight.setValue((dHeight / 2) - (50 + insets.top / 2)); secondWebViewHeight.setValue(dHeight / 2 - (50 + insets.top / 2));
openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true, insets); openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true, insets);
}; };
@@ -243,7 +248,7 @@ const MergeEditor = () => {
const onPressSaveCopyFromPrimaryWebView = () => { const onPressSaveCopyFromPrimaryWebView = () => {
setCopyToSave('primary'); setCopyToSave('primary');
simpleDialogEvent(TEMPLATE_APPLY_CHANGES); setDialogVisible(true);
}; };
const onPressKeepFromSecondaryWebView = () => { const onPressKeepFromSecondaryWebView = () => {
@@ -263,17 +268,17 @@ const MergeEditor = () => {
const onPressSaveCopyFromSecondaryWebView = () => { const onPressSaveCopyFromSecondaryWebView = () => {
setCopyToSave('secondary'); setCopyToSave('secondary');
simpleDialogEvent(TEMPLATE_APPLY_CHANGES); setDialogVisible(true);
}; };
const onPressDiscardFromPrimaryWebView = () => { const onPressDiscardFromPrimaryWebView = () => {
setDiscardedContent('primary'); setDiscardedContent('primary');
simpleDialogEvent(TEMPLATE_APPLY_CHANGES); setDialogVisible(true);
}; };
const onPressDiscardFromSecondaryWebView = () => { const onPressDiscardFromSecondaryWebView = () => {
setDiscardedContent('secondary'); setDiscardedContent('secondary');
simpleDialogEvent(TEMPLATE_APPLY_CHANGES); setDialogVisible(true);
}; };
const close = () => { const close = () => {
@@ -312,6 +317,23 @@ const MergeEditor = () => {
backgroundColor: colors.nav, backgroundColor: colors.nav,
paddingTop: insets.top, paddingTop: insets.top,
}}> }}>
{dialogVisible && (
<BaseDialog visible={true}>
<DialogContainer>
<DialogHeader
title="Apply Changes"
paragraph="Apply selected changes to note?"
/>
<DialogButtons
positiveTitle="Apply"
negativeTitle="Cancel"
onPressNegative={() => setDialogVisible(false)}
onPressPositive={applyChanges}
/>
</DialogContainer>
</BaseDialog>
)}
<View <View
style={{ style={{
height: '100%', height: '100%',

View File

@@ -35,6 +35,7 @@ export const NoteItemWrapper = ({item, index, isTrash = false}) => {
newNote.title === note.title && newNote.title === note.title &&
newNote.headline === note.headline newNote.headline === note.headline
) { ) {
console.log('returning from here',newNote.headline,note.headline);
return; return;
} }
setNote(newNote); setNote(newNote);
@@ -59,6 +60,9 @@ export const NoteItemWrapper = ({item, index, isTrash = false}) => {
}; };
const onPress = async (event) => { const onPress = async (event) => {
eSendEvent(eShowMergeDialog, note);
return;
if (note.conflicted) { if (note.conflicted) {
eSendEvent(eShowMergeDialog, note); eSendEvent(eShowMergeDialog, note);
return; return;