Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

refactoring

ammarahm-edfb11d43c9100
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 5de7dc859..d82001ca3 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -2,7 +2,6 @@ import Storage from 'notes-core/api/database';
import React, {useEffect, useState} from 'react';
import {Dimensions, Platform, StatusBar, View} from 'react-native';
import * as Animatable from 'react-native-animatable';
-import Animated from 'react-native-reanimated';
import {getColorScheme} from './src/common/common';
import {
DialogManager,
@@ -23,22 +22,18 @@ import StorageInterface from './src/utils/storage';
import {w} from './src/utils/utils';
import Editor from './src/views/Editor';
import {eSubscribeEvent, eUnSubscribeEvent} from './src/services/eventManager';
-import {eDispatchAction} from './src/services/events';
+import {
+ eDispatchAction,
+ eOpenSideMenu,
+ eCloseSideMenu,
+ eDisableGestures,
+ eEnableGestures,
+ eOpenFullscreenEditor,
+ eCloseFullscreenEditor,
+} from './src/services/events';
export const DDS = new DeviceDetectionService();
export const db = new Storage(StorageInterface);
-const {
- Clock,
- Value,
- set,
- cond,
- startClock,
- clockRunning,
- timing,
- debug,
- stopClock,
- block,
-} = Animated;
let sideMenuRef;
let editorRef;
@@ -70,24 +65,24 @@ const App = () => {
};
useEffect(() => {
- _recieveEvent('openSidebar', openSidebar);
- _recieveEvent('closeSidebar', closeSidebar);
+ eSubscribeEvent(eOpenSideMenu, openSidebar);
+ eSubscribeEvent(eCloseSideMenu, closeSidebar);
- _recieveEvent('disableGesture', disableGestures);
- _recieveEvent('enableGesture', enableGestures);
+ eSubscribeEvent(eDisableGestures, disableGestures);
+ eSubscribeEvent(eEnableGestures, enableGestures);
- _recieveEvent('showFullScreenEditor', showFullScreenEditor);
- _recieveEvent('closeFullScreenEditor', closeFullScreenEditor);
+ eSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor);
+ eSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor);
return () => {
- _unSubscribeEvent('showFullScreenEditor', showFullScreenEditor);
- _unSubscribeEvent('closeFullScreenEditor', closeFullScreenEditor);
+ eUnSubscribeEvent(eOpenFullscreenEditor, showFullScreenEditor);
+ eUnSubscribeEvent(eCloseFullscreenEditor, closeFullScreenEditor);
- _unSubscribeEvent('openSidebar', openSidebar);
- _unSubscribeEvent('closeSidebar', closeSidebar);
+ eUnSubscribeEvent(eOpenSideMenu, openSidebar);
+ eUnSubscribeEvent(eCloseSideMenu, closeSidebar);
- _unSubscribeEvent('disableGesture', disableGestures);
- _unSubscribeEvent('enableGesture', enableGestures);
+ eUnSubscribeEvent(eDisableGestures, disableGestures);
+ eUnSubscribeEvent(eEnableGestures, enableGestures);
};
}, []);
@@ -99,6 +94,7 @@ const App = () => {
width: '100%',
zIndex: 999,
paddingHorizontal: 100,
+ backgroundColor: colors.bg,
},
});
};
@@ -111,6 +107,7 @@ const App = () => {
width: '68%',
zIndex: null,
paddingHorizontal: 0,
+ backgroundColor: 'transparent',
},
});
};
@@ -164,9 +161,6 @@ const App = () => {
height: '100%',
flexDirection: 'row',
backgroundColor: colors.bg,
- }}
- onLayout={e => {
- setWidth(Dimensions.get('window').width);
}}>
{DDS.isTab ? (
<>
diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js
index 0884ee843..efa17e6ff 100644
--- a/apps/mobile/src/components/LoginDialog/index.js
+++ b/apps/mobile/src/components/LoginDialog/index.js
@@ -10,6 +10,8 @@ import Signup from '../../views/Signup';
import ForgotPassword from '../../views/ForgotPassword';
import {DDS} from '../../../App';
import {getElevation} from '../../utils/utils';
+import {eSendEvent} from '../../services/eventManager';
+import {eLoginDialogNavigateBack} from '../../services/events';
const fade = props => {
const {position, scene} = props;
@@ -104,7 +106,7 @@ class LoginDialog extends React.Component {
updateEvent({type: ACTIONS.LOGIN_NAVIGATOR, enabled: false});
this.close();
} else {
- DeviceEventEmitter.emit('goLoginBack');
+ eSendEvent(eLoginDialogNavigateBack);
}
}}
visible={visible}
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index 701a3c772..780490278 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -12,6 +12,8 @@ import {ph, pv, SIZE, WEIGHT} from '../../common/common';
import NavigationService from '../../services/NavigationService';
import {getElevation, timeSince} from '../../utils/utils';
import {ActionSheetEvent} from '../DialogManager';
+import {eSendEvent} from '../../services/eventManager';
+import {eOnLoadNote} from '../../services/events';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
@@ -114,7 +116,7 @@ export default class NoteItem extends React.Component {
});
} else {
DDS.isTab
- ? DeviceEventEmitter.emit('loadNoteEvent', item)
+ ? eSendEvent(eOnLoadNote, item)
: NavigationService.navigate('Editor', {
note: item,
});
diff --git a/apps/mobile/src/services/events.js b/apps/mobile/src/services/events.js
index f353a1cf5..eeccd63d5 100644
--- a/apps/mobile/src/services/events.js
+++ b/apps/mobile/src/services/events.js
@@ -25,3 +25,17 @@ export const eOpenLoginDialog = '511';
export const eCloseLoginDialog = '512';
export const eDispatchAction = '513';
+
+export const eLoginDialogNavigateBack = '514';
+
+export const eOpenSideMenu = '515';
+
+export const eCloseSideMenu = '516';
+
+export const eOpenFullscreenEditor = '517';
+
+export const eCloseFullscreenEditor = '518';
+
+export const eEnableGestures = '519';
+
+export const eDisableGestures = '520';
diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.js
index c7ddd702c..9e07e697c 100755
--- a/apps/mobile/src/utils/utils.js
+++ b/apps/mobile/src/utils/utils.js
@@ -1,4 +1,11 @@
import {DeviceEventEmitter, Dimensions} from 'react-native';
+import {eSendEvent} from '../services/eventManager';
+import {
+ eOpenSideMenu,
+ eCloseSideMenu,
+ eDisableGestures,
+ eEnableGestures,
+} from '../services/events';
export const getElevation = elevation => {
return {
elevation,
@@ -62,15 +69,15 @@ export const ToastEvent = {
export const SideMenuEvent = {
open: () => {
- DeviceEventEmitter.emit('openSidebar');
+ eSendEvent(eOpenSideMenu);
},
close: () => {
- DeviceEventEmitter.emit('closeSidebar');
+ eSendEvent(eCloseSideMenu);
},
disable: () => {
- DeviceEventEmitter.emit('disableGesture');
+ eSendEvent(eDisableGestures);
},
enable: () => {
- DeviceEventEmitter.emit('enableGesture');
+ eSendEvent(eEnableGestures);
},
};
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index 8f8570e14..8344702dc 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -28,6 +28,16 @@ import {ACTIONS} from '../../provider/actions';
import {SideMenuEvent, w, h} from '../../utils/utils';
import {AnimatedSafeAreaView} from '../Home';
import * as Animatable from 'react-native-animatable';
+import {
+ eSendEvent,
+ eSubscribeEvent,
+ eUnSubscribeEvent,
+} from '../../services/eventManager';
+import {
+ eCloseFullscreenEditor,
+ eOpenFullscreenEditor,
+ eOnLoadNote,
+} from '../../services/events';
const AnimatedKeyboardAvoidingView = Animatable.createAnimatableComponent(
KeyboardAvoidingView,
@@ -51,10 +61,10 @@ const Editor = ({navigation, noMenu}) => {
const post = value => EditorWebView.postMessage(value);
useEffect(() => {
- _recieveEvent('loadNoteEvent', loadNote);
+ eSubscribeEvent(eOnLoadNote, loadNote);
return () => {
- _unSubscribeEvent('loadNoteEvent', loadNote);
+ eUnSubscribeEvent(eOnLoadNote, loadNote);
};
}, []);
@@ -334,8 +344,8 @@ const Editor = ({navigation, noMenu}) => {
<TouchableOpacity
onPress={() => {
if (fullscreen) {
- DeviceEventEmitter.emit('closeFullScreenEditor');
fullscreen = false;
+ eSendEvent(eCloseFullscreenEditor);
post(
JSON.stringify({
type: 'nomenu',
@@ -343,7 +353,7 @@ const Editor = ({navigation, noMenu}) => {
}),
);
} else {
- DeviceEventEmitter.emit('showFullScreenEditor');
+ eSendEvent(eOpenFullscreenEditor);
fullscreen = true;
post(
JSON.stringify({
diff --git a/apps/mobile/src/views/ForgotPassword/index.js b/apps/mobile/src/views/ForgotPassword/index.js
index 1138631a7..1e0946527 100644
--- a/apps/mobile/src/views/ForgotPassword/index.js
+++ b/apps/mobile/src/views/ForgotPassword/index.js
@@ -14,6 +14,8 @@ import {Header} from '../../components/header';
import {useTracked} from '../../provider';
import {_recieveEvent, _unSubscribeEvent} from '../../components/DialogManager';
import {useIsFocused} from 'react-navigation-hooks';
+import {eLoginDialogNavigateBack} from '../../services/events';
+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager';
export const ForgotPassword = ({navigation}) => {
const [state, dispatch] = useTracked();
@@ -33,9 +35,9 @@ export const ForgotPassword = ({navigation}) => {
};
useEffect(() => {
- _recieveEvent('goBack', handleBackPress);
+ eSubscribeEvent(eLoginDialogNavigateBack, handleBackPress);
return () => {
- _unSubscribeEvent('goBack', handleBackPress);
+ eUnSubscribeEvent(eLoginDialogNavigateBack, handleBackPress);
};
}, [isFocused]);
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 25ddffdb2..674feb5c3 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -104,7 +104,7 @@ export const Home = ({navigation}) => {
dispatch({type: ACTIONS.NOTES});
if (DDS.isTab) {
- DeviceEventEmitter.emit('loadNoteEvent', {type: 'new'});
+ eSendEvent(eOnLoadNote, {type: 'new'});
} else {
SideMenuEvent.close();
SideMenuEvent.disable();
diff --git a/apps/mobile/src/views/Signup/index.js b/apps/mobile/src/views/Signup/index.js
index 3aa2b88bf..7b1380717 100644
--- a/apps/mobile/src/views/Signup/index.js
+++ b/apps/mobile/src/views/Signup/index.js
@@ -15,6 +15,7 @@ import {useTracked} from '../../provider';
import {useIsFocused} from 'react-navigation-hooks';
import {_recieveEvent, _unSubscribeEvent} from '../../components/DialogManager';
import {eUnSubscribeEvent, eSubscribeEvent} from '../../services/eventManager';
+import {eLoginDialogNavigateBack} from '../../services/events';
export const Signup = ({navigation}) => {
const [state, dispatch] = useTracked();
@@ -40,9 +41,9 @@ export const Signup = ({navigation}) => {
};
useEffect(() => {
- eSubscribeEvent('goLoginBack', handleBackPress);
+ eSubscribeEvent(eLoginDialogNavigateBack, handleBackPress);
return () => {
- eUnSubscribeEvent('goLoginBack', handleBackPress);
+ eUnSubscribeEvent(eLoginDialogNavigateBack, handleBackPress);
};
}, [isFocused]);