diff --git a/ReactNativeClient/lib/components/screen-header.js b/ReactNativeClient/lib/components/screen-header.js index dc3bcd230..677cbb7ff 100644 --- a/ReactNativeClient/lib/components/screen-header.js +++ b/ReactNativeClient/lib/components/screen-header.js @@ -7,6 +7,7 @@ import { _ } from 'lib/locale.js'; import { Setting } from 'lib/models/setting.js'; import { FileApi } from 'lib/file-api.js'; import { FileApiDriverOneDrive } from 'lib/file-api-driver-onedrive.js'; +import { reg } from 'lib/registry.js' const styles = StyleSheet.create({ divider: { @@ -40,25 +41,20 @@ class ScreenHeaderComponent extends Component { } } - menu_synchronize() { - this.props.dispatch({ - type: 'Navigation/NAVIGATE', - routeName: 'OneDriveLogin', - }); - - // const CLIENT_ID = 'e09fc0de-c958-424f-83a2-e56a721d331b'; - // const CLIENT_SECRET = 'JA3cwsqSGHFtjMwd5XoF5L5'; - - // let driver = new FileApiDriverOneDrive(CLIENT_ID, CLIENT_SECRET); - // let auth = Setting.value('sync.onedrive.auth'); - - // if (auth) { - // auth = JSON.parse(auth); - // } else { - // driver.api().oauthDance(vorpal); - // //auth = driver.api().oauthDance(vorpal); - // //Setting.setValue('sync.onedrive.auth', JSON.stringify(auth)); - // } + async menu_synchronize() { + if (reg.oneDriveApi().auth()) { + const sync = await reg.synchronizer(); + try { + sync.start(); + } catch (error) { + Log.error(error); + } + } else { + this.props.dispatch({ + type: 'Navigation/NAVIGATE', + routeName: 'OneDriveLogin', + }); + } } render() { diff --git a/ReactNativeClient/lib/components/screens/onedrive-login.js b/ReactNativeClient/lib/components/screens/onedrive-login.js index f192c1f9c..7750dfed1 100644 --- a/ReactNativeClient/lib/components/screens/onedrive-login.js +++ b/ReactNativeClient/lib/components/screens/onedrive-login.js @@ -3,8 +3,9 @@ import { View } from 'react-native'; import { WebView, Button } from 'react-native'; import { connect } from 'react-redux' import { Log } from 'lib/log.js' +import { Setting } from 'lib/models/setting.js' import { ScreenHeader } from 'lib/components/screen-header.js'; -import { OneDriveApi } from 'lib/onedrive-api.js'; +import { reg } from 'lib/registry.js'; import { _ } from 'lib/locale.js'; class OneDriveLoginScreenComponent extends React.Component { @@ -21,13 +22,10 @@ class OneDriveLoginScreenComponent extends React.Component { componentWillMount() { this.setState({ - webviewUrl: this.api().authCodeUrl(this.redirectUrl()), + webviewUrl: reg.oneDriveApi().authCodeUrl(this.redirectUrl()), }); } - api() { - return OneDriveApi.instance(); - redirectUrl() { return 'https://login.microsoftonline.com/common/oauth2/nativeclient'; } @@ -38,25 +36,15 @@ class OneDriveLoginScreenComponent extends React.Component { // at the moment so it's likely to change. const url = noIdeaWhatThisIs.url; - console.info('URL: ' + url); + if (!this.authCode_ && url.indexOf(this.redirectUrl() + '?code=') === 0) { + console.info('URL: ' + url); - if (!this.authCode_) { - if (url.indexOf(this.redirectUrl() + '?code=') === 0) { - let code = url.split('?code='); - this.authCode_ = code[1]; + let code = url.split('?code='); + this.authCode_ = code[1]; - await this.api().execTokenRequest(this.authCode_, this.redirectUrl(), true); - Setting.setValue('sync.onedrive.auth', JSON.stringify(this.api().auth())); - oneDriveApi.on('authRefreshed', (a) => { - Setting.setValue('sync.onedrive.auth', JSON.stringify(a)); - }); + await reg.oneDriveApi().execTokenRequest(this.authCode_, this.redirectUrl(), true); - let appDir = await this.api().appDirectory(); - - Log.info('APP DIR: ' + appDir); - // fileApi = new FileApi(appDir, driver); - // fileApi.setLogger(logger); - } + this.authCode_ = null; } } @@ -65,8 +53,6 @@ class OneDriveLoginScreenComponent extends React.Component { uri: this.state.webviewUrl, } - // - return ( diff --git a/ReactNativeClient/lib/components/side-menu-content.js b/ReactNativeClient/lib/components/side-menu-content.js index 5dbf66df8..5aae3b5d5 100644 --- a/ReactNativeClient/lib/components/side-menu-content.js +++ b/ReactNativeClient/lib/components/side-menu-content.js @@ -53,7 +53,7 @@ class SideMenuContentComponent extends Component { let buttons = []; for (let i = 0; i < this.props.folders.length; i++) { let f = this.props.folders[i]; - let title = f.title; + let title = f.title ? f.title : ''; buttons.push(