From 09e22b6eca7f9410dcd91d1ed667665562bf385c Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 28 Apr 2016 17:48:07 +0100 Subject: [PATCH] Setup start of redux login action --- app/api/CircleCI.js | 2 +- app/components/routes/login.js | 40 +++++++++--------------------- app/settings/constants.js | 3 ++- app/{api => settings}/endpoints.js | 0 4 files changed, 15 insertions(+), 30 deletions(-) rename app/{api => settings}/endpoints.js (100%) diff --git a/app/api/CircleCI.js b/app/api/CircleCI.js index 8751172..cd427c5 100644 --- a/app/api/CircleCI.js +++ b/app/api/CircleCI.js @@ -1,4 +1,4 @@ -import endpoints from './endpoints'; +import endpoints from '../settings/endpoints'; import request from './request'; import token from './token'; diff --git a/app/components/routes/login.js b/app/components/routes/login.js index e7c6f3d..65281b8 100644 --- a/app/components/routes/login.js +++ b/app/components/routes/login.js @@ -2,9 +2,9 @@ import React from 'react-native'; import GlobalStyles from '../../settings/styles'; import TokenHelp from '../login/token-help'; import RouteMaster from './RouteMaster'; -import { checkToken } from '../../api/CircleCI'; -import token from '../../api/token'; import loaderHandler from 'react-native-busy-indicator/LoaderHandler'; +import { connect } from 'react-redux'; +import { login }from '../../actions'; const dismissKeyboard = require('dismissKeyboard'); @@ -76,7 +76,7 @@ const styles = StyleSheet.create({ } }); -export default class Login extends React.Component { +export class Login extends React.Component { constructor() { super(); this.state = { @@ -101,18 +101,12 @@ export default class Login extends React.Component { this.showTokenHelp = this.showTokenHelp.bind(this); this.hideTokenHelp = this.hideTokenHelp.bind(this); this.showAbout = this.showAbout.bind(this); - this.proceed = this.proceed.bind(this); } textChanged(CIToken) { this.setState({ token: CIToken }); } - proceed() { - this.hideTokenHelp(); - this.props.nav.replace(RouteMaster.get('HOME')); - } - invalidToken() { Alert.alert('Invalid', 'Token not accepted!', @@ -127,17 +121,7 @@ export default class Login extends React.Component { loaderHandler.hideLoader(); return; } - checkToken(this.state.token).then(function (isValid) { - if (isValid) { - token.set(this.state.token).then(this.proceed); - } else { - this.invalidToken(); - this.setState({ - token: '' - }); - } - loaderHandler.hideLoader(); - }.bind(this)).catch(console.log); + this.props.login(this.state.token); } showAbout() { @@ -163,14 +147,6 @@ export default class Login extends React.Component { componentWillMount() { BackAndroid.addEventListener('hardwareBackPress', () => { return true; }); // Disable back button - token.get().then(function (CIToken) { - if (!CIToken) { - return; - } - checkToken(CIToken).then(function (isValid) { - this.proceed(); - }.bind(this)); - }.bind(this)); } componentDidMount() { @@ -223,3 +199,11 @@ export default class Login extends React.Component { ); } }; + +function mapStateToProps(state) { + return { + token: state.user.get('token') + }; +} + +export default connect(mapStateToProps, { login }) (Login); diff --git a/app/settings/constants.js b/app/settings/constants.js index 73ed28d..e08c966 100644 --- a/app/settings/constants.js +++ b/app/settings/constants.js @@ -4,5 +4,6 @@ export default Map({ PROJECT_DATA: { repository: 'https://github.com/RealOrangeOne/Sphere', CI_Badge: 'https://circleci.com/gh/RealOrangeOne/Sphere.svg?style=svg' - } + }, + STORAGE_KEY: 'SphereStorageKey' }); diff --git a/app/api/endpoints.js b/app/settings/endpoints.js similarity index 100% rename from app/api/endpoints.js rename to app/settings/endpoints.js