Skip to content

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

fix editor loading

ammarahm-ed1d8de2f5502f
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 367a27372..8be824fbe 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -17,10 +17,13 @@ import {
eUnSubscribeEvent,
} from './src/services/EventManager';
import SettingsService from './src/services/SettingsService';
+import { editing } from './src/utils';
import {db} from './src/utils/DB';
import {eDispatchAction, eOpenSideMenu} from './src/utils/Events';
import {MMKV} from './src/utils/mmkv';
+import { tabBarRef } from './src/utils/Refs';
import EditorRoot from './src/views/Editor/EditorRoot';
+import { setNoteOnly } from './src/views/Editor/Functions';
let initStatus = false;
const App = () => {
diff --git a/apps/mobile/AppRootEvents.js b/apps/mobile/AppRootEvents.js
index 9f6652c79..3a00efff8 100644
--- a/apps/mobile/AppRootEvents.js
+++ b/apps/mobile/AppRootEvents.js
@@ -51,6 +51,7 @@ async function storeAppState() {
editing: editing.currentlyEditing,
note: getNote(),
movedAway: editing.movedAway,
+ timestamp:Date.now()
});
await MMKV.setItem('appState', state);
}
diff --git a/apps/mobile/src/components/AppLoader/index.js b/apps/mobile/src/components/AppLoader/index.js
index cc7621082..b38d496d2 100644
--- a/apps/mobile/src/components/AppLoader/index.js
+++ b/apps/mobile/src/components/AppLoader/index.js
@@ -16,6 +16,7 @@ import {eOpenRateDialog, eOpenSideMenu} from '../../utils/Events';
import {MMKV} from '../../utils/mmkv';
import {tabBarRef} from '../../utils/Refs';
import {sleep} from '../../utils/TimeUtils';
+import { setNoteOnly } from '../../views/Editor/Functions';
const scaleV = new Animated.Value(0.95);
const opacityV = new Animated.Value(1);
@@ -31,17 +32,6 @@ const AppLoader = ({onLoad}) => {
opacityV.setValue(1);
return;
}
- let appState = await MMKV.getItem('appState');
- if (appState) {
- appState = JSON.parse(appState);
- if (!appState.movedAway) {
- eSendEvent('loadingNote', appState.note);
- editing.currentlyEditing = true;
- tabBarRef.current?.goToPage(1);
-
- }
- }
-
if (value === 'show') {
opacityV.setValue(0);
setLoading(false);
@@ -59,6 +49,7 @@ const AppLoader = ({onLoad}) => {
changeContainerScale(ContainerScale, 1, 600);
await sleep(150);
setLoading(false);
+
animation = false;
await db.notes.init();
dispatch({type: Actions.NOTES});
diff --git a/apps/mobile/src/views/Editor/EditorWrapper.js b/apps/mobile/src/views/Editor/EditorWrapper.js
index b88f352ca..a04166127 100644
--- a/apps/mobile/src/views/Editor/EditorWrapper.js
+++ b/apps/mobile/src/views/Editor/EditorWrapper.js
@@ -11,6 +11,7 @@ import {eSendEvent} from '../../services/EventManager';
import {eOnLoadNote} from '../../utils/Events';
import {editorRef} from '../../utils/Refs';
import EditorOverlay from './EditorOverlay';
+import Editor from "./index"
let prevVal = 0;
let finalValue = 80;
let anim2 = new Animated.Value(0);
@@ -84,22 +85,11 @@ const AnimatedKeyboardView = Animated.createAnimatedComponent(
KeyboardAvoidingView,
);
-let Editor;
-
export const EditorWrapper = ({dimensions}) => {
const [state] = useTracked();
- const {colors, loading} = state;
- const [loaded, setLoaded] = useState(false);
+ const {colors} = state;
const insets = useSafeAreaInsets();
- useEffect(() => {
- if (!loading) {
- if (!Editor) {
- Editor = require('./index').default;
- }
- setLoaded(true);
- }
- }, [loading]);
return (
<View
@@ -186,7 +176,7 @@ export const EditorWrapper = ({dimensions}) => {
</Animated.Text>
</View>
- {!loaded || loading ? null : <Editor />}
+ <Editor />
<EditorOverlay />
</AnimatedKeyboardView>
</PanGestureHandler>
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index 9cc08d157..f33bead74 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -91,7 +91,7 @@ export function clearTimer() {
}
}
-export const CHECK_STATUS = (premium) =>
+export const CHECK_STATUS = premium =>
`(function() {
setTimeout(() => {
let msg = JSON.stringify({
@@ -107,6 +107,10 @@ export function getNote() {
return note;
}
+export function setNoteOnly(n) {
+ note = n;
+}
+
export const textInput = createRef();
export function post(type, value = null) {
@@ -117,12 +121,12 @@ export function post(type, value = null) {
EditorWebView.current?.postMessage(JSON.stringify(message));
}
-export const _onShouldStartLoadWithRequest = async (request) => {
+export const _onShouldStartLoadWithRequest = async request => {
if (request.url.includes('https')) {
if (Platform.OS === 'ios' && !request.isTopFrame) return;
openLinkInBrowser(request.url, appColors)
- .catch((e) => {})
- .then((r) => {});
+ .catch(e => {})
+ .then(r => {});
return false;
} else {
@@ -170,7 +174,7 @@ let currentEditingTimer = null;
let webviewTimer = null;
-export const loadNote = async (item) => {
+export const loadNote = async item => {
editing.currentlyEditing = true;
tiny.call(EditorWebView, tiny.blur);
if (item && item.type === 'new') {
@@ -242,7 +246,7 @@ export function setIntentNote(item) {
};
}
-export const _onMessage = async (evt) => {
+export const _onMessage = async evt => {
if (!evt || !evt.nativeEvent || !evt.nativeEvent.data) return;
let message = evt.nativeEvent.data;
@@ -475,12 +479,22 @@ async function restoreEditorState() {
let appState = await MMKV.getItem('appState');
if (appState) {
appState = JSON.parse(appState);
- if (appState.editing && appState.note && appState.note.id) {
- eSendEvent(eOnLoadNote, appState.note);
- if (!appState.movedAway) {
- tabBarRef.current?.goToPage(1);
- }
+ if (
+ appState.editing &&
+ appState.note &&
+ appState.note.id &&
+ Date.now() < appState.timestamp + 3600000
+ ) {
+ eSendEvent('loadingNote', appState.note);
+ setNoteOnly(appState.note);
+ editing.currentlyEditing = true;
+ editing.movedAway = true;
+ tabBarRef.current?.goToPage(1);
+ setTimeout(() => {
+ eSendEvent(eOnLoadNote, appState.note);
+ }, 100);
MMKV.removeItem('appState');
+ editing.movedAway = false;
eSendEvent('load_overlay', 'hide_editor');
}
}
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 5fb132082..41cde5c6e 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -98,9 +98,8 @@ export const Favorites = ({route, navigation}) => {
return (
<>
- <SelectionHeader screen="Favorites" />
+ <SelectionHeader screen="Favorites" />
<ContainerTopSection>
-
<Header title="Favorites" isBack={false} screen="Favorites" />
</ContainerTopSection>
<SimpleList