1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Improved init sequence

This commit is contained in:
Laurent Cozic
2017-07-08 23:57:09 +01:00
parent a9f7b0d531
commit e9f0d38a80
4 changed files with 79 additions and 22 deletions

View File

@@ -44,21 +44,31 @@ class ActionButtonComponent extends React.Component {
} }
render() { render() {
return ( let buttons = [];
<ReactNativeActionButton buttonColor="rgba(231,76,60,1)">
<ReactNativeActionButton.Item buttonColor='#9b59b6' title="New todo" onPress={() => { this.newTodo_press() }}> if (this.props.folders.length) {
buttons.push(
<ReactNativeActionButton.Item key="ab_todo" buttonColor='#9b59b6' title="New todo" onPress={() => { this.newTodo_press() }}>
<Icon name="md-checkbox-outline" style={styles.actionButtonIcon} /> <Icon name="md-checkbox-outline" style={styles.actionButtonIcon} />
</ReactNativeActionButton.Item> </ReactNativeActionButton.Item>
);
<ReactNativeActionButton.Item buttonColor='#9b59b6' title="New note" onPress={() => { this.newNote_press() }}> buttons.push(
<ReactNativeActionButton.Item key="ab_note" buttonColor='#9b59b6' title="New note" onPress={() => { this.newNote_press() }}>
<Icon name="md-document" style={styles.actionButtonIcon} /> <Icon name="md-document" style={styles.actionButtonIcon} />
</ReactNativeActionButton.Item> </ReactNativeActionButton.Item>
);
}
<ReactNativeActionButton.Item buttonColor='#3498db' title="New folder" onPress={() => { this.newFolder_press() }}> buttons.push(
<Icon name="md-folder" style={styles.actionButtonIcon} /> <ReactNativeActionButton.Item key="ab_folder" buttonColor='#3498db' title="New folder" onPress={() => { this.newFolder_press() }}>
</ReactNativeActionButton.Item> <Icon name="md-folder" style={styles.actionButtonIcon} />
</ReactNativeActionButton.Item>
);
return (
<ReactNativeActionButton buttonColor="rgba(231,76,60,1)">
{ buttons }
</ReactNativeActionButton> </ReactNativeActionButton>
); );
} }
@@ -66,7 +76,9 @@ class ActionButtonComponent extends React.Component {
const ActionButton = connect( const ActionButton = connect(
(state) => { (state) => {
return {}; return {
folders: state.folders,
};
} }
)(ActionButtonComponent) )(ActionButtonComponent)

View File

@@ -50,6 +50,12 @@ class FolderScreenComponent extends React.Component {
this.originalFolder = await Folder.save(toSave); this.originalFolder = await Folder.save(toSave);
this.setState({ folder: this.originalFolder }); this.setState({ folder: this.originalFolder });
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Notes',
params: toSave.id,
});
} }
render() { render() {

View File

@@ -2,8 +2,8 @@ import React, { Component } from 'react';
import { View, Text } from 'react-native'; import { View, Text } from 'react-native';
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { Log } from 'lib/log.js' import { Log } from 'lib/log.js'
import { Folder } from 'lib/models/folder.js'
import { ScreenHeader } from 'lib/components/screen-header.js'; import { ScreenHeader } from 'lib/components/screen-header.js';
import { ActionButton } from 'lib/components/action-button.js';
class LoadingScreenComponent extends React.Component { class LoadingScreenComponent extends React.Component {
@@ -12,18 +12,30 @@ class LoadingScreenComponent extends React.Component {
} }
render() { render() {
return ( if (this.props.loading) {
<View style={{flex: 1}}> return (
<Text>Loading...</Text> <View style={{flex: 1}}>
</View> <Text>Loading...</Text>
); </View>
);
} else {
return (
<View style={{flex: 1}}>
<ScreenHeader navState={this.props.navigation.state} />
<Text>You currently have no notebook. Create one by clicking on (+) button.</Text>
<ActionButton></ActionButton>
</View>
);
}
} }
} }
const LoadingScreen = connect( const LoadingScreen = connect(
(state) => { (state) => {
return {}; return {
loading: state.loading,
};
} }
)(LoadingScreenComponent) )(LoadingScreenComponent)

View File

@@ -43,6 +43,8 @@ let defaultState = {
selectedItemType: 'note', selectedItemType: 'note',
selectedFolderId: null, selectedFolderId: null,
showSideMenu: false, showSideMenu: false,
screens: {},
loading: true,
}; };
const reducer = (state = defaultState, action) => { const reducer = (state = defaultState, action) => {
@@ -76,10 +78,18 @@ const reducer = (state = defaultState, action) => {
newState.selectedItemType = action.itemType; newState.selectedItemType = action.itemType;
} }
if ('screens' in action) {
for (let n in action.screens) {
if (!action.screens.hasOwnProperty(n)) continue;
newState.screens[n] = action.screens[n];
}
}
if (currentRouteName == action.routeName) { if (currentRouteName == action.routeName) {
// If the current screen is already the requested screen, don't do anything // If the current screen is already the requested screen, don't do anything
} else { } else {
const nextStateNav = AppNavigator.router.getStateForAction(action, currentRouteName != 'Loading' ? state.nav : null); //const nextStateNav = AppNavigator.router.getStateForAction(action, currentRouteName != 'Loading' ? state.nav : null);
const nextStateNav = AppNavigator.router.getStateForAction(action, state.nav);
if (nextStateNav) { if (nextStateNav) {
newState.nav = nextStateNav; newState.nav = nextStateNav;
} }
@@ -87,6 +97,13 @@ const reducer = (state = defaultState, action) => {
break; break;
// Replace all the notes with the provided array
case 'APPLICATION_LOADING_DONE':
newState = Object.assign({}, state);
newState.loading = false;
break;
// Replace all the notes with the provided array // Replace all the notes with the provided array
case 'NOTES_UPDATE_ALL': case 'NOTES_UPDATE_ALL':
@@ -186,7 +203,7 @@ const AppNavigator = StackNavigator({
Notes: { screen: NotesScreen }, Notes: { screen: NotesScreen },
Note: { screen: NoteScreen }, Note: { screen: NoteScreen },
Folder: { screen: FolderScreen }, Folder: { screen: FolderScreen },
Folders: { screen: FoldersScreen }, //Folders: { screen: FoldersScreen },
Loading: { screen: LoadingScreen }, Loading: { screen: LoadingScreen },
OneDriveLogin: { screen: OneDriveLoginScreen }, OneDriveLogin: { screen: OneDriveLoginScreen },
Log: { screen: LogScreen }, Log: { screen: LogScreen },
@@ -259,7 +276,7 @@ class AppComponent extends React.Component {
if (Setting.value('env') == 'prod') { if (Setting.value('env') == 'prod') {
await db.open({ name: 'joplin.sqlite' }) await db.open({ name: 'joplin.sqlite' })
} else { } else {
await db.open({ name: 'joplin-52.sqlite' }) await db.open({ name: 'joplin-53.sqlite' })
await db.exec('DELETE FROM notes'); await db.exec('DELETE FROM notes');
await db.exec('DELETE FROM folders'); await db.exec('DELETE FROM folders');
@@ -274,17 +291,27 @@ class AppComponent extends React.Component {
await Setting.load(); await Setting.load();
reg.logger().info('Loading folders...'); reg.logger().info('Loading folders...');
let folders = await Folder.all(); let initialFolders = await Folder.all();
this.props.dispatch({ this.props.dispatch({
type: 'FOLDERS_UPDATE_ALL', type: 'FOLDERS_UPDATE_ALL',
folders: folders, folders: initialFolders,
}); });
this.props.dispatch({ this.props.dispatch({
type: 'Navigation/NAVIGATE', type: 'APPLICATION_LOADING_DONE',
routeName: 'Folders',
}); });
// console.info(initialFolders);
// if (initialFolders.length) {
// // const selectedFolder = await Folder.defaultFolder();
// // this.props.dispatch({
// // type: 'Navigation/NAVIGATE',
// // routeName: 'Notes',
// // params: selectedFolder.id,
// // });
// }
} catch (error) { } catch (error) {
Log.error('Initialization error:', error); Log.error('Initialization error:', error);
} }