diff --git a/ReactNativeClient/lib/components/action-button.js b/ReactNativeClient/lib/components/action-button.js index 63ddf88864..58956496a0 100644 --- a/ReactNativeClient/lib/components/action-button.js +++ b/ReactNativeClient/lib/components/action-button.js @@ -44,21 +44,31 @@ class ActionButtonComponent extends React.Component { } render() { - return ( - + let buttons = []; - { this.newTodo_press() }}> + if (this.props.folders.length) { + buttons.push( + { this.newTodo_press() }}> + ); - { this.newNote_press() }}> + buttons.push( + { this.newNote_press() }}> + ); + } - { this.newFolder_press() }}> - - + buttons.push( + { this.newFolder_press() }}> + + + ); + return ( + + { buttons } ); } @@ -66,7 +76,9 @@ class ActionButtonComponent extends React.Component { const ActionButton = connect( (state) => { - return {}; + return { + folders: state.folders, + }; } )(ActionButtonComponent) diff --git a/ReactNativeClient/lib/components/screens/folder.js b/ReactNativeClient/lib/components/screens/folder.js index fa07df42c3..37eea9e904 100644 --- a/ReactNativeClient/lib/components/screens/folder.js +++ b/ReactNativeClient/lib/components/screens/folder.js @@ -50,6 +50,12 @@ class FolderScreenComponent extends React.Component { this.originalFolder = await Folder.save(toSave); this.setState({ folder: this.originalFolder }); + + this.props.dispatch({ + type: 'Navigation/NAVIGATE', + routeName: 'Notes', + params: toSave.id, + }); } render() { diff --git a/ReactNativeClient/lib/components/screens/loading.js b/ReactNativeClient/lib/components/screens/loading.js index d1285dd535..dd0bab526d 100644 --- a/ReactNativeClient/lib/components/screens/loading.js +++ b/ReactNativeClient/lib/components/screens/loading.js @@ -2,8 +2,8 @@ import React, { Component } from 'react'; import { View, Text } from 'react-native'; import { connect } from 'react-redux' import { Log } from 'lib/log.js' -import { Folder } from 'lib/models/folder.js' import { ScreenHeader } from 'lib/components/screen-header.js'; +import { ActionButton } from 'lib/components/action-button.js'; class LoadingScreenComponent extends React.Component { @@ -12,18 +12,30 @@ class LoadingScreenComponent extends React.Component { } render() { - return ( - - Loading... - - ); + if (this.props.loading) { + return ( + + Loading... + + ); + } else { + return ( + + + You currently have no notebook. Create one by clicking on (+) button. + + + ); + } } } const LoadingScreen = connect( (state) => { - return {}; + return { + loading: state.loading, + }; } )(LoadingScreenComponent) diff --git a/ReactNativeClient/root.js b/ReactNativeClient/root.js index 47d54c0bc4..98f77160b1 100644 --- a/ReactNativeClient/root.js +++ b/ReactNativeClient/root.js @@ -43,6 +43,8 @@ let defaultState = { selectedItemType: 'note', selectedFolderId: null, showSideMenu: false, + screens: {}, + loading: true, }; const reducer = (state = defaultState, action) => { @@ -76,10 +78,18 @@ const reducer = (state = defaultState, action) => { 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 the current screen is already the requested screen, don't do anything } 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) { newState.nav = nextStateNav; } @@ -87,6 +97,13 @@ const reducer = (state = defaultState, action) => { 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 case 'NOTES_UPDATE_ALL': @@ -186,7 +203,7 @@ const AppNavigator = StackNavigator({ Notes: { screen: NotesScreen }, Note: { screen: NoteScreen }, Folder: { screen: FolderScreen }, - Folders: { screen: FoldersScreen }, + //Folders: { screen: FoldersScreen }, Loading: { screen: LoadingScreen }, OneDriveLogin: { screen: OneDriveLoginScreen }, Log: { screen: LogScreen }, @@ -259,7 +276,7 @@ class AppComponent extends React.Component { if (Setting.value('env') == 'prod') { await db.open({ name: 'joplin.sqlite' }) } 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 folders'); @@ -274,17 +291,27 @@ class AppComponent extends React.Component { await Setting.load(); reg.logger().info('Loading folders...'); - let folders = await Folder.all(); + let initialFolders = await Folder.all(); this.props.dispatch({ type: 'FOLDERS_UPDATE_ALL', - folders: folders, + folders: initialFolders, }); this.props.dispatch({ - type: 'Navigation/NAVIGATE', - routeName: 'Folders', + type: 'APPLICATION_LOADING_DONE', }); + + // console.info(initialFolders); + + // if (initialFolders.length) { + // // const selectedFolder = await Folder.defaultFolder(); + // // this.props.dispatch({ + // // type: 'Navigation/NAVIGATE', + // // routeName: 'Notes', + // // params: selectedFolder.id, + // // }); + // } } catch (error) { Log.error('Initialization error:', error); }