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 Info from './info';
import Home from './home';
export default Map({
'LOGIN': {
@ -11,5 +12,9 @@ export default Map({
'INFO': {
id: '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 TokenHelp from '../login/token-help';
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');
@ -13,7 +18,8 @@ const {
TouchableHighlight,
ScrollView,
BackAndroid,
TouchableWithoutFeedback
TouchableWithoutFeedback,
Alert
} = React;
const styles = StyleSheet.create({
@ -89,14 +95,36 @@ 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(token) {
this.setState({ token });
}
proceed() {
this.props.nav.push(RouteMaster.get('HOME'));
}
validate() {
loaderHandler.showLoader('Loading');
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() {
@ -172,6 +200,7 @@ export default class Login extends React.Component {
</TouchableHighlight>
</View>
<TokenHelp open={this.state.showTokenHelp} onClose={this.hideTokenHelp} />
<BusyIndicator />
</View>
);
}

View file

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