diff --git a/ElectronClient/app/gui/OneDriveAuthScreen.jsx b/ElectronClient/app/gui/OneDriveLoginScreen.jsx similarity index 92% rename from ElectronClient/app/gui/OneDriveAuthScreen.jsx rename to ElectronClient/app/gui/OneDriveLoginScreen.jsx index 7e8be9833..6d4483e8e 100644 --- a/ElectronClient/app/gui/OneDriveAuthScreen.jsx +++ b/ElectronClient/app/gui/OneDriveLoginScreen.jsx @@ -6,7 +6,7 @@ const { Header } = require('./Header.min.js'); const { themeStyle } = require('../theme.js'); const { _ } = require('lib/locale.js'); -class OneDriveAuthScreenComponent extends React.Component { +class OneDriveLoginScreenComponent extends React.Component { constructor() { super(); @@ -104,6 +104,6 @@ const mapStateToProps = (state) => { return {}; }; -const OneDriveAuthScreen = connect(mapStateToProps)(OneDriveAuthScreenComponent); +const OneDriveLoginScreen = connect(mapStateToProps)(OneDriveLoginScreenComponent); -module.exports = { OneDriveAuthScreen }; \ No newline at end of file +module.exports = { OneDriveLoginScreen }; \ No newline at end of file diff --git a/ElectronClient/app/gui/Root.jsx b/ElectronClient/app/gui/Root.jsx index d4abff66d..e4e46718f 100644 --- a/ElectronClient/app/gui/Root.jsx +++ b/ElectronClient/app/gui/Root.jsx @@ -4,7 +4,7 @@ const { createStore } = require('redux'); const { connect, Provider } = require('react-redux'); const { MainScreen } = require('./MainScreen.min.js'); -const { OneDriveAuthScreen } = require('./OneDriveAuthScreen.min.js'); +const { OneDriveLoginScreen } = require('./OneDriveLoginScreen.min.js'); const { Navigator } = require('./Navigator.min.js'); const { app } = require('../app'); @@ -51,7 +51,7 @@ class RootComponent extends React.Component { const screens = { Main: { screen: MainScreen }, - OneDriveAuth: { screen: OneDriveAuthScreen }, + OneDriveLogin: { screen: OneDriveLoginScreen }, }; return ( diff --git a/ElectronClient/app/gui/SideBar.jsx b/ElectronClient/app/gui/SideBar.jsx index 87ede1f1b..9f465b0e1 100644 --- a/ElectronClient/app/gui/SideBar.jsx +++ b/ElectronClient/app/gui/SideBar.jsx @@ -19,11 +19,8 @@ class SideBarComponent extends React.Component { }); } - sync_click() { - this.props.dispatch({ - type: 'NAV_GO', - routeName: 'OneDriveAuth', - }); + async sync_click() { + await shared.synchronize_press(this); } folderItem(folder, selected) { diff --git a/ReactNativeClient/lib/BaseApplication.js b/ReactNativeClient/lib/BaseApplication.js index 6bd543a00..2dbd03a7f 100644 --- a/ReactNativeClient/lib/BaseApplication.js +++ b/ReactNativeClient/lib/BaseApplication.js @@ -182,13 +182,13 @@ class BaseApplication { reducerActionToString(action) { let o = [action.type]; - if (action.id) o.push(action.id); - if (action.noteId) o.push(action.noteId); - if (action.folderId) o.push(action.folderId); - if (action.tagId) o.push(action.tagId); - if (action.tag) o.push(action.tag.id); - if (action.folder) o.push(action.folder.id); - if (action.notesSource) o.push(JSON.stringify(action.notesSource)); + if ('id' in action) o.push(action.id); + if ('noteId' in action) o.push(action.noteId); + if ('folderId' in action) o.push(action.folderId); + if ('tagId' in action) o.push(action.tagId); + if ('tag' in action) o.push(action.tag.id); + if ('folder' in action) o.push(action.folder.id); + if ('notesSource' in action) o.push(JSON.stringify(action.notesSource)); return o.join(', '); } @@ -239,6 +239,7 @@ class BaseApplication { this.store_ = createStore(this.reducer, applyMiddleware(this.generalMiddleware())); BaseModel.dispatch = this.store().dispatch; FoldersScreenUtils.dispatch = this.store().dispatch; + reg.dispatch = this.store().dispatch; } async start(argv) { diff --git a/ReactNativeClient/lib/components/shared/side-menu-shared.js b/ReactNativeClient/lib/components/shared/side-menu-shared.js index 5bf6c7dba..63392e01d 100644 --- a/ReactNativeClient/lib/components/shared/side-menu-shared.js +++ b/ReactNativeClient/lib/components/shared/side-menu-shared.js @@ -20,4 +20,36 @@ shared.renderTags = function(props, renderItem) { return tagItems; } +shared.synchronize_press = async function(comp) { + const { Setting } = require('lib/models/setting.js'); + const { reg } = require('lib/registry.js'); + + const action = comp.props.syncStarted ? 'cancel' : 'start'; + + if (Setting.value('sync.target') == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) { + comp.props.dispatch({ + type: 'NAV_GO', + routeName: 'OneDriveLogin', + }); + return 'auth'; + } + + let sync = null; + try { + sync = await reg.synchronizer(Setting.value('sync.target')) + } catch (error) { + reg.logger().info('Could not acquire synchroniser:'); + reg.logger().info(error); + return 'error'; + } + + if (action == 'cancel') { + sync.cancel(); + return 'cancel'; + } else { + reg.scheduleSync(0); + return 'sync'; + } +} + module.exports = shared; \ No newline at end of file diff --git a/ReactNativeClient/lib/components/side-menu-content.js b/ReactNativeClient/lib/components/side-menu-content.js index 71bc083c1..d4abbcca9 100644 --- a/ReactNativeClient/lib/components/side-menu-content.js +++ b/ReactNativeClient/lib/components/side-menu-content.js @@ -105,32 +105,8 @@ class SideMenuContentComponent extends Component { } async synchronize_press() { - const action = this.props.syncStarted ? 'cancel' : 'start'; - - if (Setting.value('sync.target') == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) { - this.props.dispatch({ type: 'SIDE_MENU_CLOSE' }); - - this.props.dispatch({ - type: 'NAV_GO', - routeName: 'OneDriveLogin', - }); - return; - } - - let sync = null; - try { - sync = await reg.synchronizer(Setting.value('sync.target')) - } catch (error) { - reg.logger().info('Could not acquire synchroniser:'); - reg.logger().info(error); - return; - } - - if (action == 'cancel') { - sync.cancel(); - } else { - reg.scheduleSync(0); - } + const actionDone = await shared.synchronize_press(this); + if (actionDone === 'auth') this.props.dispatch({ type: 'SIDE_MENU_CLOSE' }); } folderItem(folder, selected) {