mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
fix delay on first load
This commit is contained in:
@@ -17,13 +17,10 @@ import {
|
|||||||
eUnSubscribeEvent,
|
eUnSubscribeEvent,
|
||||||
} from './src/services/EventManager';
|
} from './src/services/EventManager';
|
||||||
import SettingsService from './src/services/SettingsService';
|
import SettingsService from './src/services/SettingsService';
|
||||||
import { editing } from './src/utils';
|
|
||||||
import {db} from './src/utils/DB';
|
import {db} from './src/utils/DB';
|
||||||
import {eDispatchAction, eOpenSideMenu} from './src/utils/Events';
|
import {eDispatchAction, eOpenSideMenu} from './src/utils/Events';
|
||||||
import {MMKV} from './src/utils/mmkv';
|
import {MMKV} from './src/utils/mmkv';
|
||||||
import { tabBarRef } from './src/utils/Refs';
|
|
||||||
import EditorRoot from './src/views/Editor/EditorRoot';
|
import EditorRoot from './src/views/Editor/EditorRoot';
|
||||||
import { setNoteOnly } from './src/views/Editor/Functions';
|
|
||||||
|
|
||||||
let initStatus = false;
|
let initStatus = false;
|
||||||
const App = () => {
|
const App = () => {
|
||||||
@@ -48,9 +45,11 @@ const App = () => {
|
|||||||
eSendEvent(eOpenSideMenu);
|
eSendEvent(eOpenSideMenu);
|
||||||
SplashScreen.hide();
|
SplashScreen.hide();
|
||||||
await db.init();
|
await db.init();
|
||||||
|
console.log('db is ready');
|
||||||
let requireIntro = await MMKV.getItem('introCompleted');
|
let requireIntro = await MMKV.getItem('introCompleted');
|
||||||
|
loadDefaultNotes();
|
||||||
|
console.log('loaded default note');
|
||||||
if (!requireIntro) {
|
if (!requireIntro) {
|
||||||
await loadDefaultNotes();
|
|
||||||
await MMKV.setItem(
|
await MMKV.setItem(
|
||||||
'askForRating',
|
'askForRating',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -86,7 +85,7 @@ const App = () => {
|
|||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const _dispatch = (data) => {
|
const _dispatch = data => {
|
||||||
dispatch(data);
|
dispatch(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,6 +97,7 @@ const App = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const loadMainApp = () => {
|
const loadMainApp = () => {
|
||||||
|
console.log('status on init', initStatus);
|
||||||
if (initStatus) {
|
if (initStatus) {
|
||||||
SettingsService.setAppLoaded();
|
SettingsService.setAppLoaded();
|
||||||
eSendEvent('load_overlay');
|
eSendEvent('load_overlay');
|
||||||
@@ -107,6 +107,7 @@ const App = () => {
|
|||||||
|
|
||||||
async function loadDefaultNotes() {
|
async function loadDefaultNotes() {
|
||||||
try {
|
try {
|
||||||
|
console.log('creating note');
|
||||||
const isCreated = await MMKV.getItem('defaultNoteCreated');
|
const isCreated = await MMKV.getItem('defaultNoteCreated');
|
||||||
if (isCreated) return;
|
if (isCreated) return;
|
||||||
const notes = await http.get(
|
const notes = await http.get(
|
||||||
@@ -114,6 +115,7 @@ const App = () => {
|
|||||||
);
|
);
|
||||||
if (!notes) return;
|
if (!notes) return;
|
||||||
for (let note of notes) {
|
for (let note of notes) {
|
||||||
|
console.log('getting content');
|
||||||
const content = await http.get(note.mobileContent);
|
const content = await http.get(note.mobileContent);
|
||||||
await db.notes.add({
|
await db.notes.add({
|
||||||
title: note.title,
|
title: note.title,
|
||||||
@@ -122,9 +124,11 @@ const App = () => {
|
|||||||
content: {type: 'tiny', data: content},
|
content: {type: 'tiny', data: content},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.log('default note created');
|
||||||
await MMKV.setItem('defaultNoteCreated', 'yes');
|
await MMKV.setItem('defaultNoteCreated', 'yes');
|
||||||
|
dispatch({type: Actions.ALL});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e, 'loading note on welcome');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export const RootView = React.memo(
|
|||||||
<ContextMenu />
|
<ContextMenu />
|
||||||
<DummyText />
|
<DummyText />
|
||||||
<DialogManager />
|
<DialogManager />
|
||||||
<Splash />
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
import React, {useEffect, useState} from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import {View} from 'react-native';
|
import { View } from 'react-native';
|
||||||
import Animated, {Easing} from 'react-native-reanimated';
|
import Animated, { Easing } from 'react-native-reanimated';
|
||||||
import AnimatedProgress from 'react-native-reanimated-progress-bar';
|
import AnimatedProgress from 'react-native-reanimated-progress-bar';
|
||||||
import {useTracked} from '../../provider';
|
import { useTracked } from '../../provider';
|
||||||
import {Actions} from '../../provider/Actions';
|
import { Actions } from '../../provider/Actions';
|
||||||
import {
|
import {
|
||||||
eSendEvent,
|
eSendEvent,
|
||||||
eSubscribeEvent,
|
eSubscribeEvent,
|
||||||
eUnSubscribeEvent,
|
eUnSubscribeEvent
|
||||||
} from '../../services/EventManager';
|
} from '../../services/EventManager';
|
||||||
import {editing} from '../../utils';
|
import { editing } from '../../utils';
|
||||||
import {changeContainerScale, ContainerScale} from '../../utils/Animations';
|
import { changeContainerScale, ContainerScale } from '../../utils/Animations';
|
||||||
import {db} from '../../utils/DB';
|
import { db } from '../../utils/DB';
|
||||||
import {eOpenRateDialog, eOpenSideMenu} from '../../utils/Events';
|
import { eOpenRateDialog, eOpenSideMenu } from '../../utils/Events';
|
||||||
import {MMKV} from '../../utils/mmkv';
|
import { MMKV } from '../../utils/mmkv';
|
||||||
import {tabBarRef} from '../../utils/Refs';
|
import { tabBarRef } from '../../utils/Refs';
|
||||||
import {sleep} from '../../utils/TimeUtils';
|
import { sleep } from '../../utils/TimeUtils';
|
||||||
import {setNoteOnly} from '../../views/Editor/Functions';
|
import SplashScreen from '../SplashScreen';
|
||||||
|
|
||||||
const scaleV = new Animated.Value(0.95);
|
const scaleV = new Animated.Value(0.95);
|
||||||
const opacityV = new Animated.Value(1);
|
const opacityV = new Animated.Value(1);
|
||||||
@@ -27,6 +27,7 @@ const AppLoader = ({onLoad}) => {
|
|||||||
const [opacity, setOpacity] = useState(true);
|
const [opacity, setOpacity] = useState(true);
|
||||||
|
|
||||||
const load = async value => {
|
const load = async value => {
|
||||||
|
console.log('loading called here');
|
||||||
if (value === 'hide') {
|
if (value === 'hide') {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
opacityV.setValue(1);
|
opacityV.setValue(1);
|
||||||
@@ -34,7 +35,6 @@ const AppLoader = ({onLoad}) => {
|
|||||||
}
|
}
|
||||||
let appState = await MMKV.getItem('appState');
|
let appState = await MMKV.getItem('appState');
|
||||||
if (appState) {
|
if (appState) {
|
||||||
|
|
||||||
appState = JSON.parse(appState);
|
appState = JSON.parse(appState);
|
||||||
if (!appState.movedAway && Date.now() < appState.timestamp + 3600000) {
|
if (!appState.movedAway && Date.now() < appState.timestamp + 3600000) {
|
||||||
editing.isRestoringState = true;
|
editing.isRestoringState = true;
|
||||||
@@ -86,41 +86,41 @@ const AppLoader = ({onLoad}) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return loading ? (
|
||||||
loading && (
|
<Animated.View
|
||||||
|
style={{
|
||||||
|
backgroundColor: opacity ? colors.bg : 'rgba(0,0,0,0)',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
position: 'absolute',
|
||||||
|
zIndex: 999,
|
||||||
|
borderRadius: 10,
|
||||||
|
}}>
|
||||||
<Animated.View
|
<Animated.View
|
||||||
|
onTouchStart={() => {
|
||||||
|
setLoading(false);
|
||||||
|
}}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: opacity ? colors.bg : 'rgba(0,0,0,0)',
|
backgroundColor: colors.bg,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
position: 'absolute',
|
justifyContent: 'center',
|
||||||
zIndex: 999,
|
alignItems: 'center',
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
|
opacity: opacityV,
|
||||||
}}>
|
}}>
|
||||||
<Animated.View
|
<View
|
||||||
onTouchStart={() => {
|
|
||||||
setLoading(false);
|
|
||||||
}}
|
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: colors.bg,
|
height: 10,
|
||||||
width: '100%',
|
flexDirection: 'row',
|
||||||
height: '100%',
|
width: 100,
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
borderRadius: 10,
|
|
||||||
opacity: opacityV,
|
|
||||||
}}>
|
}}>
|
||||||
<View
|
<AnimatedProgress fill={colors.accent} current={4} total={4} />
|
||||||
style={{
|
</View>
|
||||||
height: 10,
|
|
||||||
flexDirection: 'row',
|
|
||||||
width: 100,
|
|
||||||
}}>
|
|
||||||
<AnimatedProgress fill={colors.accent} current={4} total={4} />
|
|
||||||
</View>
|
|
||||||
</Animated.View>
|
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
)
|
</Animated.View>
|
||||||
|
) : (
|
||||||
|
<SplashScreen />
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user