Add route to home page.

This commit is contained in:
Jake Howard 2016-02-06 12:42:44 +00:00
parent 9974d4af91
commit d95035b779
4 changed files with 83 additions and 1 deletions

View file

@ -2,6 +2,7 @@ import { Map } from 'immutable';
import Login from './login'; import Login from './login';
import Info from './info'; import Info from './info';
import Home from './home';
export default Map({ export default Map({
'LOGIN': { 'LOGIN': {
@ -11,5 +12,9 @@ export default Map({
'INFO': { 'INFO': {
id: 'info', id: 'info',
component: Info component: Info
},
'HOME': {
id: 'home',
component: Home
} }
}); });

View file

@ -0,0 +1,47 @@
import React from 'react-native';
const {
StyleSheet,
Text,
View,
ScrollView,
BackAndroid,
} = React;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#333',
},
contentWrapper: {
flex: 0.85,
justifyContent: 'flex-start',
alignItems: 'center'
},
text: {
color: 'white'
}
});
export default class Home extends React.Component {
componentWillUnmount() {
BackAndroid.removeEventListener('hardwareBackPress', () => true);
}
componentWillMount() {
BackAndroid.addEventListener('hardwareBackPress', () => true);
}
render() {
return (
<View style={styles.container}>
<ScrollView keyboardShouldPersistTaps={false} contentContainerStyle={styles.container}>
<View style={styles.contentWrapper}>
<Text style={styles.text}>Home</Text>
</View>
</ScrollView>
</View>
);
}
};

View file

@ -2,6 +2,11 @@ import React from 'react-native';
import GlobalStyles from '../../settings/styles'; import GlobalStyles from '../../settings/styles';
import TokenHelp from '../login/token-help'; import TokenHelp from '../login/token-help';
import RouteMaster from './RouteMaster'; import RouteMaster from './RouteMaster';
import { checkToken } from '../../api/CircleCI';
import { set } from '../../api/token';
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
import BusyIndicator from 'react-native-busy-indicator';
const dismissKeyboard = require('dismissKeyboard'); const dismissKeyboard = require('dismissKeyboard');
@ -13,7 +18,8 @@ const {
TouchableHighlight, TouchableHighlight,
ScrollView, ScrollView,
BackAndroid, BackAndroid,
TouchableWithoutFeedback TouchableWithoutFeedback,
Alert
} = React; } = React;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@ -89,14 +95,36 @@ export default class Login extends React.Component {
this.showTokenHelp = this.showTokenHelp.bind(this); this.showTokenHelp = this.showTokenHelp.bind(this);
this.hideTokenHelp = this.hideTokenHelp.bind(this); this.hideTokenHelp = this.hideTokenHelp.bind(this);
this.showAbout = this.showAbout.bind(this); this.showAbout = this.showAbout.bind(this);
this.proceed = this.proceed.bind(this);
} }
textChanged(token) { textChanged(token) {
this.setState({ token }); this.setState({ token });
} }
proceed() {
this.props.nav.push(RouteMaster.get('HOME'));
}
validate() { validate() {
loaderHandler.showLoader('Loading');
dismissKeyboard(); dismissKeyboard();
checkToken(this.state.token).then(function (isValid) {
if (isValid) {
Alert.alert('Valid',
'Token accepted!',
[ {text: 'OK' }]);
set(this.state.token).then(this.proceed);
} else {
Alert.alert('Invalid',
'Token not accepted!',
[ {text: 'Return' }]);
this.setState({
token: ''
});
}
loaderHandler.hideLoader();
}.bind(this));
} }
showAbout() { showAbout() {
@ -172,6 +200,7 @@ export default class Login extends React.Component {
</TouchableHighlight> </TouchableHighlight>
</View> </View>
<TokenHelp open={this.state.showTokenHelp} onClose={this.hideTokenHelp} /> <TokenHelp open={this.state.showTokenHelp} onClose={this.hideTokenHelp} />
<BusyIndicator />
</View> </View>
); );
} }

View file

@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"immutable": "=3.7.6", "immutable": "=3.7.6",
"react-native": "=0.19.0", "react-native": "=0.19.0",
"react-native-busy-indicator": "=1.0.6",
"react-native-modalbox": "=1.2.8", "react-native-modalbox": "=1.2.8",
"react-native-side-menu": "=0.18.0", "react-native-side-menu": "=0.18.0",
"react-native-vector-icons": "=1.0.4", "react-native-vector-icons": "=1.0.4",