mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 14:09:34 +01:00
remove editor root
This commit is contained in:
@@ -1,31 +1,30 @@
|
||||
import http from 'notes-core/utils/http';
|
||||
import React, {useEffect} from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import Orientation from 'react-native-orientation';
|
||||
import {SafeAreaProvider} from 'react-native-safe-area-context';
|
||||
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||
import SplashScreen from 'react-native-splash-screen';
|
||||
import {AppRootEvents} from './AppRootEvents';
|
||||
import {RootView} from './initializer.root';
|
||||
import { AppRootEvents } from './AppRootEvents';
|
||||
import { RootView } from './initializer.root';
|
||||
import AppLoader from './src/components/AppLoader';
|
||||
import {useTracked} from './src/provider';
|
||||
import { useTracked } from './src/provider';
|
||||
import {
|
||||
initialize,
|
||||
useMessageStore,
|
||||
useNoteStore,
|
||||
useSettingStore,
|
||||
useUserStore,
|
||||
useUserStore
|
||||
} from './src/provider/stores';
|
||||
import {DDS} from './src/services/DeviceDetection';
|
||||
import { DDS } from './src/services/DeviceDetection';
|
||||
import {
|
||||
eSendEvent,
|
||||
eSubscribeEvent,
|
||||
eUnSubscribeEvent,
|
||||
eUnSubscribeEvent
|
||||
} from './src/services/EventManager';
|
||||
import SettingsService from './src/services/SettingsService';
|
||||
import {Tracker} from './src/utils';
|
||||
import {db} from './src/utils/DB';
|
||||
import {eDispatchAction} from './src/utils/Events';
|
||||
import {MMKV} from './src/utils/mmkv';
|
||||
import EditorRoot from './src/views/Editor/EditorRoot';
|
||||
import { Tracker } from './src/utils';
|
||||
import { db } from './src/utils/DB';
|
||||
import { eDispatchAction } from './src/utils/Events';
|
||||
import { MMKV } from './src/utils/mmkv';
|
||||
|
||||
let databaseHasLoaded = false;
|
||||
|
||||
@@ -139,7 +138,6 @@ const App = () => {
|
||||
return (
|
||||
<SafeAreaProvider>
|
||||
<RootView />
|
||||
<EditorRoot />
|
||||
<AppRootEvents />
|
||||
<AppLoader onLoad={loadMainApp} />
|
||||
</SafeAreaProvider>
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { BackHandler, InteractionManager, Keyboard } from 'react-native';
|
||||
import { useSettingStore } from '../../provider/stores';
|
||||
import { DDS } from '../../services/DeviceDetection';
|
||||
import {
|
||||
eSendEvent,
|
||||
eSubscribeEvent,
|
||||
eUnSubscribeEvent,
|
||||
ToastEvent
|
||||
} from '../../services/EventManager';
|
||||
import { editing } from '../../utils';
|
||||
import {
|
||||
eClearEditor,
|
||||
eCloseFullscreenEditor,
|
||||
eOnLoadNote
|
||||
} from '../../utils/Events';
|
||||
import { tabBarRef } from '../../utils/Refs';
|
||||
import {
|
||||
checkNote,
|
||||
clearEditor,
|
||||
clearTimer,
|
||||
|
||||
EditorWebView,
|
||||
|
||||
isNotedEdited,
|
||||
loadNote
|
||||
} from './Functions';
|
||||
import tiny from './tiny/tiny';
|
||||
import { toolbarRef } from './tiny/toolbar/constants';
|
||||
|
||||
let handleBack;
|
||||
|
||||
const EditorRoot = () => {
|
||||
const fullscreen = useSettingStore(state => state.fullscreen);
|
||||
|
||||
useEffect(() => {
|
||||
eSubscribeEvent(eOnLoadNote, load);
|
||||
eSubscribeEvent(eClearEditor, onCallClear);
|
||||
return () => {
|
||||
eUnSubscribeEvent(eClearEditor, onCallClear);
|
||||
eUnSubscribeEvent(eOnLoadNote, load);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (fullscreen && DDS.isTab) {
|
||||
handleBack = BackHandler.addEventListener('hardwareBackPress', _onBackPress);
|
||||
}
|
||||
|
||||
return () => {
|
||||
clearTimer();
|
||||
if (handleBack) {
|
||||
handleBack.remove();
|
||||
handleBack = null;
|
||||
}
|
||||
};
|
||||
}, [fullscreen]);
|
||||
|
||||
const load = async (item) => {
|
||||
await loadNote(item);
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
Keyboard.addListener('keyboardDidShow', tiny.onKeyboardShow);
|
||||
if (!DDS.isTab) {
|
||||
handleBack = BackHandler.addEventListener(
|
||||
'hardwareBackPress',
|
||||
_onHardwareBackPress,
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const onCallClear = async (value) => {
|
||||
if (value === 'removeHandler') {
|
||||
if (handleBack) {
|
||||
handleBack.remove();
|
||||
handleBack = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (value === 'addHandler') {
|
||||
if (handleBack) {
|
||||
handleBack.remove();
|
||||
handleBack = null;
|
||||
}
|
||||
|
||||
handleBack = BackHandler.addEventListener(
|
||||
'hardwareBackPress',
|
||||
_onHardwareBackPress,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (editing.currentlyEditing) {
|
||||
await _onBackPress();
|
||||
}
|
||||
};
|
||||
|
||||
const _onHardwareBackPress = async () => {
|
||||
if (editing.currentlyEditing) {
|
||||
await _onBackPress();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const _onBackPress = async () => {
|
||||
if (DDS.isTab && fullscreen) {
|
||||
eSendEvent(eCloseFullscreenEditor);
|
||||
return;
|
||||
}
|
||||
tiny.call(EditorWebView,tiny.blur);
|
||||
setTimeout(async () => {
|
||||
eSendEvent('showTooltip');
|
||||
toolbarRef.current?.scrollTo({
|
||||
x: 0,
|
||||
y: 0,
|
||||
animated: false,
|
||||
});
|
||||
editing.isFocused = false;
|
||||
editing.currentlyEditing = false;
|
||||
|
||||
if (DDS.isTab) {
|
||||
if (fullscreen) {
|
||||
eSendEvent(eCloseFullscreenEditor);
|
||||
}
|
||||
} else {
|
||||
if (!DDS.isTab) {
|
||||
tabBarRef.current?.goToPage(0);
|
||||
}
|
||||
eSendEvent('historyEvent', {
|
||||
undo: 0,
|
||||
redo: 0,
|
||||
});
|
||||
|
||||
if (checkNote() && isNotedEdited()) {
|
||||
ToastEvent.show({
|
||||
heading: 'Note Saved',
|
||||
type: 'success',
|
||||
duration:1500
|
||||
});
|
||||
}
|
||||
await clearEditor();
|
||||
Keyboard.removeListener('keyboardDidShow', tiny.onKeyboardShow);
|
||||
if (handleBack) {
|
||||
handleBack.remove();
|
||||
handleBack = null;
|
||||
}
|
||||
}
|
||||
}, 50);
|
||||
};
|
||||
|
||||
return <></>;
|
||||
};
|
||||
|
||||
export default EditorRoot;
|
||||
Reference in New Issue
Block a user