A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
add merging
ammarahm-ed4d7af5c3ac08
diff --git a/apps/mobile/android/app/src/main/assets/plaineditor.html b/apps/mobile/android/app/src/main/assets/plaineditor.htmlindex 01e4424bd..5d9151ac4 100644--- a/apps/mobile/android/app/src/main/assets/plaineditor.html+++ b/apps/mobile/android/app/src/main/assets/plaineditor.html@@ -1127,7 +1127,7 @@imageType: 'image/jpeg'},},- placeholder: 'Start writing your note',+ placeholder: ' ',});@@ -1447,12 +1447,7 @@setTheme();- editor.once('text-change', function () {-- window.ReactNativeWebView.postMessage("loaded");--- });+// Receber mensagens do RNdiff --git a/apps/mobile/html/Web.bundle/site/plaineditor.html b/apps/mobile/html/Web.bundle/site/plaineditor.htmlindex 211c2834b..38658fa33 100644--- a/apps/mobile/html/Web.bundle/site/plaineditor.html+++ b/apps/mobile/html/Web.bundle/site/plaineditor.html@@ -1127,7 +1127,7 @@imageType: 'image/jpeg'},},- placeholder: 'Start writing your note',+ placeholder: ' ',});diff --git a/apps/mobile/src/components/MergeEditor/index.js b/apps/mobile/src/components/MergeEditor/index.jsindex 83e71c331..722504c9a 100644--- a/apps/mobile/src/components/MergeEditor/index.js+++ b/apps/mobile/src/components/MergeEditor/index.js@@ -1,19 +1,15 @@-import React, {useState, createRef, useEffect} from 'react';-import {Modal, View, TouchableOpacity, Text} from 'react-native';+import React, {createRef, useEffect, useState} from 'react';+import {Modal, Text, TouchableOpacity, View} from 'react-native';+import Animated, {Easing} from 'react-native-reanimated';+import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import WebView from 'react-native-webview';-import {h, getElevation} from '../../utils/utils';+import {normalize, SIZE, WEIGHT} from '../../common/common';import {useTracked} from '../../provider';-import {SIZE, WEIGHT, normalize} from '../../common/common';-import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import Animated, {Easing} from 'react-native-reanimated';-import {- eSubscribeEvent,- eUnSubscribeEvent,- eSendEvent,-} from '../../services/eventManager';-import {eApplyChanges, eOpenSimpleDialog} from '../../services/events';-import {TEMPLATE_APPLY_CHANGES} from '../DialogManager/templates';+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager';+import {eApplyChanges, eShowMergeDialog} from '../../services/events';+import {getElevation, h, db} from '../../utils/utils';import {simpleDialogEvent} from '../DialogManager/recievers';+import {TEMPLATE_APPLY_CHANGES} from '../DialogManager/templates';const {Value, timing} = Animated;const firstWebViewHeight = new Value(h * 0.5 - 50);@@ -21,8 +17,9 @@ const secondWebViewHeight = new Value(h * 0.5 - 50);const primaryWebView = createRef();const secondaryWebView = createRef();+let note = null;-export function openEditorAnimation(+function openEditorAnimation(heightToAnimate,extendedHeight = null,siblingStatus,@@ -45,7 +42,7 @@ export function openEditorAnimation(timing(heightToAnimate, openConfig).start();}-export function closeEditorAnimation(heightToAnimate, heightToExtend = null) {+function closeEditorAnimation(heightToAnimate, heightToExtend = null) {let closeConfig = {duration: 300,toValue: 0,@@ -65,15 +62,15 @@ export function closeEditorAnimation(heightToAnimate, heightToExtend = null) {}let primaryDelta = null;-let primaryText = 'Hello world, I am primary text conflict';+let primaryText = '';let secondaryDelta = null;-let secondaryText = 'Hello world, I am secondary text confilict';+let secondaryText = '';const MergeEditor = () => {const [state, dispatch] = useTracked();const {colors} = state;- const [visible, setVisible] = useState(true);+ const [visible, setVisible] = useState(false);const [primary, setPrimary] = useState(true);const [secondary, setSecondary] = useState(true);const [keepContentFrom, setKeepContentFrom] = useState(null);@@ -88,8 +85,8 @@ const MergeEditor = () => {const onPrimaryWebViewLoad = () => {postMessageToPrimaryWebView({- type: 'text',- value: primaryText,+ type: 'delta',+ value: primaryDelta,});let c = {...colors};c.factor = normalize(1);@@ -101,8 +98,8 @@ const MergeEditor = () => {const onSecondaryWebViewLoad = () => {postMessageToSecondaryWebView({- type: 'text',- value: secondaryText,+ type: 'delta',+ value: secondaryDelta,});let c = {...colors};c.factor = normalize(1);@@ -122,11 +119,7 @@ const MergeEditor = () => {};const onMessageFromPrimaryWebView = evt => {- if (evt.nativeEvent.data === 'loaded') {- } else if (- evt.nativeEvent.data !== '' &&- evt.nativeEvent.data !== 'loaded'- ) {+ if (evt.nativeEvent.data !== '') {let data = JSON.parse(evt.nativeEvent.data);primaryDelta = data.delta;primaryText = data.text;@@ -134,11 +127,7 @@ const MergeEditor = () => {};const onMessageFromSecondaryWebView = evt => {- if (evt.nativeEvent.data === 'loaded') {- } else if (- evt.nativeEvent.data !== '' &&- evt.nativeEvent.data !== 'loaded'- ) {+ if (evt.nativeEvent.data !== '') {let data = JSON.parse(evt.nativeEvent.data);secondaryDelta = data.delta;secondaryText = data.text;@@ -146,15 +135,69 @@ const MergeEditor = () => {}};- const applyChanges = () => {- alert('hello');+ const applyChanges = async () => {+ if (keepContentFrom === 'primary') {+ await db.notes.add({+ content: {+ text: primaryText,+ delta: primaryDelta,+ },+ id: note.id,+ });+ } else {+ await db.notes.add({+ content: {+ text: secondaryText,+ delta: secondaryDelta,+ },+ id: note.id,+ });+ }++ if (copyToSave === 'primary') {+ await db.notes.add({+ content: {+ text: primaryText,+ delta: primaryDelta,+ },+ id: null,+ });+ } else {+ await db.notes.add({+ content: {+ text: secondaryText,+ delta: secondaryDelta,+ },+ id: null,+ });+ }++ close();+ };++ const show = async item => {+ note = item;+ primaryDelta = await db.notes.note(note.id).delta();+ secondaryDelta = await db.notes.note(note.id).delta();+ setVisible(true);+ postMessageToPrimaryWebView({+ type: 'delta',+ value: primaryDelta,+ });+ postMessageToSecondaryWebView({+ type: 'delta',+ value: secondaryDelta,+ });++ openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true);};useEffect(() => {eSubscribeEvent(eApplyChanges, applyChanges);-+ eSubscribeEvent(eShowMergeDialog, show);return () => {eUnSubscribeEvent(eApplyChanges, applyChanges);+ eUnSubscribeEvent(eShowMergeDialog, show);};});@@ -198,6 +241,21 @@ const MergeEditor = () => {simpleDialogEvent(TEMPLATE_APPLY_CHANGES);};+ const close = () => {+ setVisible(false);+ setPrimary(true);+ setSecondary(true);+ setCopyToSave(null);+ setDiscardedContent(null);+ setKeepContentFrom(null);+ primaryDelta = null;+ secondaryDelta = null;+ primaryText = null;+ secondaryText = null;+ note = null;+ openEditorAnimation(firstWebViewHeight, secondWebViewHeight, true);+ };+const params = 'platform=' + Platform.OS;const sourceUri =(Platform.OS === 'android' ? 'file:///android_asset/' : '') +@@ -240,6 +298,7 @@ const MergeEditor = () => {textAlignVertical: 'center',marginLeft: -8,}}+ onPress={close}size={SIZE.xxl}name="chevron-left"/>diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.jsindex 6a880c298..0a8522d8d 100644--- a/apps/mobile/src/components/NoteItem/index.js+++ b/apps/mobile/src/components/NoteItem/index.js@@ -3,7 +3,7 @@ import {Dimensions, Text, TouchableOpacity, View} from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import {ph, pv, SIZE, WEIGHT} from '../../common/common';import {eSendEvent, openVault} from '../../services/eventManager';-import {eOnLoadNote} from '../../services/events';+import {eOnLoadNote, eShowMergeDialog} from '../../services/events';import {openEditorAnimation} from '../../utils/animations';import {DDS, timeSince} from '../../utils/utils';import {ActionSheetEvent, simpleDialogEvent} from '../DialogManager/recievers';@@ -86,6 +86,8 @@ export default class NoteItem extends React.Component {activeOpacity={0.8}onLongPress={() => onLongPress()}onPress={() => {+ eSendEvent(eShowMergeDialog, item);+ return;if (this.props.selectionMode) {this.props.onLongPress();return;diff --git a/apps/mobile/src/services/events.js b/apps/mobile/src/services/events.jsindex 84327ada9..3147756c5 100644--- a/apps/mobile/src/services/events.js+++ b/apps/mobile/src/services/events.js@@ -69,3 +69,5 @@ export const eClearSearch = '533';export const eClearEditor = '534';export const eApplyChanges = '535';++export const eShowMergeDialog = '536';