1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Improved app startup

This commit is contained in:
Laurent Cozic 2017-08-01 17:41:58 +00:00
parent 72c4ed8453
commit a270a345d3
2 changed files with 30 additions and 38 deletions

View File

@ -22,23 +22,15 @@ class WelcomeScreenComponent extends BaseScreenComponent {
} }
render() { render() {
if (this.props.loading) { let message = this.props.folders.length ? _('Click on the (+) button to create a new note or notebook. Click on the side menu to access your existing notebooks.') : _('You currently have no notebook. Create one by clicking on (+) button.');
return (
<View style={{flex: 1}}>
<Text>Loading...</Text>
</View>
);
} else {
let message = this.props.folders.length ? _('Click on the (+) button to create a new note or notebook. Click on the side menu to access your existing notebooks.') : _('You currently have no notebook. Create one by clicking on (+) button.');
return ( return (
<View style={this.styles().screen} > <View style={this.styles().screen} >
<ScreenHeader title={_('Welcome')}/> <ScreenHeader title={_('Welcome')}/>
<Text style={styles.message}>{message}</Text> <Text style={styles.message}>{message}</Text>
<ActionButton addFolderNoteButtons={true}/> <ActionButton addFolderNoteButtons={true}/>
</View> </View>
); );
}
} }
} }
@ -46,7 +38,6 @@ class WelcomeScreenComponent extends BaseScreenComponent {
const WelcomeScreen = connect( const WelcomeScreen = connect(
(state) => { (state) => {
return { return {
loading: state.loading,
folders: state.folders, folders: state.folders,
}; };
} }

View File

@ -47,7 +47,6 @@ let defaultState = {
selectedItemType: 'note', selectedItemType: 'note',
showSideMenu: false, showSideMenu: false,
screens: {}, screens: {},
loading: true,
historyCanGoBack: false, historyCanGoBack: false,
notesOrder: [ notesOrder: [
{ by: 'updated_time', dir: 'DESC' }, { by: 'updated_time', dir: 'DESC' },
@ -56,6 +55,7 @@ let defaultState = {
syncReport: {}, syncReport: {},
searchQuery: '', searchQuery: '',
settings: {}, settings: {},
appState: 'starting',
}; };
const initialRoute = { const initialRoute = {
@ -188,13 +188,6 @@ const reducer = (state = defaultState, action) => {
newState.historyCanGoBack = !!navHistory.length; newState.historyCanGoBack = !!navHistory.length;
break; break;
// Replace all the notes with the provided array
case 'APPLICATION_LOADING_DONE':
newState = Object.assign({}, state);
newState.loading = false;
break;
case 'SETTINGS_UPDATE_ALL': case 'SETTINGS_UPDATE_ALL':
newState = Object.assign({}, state); newState = Object.assign({}, state);
@ -348,6 +341,11 @@ const reducer = (state = defaultState, action) => {
newState = Object.assign({}, state); newState = Object.assign({}, state);
newState.searchQuery = action.query.trim(); newState.searchQuery = action.query.trim();
case 'SET_APP_STATE':
newState = Object.assign({}, state);
newState.appState = action.state;
} }
} catch (error) { } catch (error) {
error.message = 'In reducer: ' + error.message + ' Action: ' + JSON.stringify(action); error.message = 'In reducer: ' + error.message + ' Action: ' + JSON.stringify(action);
@ -383,15 +381,9 @@ const generalMiddleware = store => next => async (action) => {
let store = createStore(reducer, applyMiddleware(generalMiddleware)); let store = createStore(reducer, applyMiddleware(generalMiddleware));
let initializationState_ = 'waiting';
async function initialize(dispatch, backButtonHandler) { async function initialize(dispatch, backButtonHandler) {
if (initializationState_ != 'waiting') return;
shimInit(); shimInit();
initializationState_ = 'in_progress';
Setting.setConstant('env', __DEV__ ? 'dev' : 'prod'); Setting.setConstant('env', __DEV__ ? 'dev' : 'prod');
Setting.setConstant('appId', 'net.cozic.joplin'); Setting.setConstant('appId', 'net.cozic.joplin');
Setting.setConstant('appType', 'mobile'); Setting.setConstant('appType', 'mobile');
@ -476,10 +468,6 @@ async function initialize(dispatch, backButtonHandler) {
tags: tags, tags: tags,
}); });
dispatch({
type: 'APPLICATION_LOADING_DONE',
});
let folderId = Setting.value('activeFolderId'); let folderId = Setting.value('activeFolderId');
let folder = await Folder.load(folderId); let folder = await Folder.load(folderId);
@ -513,8 +501,6 @@ async function initialize(dispatch, backButtonHandler) {
reg.scheduleSync(); reg.scheduleSync();
} }
initializationState_ = 'done';
reg.logger().info('Application initialized'); reg.logger().info('Application initialized');
} }
@ -526,7 +512,19 @@ class AppComponent extends React.Component {
} }
async componentDidMount() { async componentDidMount() {
await initialize(this.props.dispatch, this.backButtonHandler.bind(this)); if (this.props.appState == 'starting') {
this.props.dispatch({
type: 'SET_APP_STATE',
state: 'initializing',
});
await initialize(this.props.dispatch, this.backButtonHandler.bind(this));
this.props.dispatch({
type: 'SET_APP_STATE',
state: 'ready',
});
}
} }
backButtonHandler() { backButtonHandler() {
@ -559,6 +557,8 @@ class AppComponent extends React.Component {
} }
render() { render() {
if (this.props.appState != 'ready') return null;
const sideMenuContent = <SideMenuContent/>; const sideMenuContent = <SideMenuContent/>;
const appNavInit = { const appNavInit = {
@ -588,6 +588,7 @@ const mapStateToProps = (state) => {
historyCanGoBack: state.historyCanGoBack, historyCanGoBack: state.historyCanGoBack,
showSideMenu: state.showSideMenu, showSideMenu: state.showSideMenu,
syncStarted: state.syncStarted, syncStarted: state.syncStarted,
appState: state.appState,
}; };
}; };