From 8ac1c75dc33cfcbfddf85801a2dc723489fe20ca Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Fri, 5 Feb 2021 11:02:54 +0500 Subject: [PATCH] fix note loading errors --- .../android/app/src/main/assets/init.js | 5 + apps/mobile/src/views/Editor/EditorHeader.js | 128 +++++++++--------- apps/mobile/src/views/Editor/EditorOverlay.js | 100 ++++++++++++++ apps/mobile/src/views/Editor/EditorTitle.js | 1 - apps/mobile/src/views/Editor/EditorWrapper.js | 33 +++-- apps/mobile/src/views/Editor/Functions.js | 17 ++- apps/mobile/src/views/Editor/index.js | 1 + apps/mobile/src/views/Editor/tiny/tiny.js | 19 +-- 8 files changed, 206 insertions(+), 98 deletions(-) create mode 100644 apps/mobile/src/views/Editor/EditorOverlay.js diff --git a/apps/mobile/android/app/src/main/assets/init.js b/apps/mobile/android/app/src/main/assets/init.js index 6f6c639a4..4133d7a4f 100644 --- a/apps/mobile/android/app/src/main/assets/init.js +++ b/apps/mobile/android/app/src/main/assets/init.js @@ -65,6 +65,11 @@ function init_tiny(size) { editor.on('focus', () => { reactNativeEventHandler('focus', 'editor'); }); + editor.on("SetContent", event => { + if (!event.paste) { + reactNativeEventHandler('noteLoaded', true); + } + }) editor.on('Change', function (e) { clearTimeout(changeTimer); if (isLoading) { diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.js index d465c7017..66c283f69 100644 --- a/apps/mobile/src/views/Editor/EditorHeader.js +++ b/apps/mobile/src/views/Editor/EditorHeader.js @@ -1,23 +1,23 @@ -import React, { useEffect } from 'react'; -import { Keyboard, Platform, View } from 'react-native'; +import React, {useEffect} from 'react'; +import {Keyboard, Platform, View} from 'react-native'; import RNExitApp from 'react-native-exit-app'; -import { useSafeAreaInsets } from 'react-native-safe-area-context'; -import { notesnook } from '../../../e2e/test.ids'; -import { ActionIcon } from '../../components/ActionIcon'; -import { ActionSheetEvent } from '../../components/DialogManager/recievers'; -import { useTracked } from '../../provider'; -import { DDS } from '../../services/DeviceDetection'; -import { eSendEvent, ToastEvent } from '../../services/EventManager'; +import {useSafeAreaInsets} from 'react-native-safe-area-context'; +import {notesnook} from '../../../e2e/test.ids'; +import {ActionIcon} from '../../components/ActionIcon'; +import {ActionSheetEvent} from '../../components/DialogManager/recievers'; +import {useTracked} from '../../provider'; +import {DDS} from '../../services/DeviceDetection'; +import {eSendEvent, ToastEvent} from '../../services/EventManager'; import Navigation from '../../services/Navigation'; -import { editing } from '../../utils'; -import { db } from '../../utils/DB'; +import {editing} from '../../utils'; +import {db} from '../../utils/DB'; import { eCloseFullscreenEditor, - eOpenFullscreenEditor + eOpenFullscreenEditor, } from '../../utils/Events'; -import { sideMenuRef, tabBarRef } from '../../utils/Refs'; -import { sleep } from '../../utils/TimeUtils'; -import { EditorTitle } from './EditorTitle'; +import {sideMenuRef, tabBarRef} from '../../utils/Refs'; +import {sleep} from '../../utils/TimeUtils'; +import {EditorTitle} from './EditorTitle'; import { checkNote, clearEditor, @@ -28,7 +28,7 @@ import { post, saveNote, setColors, - setIntent + setIntent, } from './Functions'; import HistoryComponent from './HistoryComponent'; import tiny from './tiny/tiny'; @@ -38,20 +38,13 @@ let tapCount = 0; const EditorHeader = () => { const [state] = useTracked(); - const {colors, fullscreen, deviceMode,premiumUser} = state; + const {colors, fullscreen} = state; const insets = useSafeAreaInsets(); useEffect(() => { setColors(colors); }, [colors.bg]); - - - useEffect(() => { - - EditorWebView.current?.reload(); - }, [premiumUser]); - const _onBackPress = async () => { if (sideMenuRef.current === null) { if (tapCount > 0) { @@ -141,56 +134,57 @@ const EditorHeader = () => { style={{ flexDirection: 'row', }}> - { - await loadNote({type: 'new'}); - }} - /> - - {DDS.isLargeTablet() && !fullscreen ? ( + <> { + await loadNote({type: 'new'}); + }} + /> + + {DDS.isLargeTablet() && !fullscreen ? ( + { + eSendEvent(eOpenFullscreenEditor); + editing.isFullscreen = true; + }} + /> + ) : null} + + + { - eSendEvent(eOpenFullscreenEditor); - editing.isFullscreen = true; + onPress={async () => { + let note = getNote() && db.notes.note(getNote().id).data; + if (editing.isFocused) { + tiny.call(EditorWebView, tiny.blur); + await sleep(500); + editing.isFocused = true; + } + ActionSheetEvent( + note, + true, + true, + ['Add to', 'Share', 'Export', 'Delete'], + ['Dark Mode', 'Add to Vault', 'Pin', 'Favorite'], + ); }} /> - ) : null} - - - - { - let note = getNote() && db.notes.note(getNote().id).data; - if (editing.isFocused) { - tiny.call(EditorWebView,tiny.blur) - await sleep(500); - editing.isFocused = true; - } - ActionSheetEvent( - note, - true, - true, - ['Add to', 'Share', 'Export', 'Delete'], - ['Dark Mode', 'Add to Vault', 'Pin', 'Favorite'], - ); - }} - /> + diff --git a/apps/mobile/src/views/Editor/EditorOverlay.js b/apps/mobile/src/views/Editor/EditorOverlay.js new file mode 100644 index 000000000..ea9096a27 --- /dev/null +++ b/apps/mobile/src/views/Editor/EditorOverlay.js @@ -0,0 +1,100 @@ +import React, {useEffect, useState} from 'react'; +import {ActivityIndicator} from 'react-native'; +import {View} from 'react-native'; +import {Button} from '../../components/Button'; +import Heading from '../../components/Typography/Heading'; +import Paragraph from '../../components/Typography/Paragraph'; +import {useTracked} from '../../provider'; +import { + eSendEvent, + eSubscribeEvent, + eUnSubscribeEvent, +} from '../../services/EventManager'; +import {SIZE} from '../../utils/SizeUtils'; + +let timer = null; +let timerError = null; +const EditorOverlay = () => { + const [state] = useTracked(); + const {colors} = state; + const [loading, setLoading] = useState(false); + const [error, setError] = useState(false); + const load = (loading) => { + clearTimeout(timer); + clearTimeout(timerError); + if (loading) { + timer = setTimeout(() => { + setLoading(loading); + timerError = setTimeout(() => { + setError(true); + }, 6000); + }, 3000); + } else { + setError(false); + setLoading(false); + } + }; + + useEffect(() => { + eSubscribeEvent('loadingNote', load); + return () => { + eUnSubscribeEvent('loadingNote', load); + }; + }, []); + + return ( + loading && ( + + + + Loading Note + + {error && ( + <> +