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
refactor editor
ammarahm-edbf9d2b72e3e6
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 79a455af2..5397eee36 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -33,7 +33,6 @@ import SplashScreen from 'react-native-splash-screen';let firstLoad = true;let note = null;-let syncTimeout = null;const App = () => {const [, dispatch] = useTracked(),[init, setInit] = useState(false),@@ -160,7 +159,7 @@ const App = () => {}dispatch({type: Actions.ALL});setInit(true);- backupData();+ backupData().then(r=> r)setTimeout(() => {if (error) {@@ -174,7 +173,7 @@ const App = () => {async function backupData() {await sleep(1000);- settings = await MMKV.getStringAsync('settings');+ let settings = await MMKV.getStringAsync('settings');settings = JSON.parse(settings);if (await Backup.checkBackupRequired(settings.reminder)) {try {@@ -199,7 +198,7 @@ const App = () => {firstLoad = false;}settings = await MMKV.getStringAsync('settings');- console.log('settings', settings);+if (!settings) {settings = defaultState.settings;await MMKV.setStringAsync('settings', JSON.stringify(settings));diff --git a/apps/mobile/index.mobile.js b/apps/mobile/index.mobile.jsindex 10cd38542..1426bc828 100644--- a/apps/mobile/index.mobile.js+++ b/apps/mobile/index.mobile.js@@ -70,18 +70,9 @@ export const Initialize = () => {elevation: 10,opacity: EditorOpacity,transform: [- {- translateX: EditorPosition,- },{translateY: EditorTranslateY,},- {- scaleX: EditorScale,- },- {- scaleY: EditorScale,- },],}}><Screendiff --git a/apps/mobile/src/components/SimpleList/NoteItemWrapper.js b/apps/mobile/src/components/SimpleList/NoteItemWrapper.jsindex 1255455b5..60e665c56 100644--- a/apps/mobile/src/components/SimpleList/NoteItemWrapper.js+++ b/apps/mobile/src/components/SimpleList/NoteItemWrapper.js@@ -65,7 +65,7 @@ export const NoteItemWrapper = ({dispatch({type: Actions.SELECTED_ITEMS, item: note});};- const onPress = async () => {+ const onPress = async (event) => {if (note.conflicted) {eSendEvent(eShowMergeDialog, note);return;@@ -83,7 +83,7 @@ export const NoteItemWrapper = ({eSendEvent(eOnLoadNote, note);}if (DDS.isPhone || DDS.isSmallTab) {- openEditorAnimation();+ openEditorAnimation(event.nativeEvent);}};diff --git a/apps/mobile/src/navigation/NavigatorStack.js b/apps/mobile/src/navigation/NavigatorStack.jsindex eaeec09c9..a2c14fc77 100644--- a/apps/mobile/src/navigation/NavigatorStack.js+++ b/apps/mobile/src/navigation/NavigatorStack.js@@ -19,7 +19,6 @@ export const NavigatorStack = () => {const [state, dispatch] = useTracked();const {settings} = state;- console.log(settings)return (<Container root={true}><NavigationContainer independent={true} ref={rootNavigatorRef}>@@ -31,7 +30,7 @@ export const NavigatorStack = () => {gestureEnabled: false,cardOverlayEnabled: false,cardShadowEnabled: false,-+}}><Stack.Screen name="Home" component={Home} /><Stack.Screendiff --git a/apps/mobile/src/utils/Animations.js b/apps/mobile/src/utils/Animations.jsindex 66bbf0379..ebb016ffd 100644--- a/apps/mobile/src/utils/Animations.js+++ b/apps/mobile/src/utils/Animations.js@@ -4,21 +4,19 @@ import {editing} from './index';const {Value, timing} = Animated;-export const EditorPosition = new Value(Dimensions.get('window').width * 1.5);+export const EditorPosition = new Value(0);export const EditorScale = new Value(1);export const EditorOpacity = new Value(0);export const EditorTranslateY = new Value(- Dimensions.get('window').height * 0.75,+ Dimensions.get('window').height * 2);export function openEditorAnimation() {- EditorPosition.setValue(Dimensions.get('window').width * 1.5);EditorTranslateY.setValue(Dimensions.get('window').height * 0.75);EditorOpacity.setValue(0);editing.currentlyEditing = true;- EditorPosition.setValue(0);timing(EditorTranslateY, {duration: 200,@@ -33,7 +31,6 @@ export function openEditorAnimation() {}export function exitEditorAnimation() {- EditorPosition.setValue(0);EditorOpacity.setValue(1);EditorTranslateY.setValue(0);editing.currentlyEditing = false;@@ -42,12 +39,10 @@ export function exitEditorAnimation() {duration: 150,toValue: 0,easing: Easing.inOut(Easing.ease),- }).start(() => {- EditorPosition.setValue(Dimensions.get('window').width * 1.5);- });+ }).start();timing(EditorTranslateY, {duration: 200,- toValue: Dimensions.get('window').height * 0.75,+ toValue: Dimensions.get('window').height * 2,easing: Easing.inOut(Easing.ease),}).start();}diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsnew file mode 100644index 000000000..38d4d8866--- /dev/null+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -0,0 +1,261 @@+import React, {createRef, useEffect, useState} from 'react';+import {BackHandler, Keyboard, Platform, StatusBar, View,} from 'react-native';+import {ActionIcon} from '../../components/ActionIcon';+import {ActionSheetEvent, simpleDialogEvent,} from '../../components/DialogManager/recievers';+import {TEMPLATE_EXIT_FULLSCREEN, TEMPLATE_NEW_NOTE,} from '../../components/DialogManager/Templates';+import {useTracked} from '../../provider';+import {eSendEvent, eSubscribeEvent, eUnSubscribeEvent, ToastEvent,} from '../../services/EventManager';+import {eClearEditor, eCloseFullscreenEditor, eOnLoadNote, eOpenFullscreenEditor,} from '../../utils/Events';+import {exitEditorAnimation} from '../../utils/Animations';+import {editing} from '../../utils';+import {+ checkNote,+ clearEditor,+ clearTimer,+ EditorWebView,+ getNote,+ isNotedEdited,+ loadNote,+ post,+ textInput,+} from './Functions';+import {normalize} from '../../utils/SizeUtils';+import {DDS} from '../../services/DeviceDetection';+import HistoryComponent from "./HistoryComponent";++let handleBack;+let tapCount = 0;++const EditorHeader = ({noMenu}) => {+ const [state] = useTracked();+ const {colors, premiumUser} = state;+ const [fullscreen, setFullscreen] = useState(false);++++ useEffect(() => {+ let c = {...colors};+ c.factor = normalize(1);+ post('theme', colors);+ }, [colors.bg]);++ useEffect(() => {+ if (!DDS.isTab) return;+ if (noMenu) {+ post('nomenu', true);+ } else {+ post('nomenu', false);+ }+ }, [noMenu]);++ useEffect(() => {+ eSubscribeEvent(eOnLoadNote, load);+ eSubscribeEvent(eCloseFullscreenEditor, closeFullscreen);+ eSubscribeEvent(eClearEditor, onCallClear);+ Keyboard.addListener("keyboardDidShow",() => {+ post("keyboard")+ })+ return () => {+ eUnSubscribeEvent(eClearEditor, onCallClear);+ eUnSubscribeEvent(eCloseFullscreenEditor, closeFullscreen);+ eUnSubscribeEvent(eOnLoadNote, load);+ Keyboard.removeListener("keyboardDidShow",() => {+ post("keyboard")+ })+ };+ }, []);++ useEffect(() => {+ if (!noMenu && DDS.isTab) {+ handleBack = BackHandler.addEventListener('hardwareBackPress', () => {+ simpleDialogEvent(TEMPLATE_EXIT_FULLSCREEN());+ editing.isFullscreen = false;+ return true;+ });+ }++ return () => {+ clearTimer();+ if (handleBack) {+ handleBack.remove();+ handleBack = null;+ }+ };+ }, [noMenu]);++ const load = async (item) => {+ await loadNote(item);+ if (item.type === 'new') {+ textInput.current?.focus();+ post('focusTitle');+ Platform.OS === 'android' ? EditorWebView.current?.requestFocus() : null;+ }+ if (!DDS.isTab) {+ handleBack = BackHandler.addEventListener(+ 'hardwareBackPress',+ _onHardwareBackPress,+ );+ }+ };++ const onCallClear = async () => {+ if (editing.currentlyEditing) {+ exitEditorAnimation();+ }+ await clearEditor();+ };+ const closeFullscreen = () => {+ setFullscreen(false);+ };++ useEffect(() => {+ EditorWebView.current?.reload();+ }, [premiumUser]);++ const _onHardwareBackPress = async () => {+ if (editing.currentlyEditing) {+ if (tapCount > 0) {+ await _onBackPress();+ return true;+ } else {+ tapCount = 1;+ setTimeout(() => {+ tapCount = 0;+ }, 3000);+ ToastEvent.show('Press back again to exit editor', 'success');+ return true;+ }+ }+ };++ const _onBackPress = async () => {+ editing.currentlyEditing = true;+ if (DDS.isTab && !DDS.isSmallTab) {+ simpleDialogEvent(TEMPLATE_EXIT_FULLSCREEN());+ } else {+ exitEditorAnimation();++ if (checkNote() && isNotedEdited()) {+ ToastEvent.show('Note Saved!', 'success');+ }+ await clearEditor();+ if (handleBack) {+ handleBack.remove();+ handleBack = null;+ }+ }+ };++ return (+ <>+ {noMenu || DDS.isPhone || DDS.isSmallTab ? (+ <View />+ ) : (+ <ActionIcon+ name="arrow-left"+ color={colors.heading}+ onPress={_onBackPress}+ bottom={5}+ iconStyle={{+ textAlignVertical: 'center',+ }}+ customStyle={{+ marginLeft: -5,+ position: 'absolute',+ marginTop:+ Platform.OS === 'ios' ? 0 : StatusBar.currentHeight + 5,+ zIndex: 11,+ left: 0,+ justifyContent: 'center',+ alignItems: 'center',+ }}+ />+ )}++ <View+ style={{+ flexDirection: 'row',+ width: DDS.isTab && !DDS.isSmallTab ? '30%' : '100%',+ height: 50,+ justifyContent: 'space-between',+ alignItems: 'center',+ paddingHorizontal: 12,+ position: DDS.isTab && !DDS.isSmallTab ? 'absolute' : 'relative',+ backgroundColor: colors.bg,+ right: 0,+ marginTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight,+ zIndex: 10,+ }}>+ {DDS.isTab && !DDS.isSmallTab ? (+ <View />+ ) : (+ <ActionIcon+ name="arrow-left"+ color={colors.heading}+ onPress={_onBackPress}+ bottom={5}+ customStyle={{+ marginLeft: -5,+ }}+ />+ )}++ <View+ style={{+ flexDirection: 'row',+ }}>+ <ActionIcon+ name="plus"+ color={colors.heading}+ customStyle={{+ marginLeft: 10,+ }}+ onPress={() => {+ simpleDialogEvent(TEMPLATE_NEW_NOTE);+ }}+ />+ {DDS.isTab && !DDS.isSmallTab && !fullscreen ? (+ <ActionIcon+ name="fullscreen"+ color={colors.heading}+ customStyle={{+ marginLeft: 10,+ }}+ onPress={() => {+ eSendEvent(eOpenFullscreenEditor);+ setFullscreen(true);+ editing.isFullscreen = true;+ post(+ JSON.stringify({+ type: 'nomenu',+ value: false,+ }),+ );+ }}+ />+ ) : null}++ <HistoryComponent/>++ <ActionIcon+ name="dots-horizontal"+ color={colors.heading}+ customStyle={{+ marginLeft: 10,+ }}+ onPress={() => {+ ActionSheetEvent(+ getNote(),+ true,+ true,+ ['Add to', 'Share', 'Export', 'Delete'],+ ['Dark Mode', 'Add to Vault', 'Pin', 'Favorite'],+ );+ }}+ />+ </View>+ </View></>+ );+};++export default EditorHeader;diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex 2b182ccaf..d432795ee 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -64,6 +64,9 @@ export function getNote() {}+export const textInput = createRef();++export function post(type, value = null) {let message = {type,diff --git a/apps/mobile/src/views/Editor/HistoryComponent.js b/apps/mobile/src/views/Editor/HistoryComponent.jsnew file mode 100644index 000000000..e4fa9ba3c--- /dev/null+++ b/apps/mobile/src/views/Editor/HistoryComponent.js@@ -0,0 +1,43 @@+import React, {useState} from 'react';+import {ActionIcon} from '../../components/ActionIcon';+import {useTracked} from '../../provider';+import {post,} from './Functions';+++const HistoryComponent = () => {+ const [state] = useTracked();+ const {colors} = state;+ const [historyState,setHistoryState] = useState({+ undo:0,+ redo:0+ });++ return (+ <>++ <ActionIcon+ name="undo-variant"+ color={colors.heading}+ customStyle={{+ marginLeft: 10,+ }}+ onPress={() => {+ post('undo');+ }}+ />+ <ActionIcon+ name="redo-variant"+ color={colors.heading}+ customStyle={{+ marginLeft: 10,+ }}+ onPress={() => {+ post('redo');+ }}+ />++ </>+ );+};++export default HistoryComponent;diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.jsindex 7dc7c049b..212321cb4 100755--- a/apps/mobile/src/views/Editor/index.js+++ b/apps/mobile/src/views/Editor/index.js@@ -1,185 +1,22 @@-import React, {createRef, useEffect, useState} from 'react';-import {- BackHandler,- Keyboard,- KeyboardAvoidingView,- Platform,- SafeAreaView,- StatusBar,- TextInput,- View,-} from 'react-native';+import React, {createRef} from 'react';+import {KeyboardAvoidingView, Platform, SafeAreaView, StatusBar, TextInput, View,} from 'react-native';import WebView from 'react-native-webview';-import {ActionIcon} from '../../components/ActionIcon';-import {- ActionSheetEvent,- simpleDialogEvent,-} from '../../components/DialogManager/recievers';-import {- TEMPLATE_EXIT_FULLSCREEN,- TEMPLATE_NEW_NOTE,-} from '../../components/DialogManager/Templates';import {useTracked} from '../../provider';import {- eSendEvent,- eSubscribeEvent,- eUnSubscribeEvent,- ToastEvent,-} from '../../services/EventManager';-import {- eClearEditor,- eCloseFullscreenEditor,- eOnLoadNote,- eOpenFullscreenEditor,-} from '../../utils/Events';-import {exitEditorAnimation} from '../../utils/Animations';-import {editing} from '../../utils';-import {- _onMessage,- _onShouldStartLoadWithRequest,- checkNote,- clearEditor,- clearTimer,- EditorWebView,- getNote,- injectedJS,- isNotedEdited,- loadNote,- onWebViewLoad,- post,- sourceUri,+ _onMessage,+ _onShouldStartLoadWithRequest,+ EditorWebView,+ injectedJS,+ onWebViewLoad,+ sourceUri, textInput,} from './Functions';-import {normalize} from '../../utils/SizeUtils';import {DDS} from '../../services/DeviceDetection';+import EditorHeader from "./EditorHeader";-let handleBack;-let tapCount = 0;--const textInput = createRef();const Editor = ({noMenu}) => {- // Global Stateconst [state] = useTracked();const {colors, premiumUser} = state;- const [fullscreen, setFullscreen] = useState(false);-- // FUNCTIONS-- useEffect(() => {- let c = {...colors};- c.factor = normalize(1);- post('theme', colors);- }, [colors.bg]);-- useEffect(() => {- if (!DDS.isTab) return;- if (noMenu) {- post('nomenu', true);- } else {- post('nomenu', false);- }- }, [noMenu]);-- useEffect(() => {- eSubscribeEvent(eOnLoadNote, load);- eSubscribeEvent(eCloseFullscreenEditor, closeFullscreen);- eSubscribeEvent(eClearEditor, onCallClear);- Keyboard.addListener("keyboardDidShow",() => {- console.log('keyboard is shown')- post("keyboard")- })- return () => {- eUnSubscribeEvent(eClearEditor, onCallClear);- eUnSubscribeEvent(eCloseFullscreenEditor, closeFullscreen);- eUnSubscribeEvent(eOnLoadNote, load);- Keyboard.removeListener("keyboardDidShow",() => {- post("keyboard")- })- };- }, []);-- useEffect(() => {- if (!noMenu && DDS.isTab) {- handleBack = BackHandler.addEventListener('hardwareBackPress', () => {- simpleDialogEvent(TEMPLATE_EXIT_FULLSCREEN());- editing.isFullscreen = false;- return true;- });- }-- return () => {- clearTimer();- if (handleBack) {- handleBack.remove();- handleBack = null;- }- };- }, [noMenu]);-- const load = async (item) => {- console.log('loading new note');- await loadNote(item);- if (item.type === 'new') {- textInput.current?.focus();- post('focusTitle');- Platform.OS === 'android' ? EditorWebView.current?.requestFocus() : null;- }- if (!DDS.isTab) {- handleBack = BackHandler.addEventListener(- 'hardwareBackPress',- _onHardwareBackPress,- );- }- };-- const onCallClear = async () => {- if (editing.currentlyEditing) {- exitEditorAnimation();- }- await clearEditor();- };- const closeFullscreen = () => {- setFullscreen(false);- };-- useEffect(() => {- EditorWebView.current?.reload();- }, [premiumUser]);-- const _onHardwareBackPress = async () => {- if (editing.currentlyEditing) {- if (tapCount > 0) {- await _onBackPress();- return true;- } else {- tapCount = 1;- setTimeout(() => {- tapCount = 0;- }, 3000);- ToastEvent.show('Press back again to exit editor', 'success');- return true;- }- }- };-- const _onBackPress = async () => {- editing.currentlyEditing = true;- if (DDS.isTab && !DDS.isSmallTab) {- simpleDialogEvent(TEMPLATE_EXIT_FULLSCREEN());- } else {- exitEditorAnimation();-- if (checkNote() && isNotedEdited()) {- ToastEvent.show('Note Saved!', 'success');- }- await clearEditor();- if (handleBack) {- handleBack.remove();- handleBack = null;- }- }- };-return (<SafeAreaViewstyle={{@@ -202,133 +39,8 @@ const Editor = ({noMenu}) => {height: '100%',width: '100%',}}>- {noMenu || DDS.isPhone || DDS.isSmallTab ? (- <View />- ) : (- <ActionIcon- name="arrow-left"- color={colors.heading}- onPress={_onBackPress}- bottom={5}- iconStyle={{- textAlignVertical: 'center',- }}- customStyle={{- marginLeft: -5,- position: 'absolute',- marginTop:- Platform.OS === 'ios' ? 0 : StatusBar.currentHeight + 5,- zIndex: 11,- left: 0,- justifyContent: 'center',- alignItems: 'center',- }}- />- )}-- <View- style={{- flexDirection: 'row',- width: DDS.isTab && !DDS.isSmallTab ? '30%' : '100%',- height: 50,- justifyContent: 'space-between',- alignItems: 'center',- paddingHorizontal: 12,- position: DDS.isTab && !DDS.isSmallTab ? 'absolute' : 'relative',- backgroundColor: colors.bg,- right: 0,- marginTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight,- zIndex: 10,- }}>- {DDS.isTab && !DDS.isSmallTab ? (- <View />- ) : (- <ActionIcon- name="arrow-left"- color={colors.heading}- onPress={_onBackPress}- bottom={5}- customStyle={{- marginLeft: -5,- }}- />- )}-- <View- style={{- flexDirection: 'row',- }}>- <ActionIcon- name="plus"- color={colors.heading}- customStyle={{- marginLeft: 10,- }}- onPress={() => {- simpleDialogEvent(TEMPLATE_NEW_NOTE);- }}- />- {DDS.isTab && !DDS.isSmallTab && !fullscreen ? (- <ActionIcon- name="fullscreen"- color={colors.heading}- customStyle={{- marginLeft: 10,- }}- onPress={() => {- eSendEvent(eOpenFullscreenEditor);- setFullscreen(true);- editing.isFullscreen = true;- post(- JSON.stringify({- type: 'nomenu',- value: false,- }),- );- }}- />- ) : null}-- <ActionIcon- name="undo-variant"- color={colors.heading}- customStyle={{- marginLeft: 10,- }}- onPress={() => {- post('undo');- }}- />- <ActionIcon- name="redo-variant"- color={colors.heading}- customStyle={{- marginLeft: 10,- }}- onPress={() => {- post('redo');- }}- />-- <ActionIcon- name="dots-horizontal"- color={colors.heading}- customStyle={{- marginLeft: 10,- }}- onPress={() => {- ActionSheetEvent(- getNote(),- true,- true,- ['Add to', 'Share', 'Export', 'Delete'],- ['Dark Mode', 'Add to Vault', 'Pin', 'Favorite'],- );- }}- />- </View>- </View>+ <EditorHeader noMenu={noMenu} /><WebViewtestID="editor"ref={EditorWebView}diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.jsindex 77d06f90b..878e5e5e1 100755--- a/apps/mobile/src/views/Home/index.js+++ b/apps/mobile/src/views/Home/index.js@@ -13,7 +13,6 @@ import {} from '../../utils/Events';import {openEditorAnimation} from '../../utils/Animations';import {DDS} from '../../services/DeviceDetection';-import ResultDialog from '../../components/ResultDialog';export const Home = ({navigation}) => {const [state, dispatch] = useTracked();@@ -79,16 +78,13 @@ export const Home = ({navigation}) => {}}, [notes]);- const _onPressBottomButton = async () => {+ const _onPressBottomButton = async (event) => {eSendEvent(eOnLoadNote, {type: 'new'});if (DDS.isPhone || DDS.isSmallTab) {openEditorAnimation();}};- useEffect(() => {- console.log('render home');- });return (<>diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.jsindex e248e649c..260ccdeff 100644--- a/apps/mobile/src/views/Settings/index.js+++ b/apps/mobile/src/views/Settings/index.js@@ -529,7 +529,7 @@ export const Settings = ({navigation}) => {alignItems: 'center',marginTop: 5,marginRight: ((dWidth) - ((dWidth / 7.5) * 6))/12 ,- marginLeft: index === 0 ? 0 : ((dWidth - 12) - ((dWidth / 7.5) * 6))/12.1 ,+ marginLeft: index === 0 ? 0.5 : ((dWidth - 12) - ((dWidth / 7.5) * 6))/12.1 ,width: DDS.isTab ? (dWidth * 0.28) / 5 - 24 : dWidth / 7.5,height: DDS.isTab ? (dWidth * 0.28) / 5 - 24 : dWidth / 7.5,borderRadius: 100,@@ -622,10 +622,10 @@ export const Settings = ({navigation}) => {<Icon color={colors.icon} name="menu-down" size={SIZE.md} /></TouchableOpacity>}>- {MenuItemsList.map((item) => (+ {MenuItemsList.slice(0,MenuItemsList.length - 1).map((item) => (<MenuItem- onPress={() => {- setSetting(settings, 'homepage', item.name);+ onPress={async () => {+ await setSetting(settings, 'homepage', item.name);}}style={{backgroundColor: