vn-verdnaturachat/app/index.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-08-22 01:24:41 +00:00
import PropTypes from 'prop-types';
2017-08-21 00:11:46 +00:00
import React from 'react';
import { connect } from 'react-redux';
import { Text } from 'react-native';
import setNavigator from './actions/navigator';
import LoginView from './views/login';
import ListServerView from './views/serverList';
import store from './lib/createStore';
export const authenticated = WrappedComponent => class _p extends React.PureComponent {
constructor() {
super();
this.login = store.getState().login;
console.log('this.login.token', this.login.token);
if (!this.login.token || this.login.failure) {
return store.getState().navigator.resetTo({
screen: 'Login'
});
}
}
render() {
// Wraps the input component in a container, without mutating it. Good!
return <WrappedComponent {...this.props} />;
}
};
//
export class PublicScreen extends React.PureComponent {
render() {
return !this.login.isAuthenticated || !this.login.user ? null : (<ListServerView {...this.props} />);
}
}
@connect(null, dispatch => ({
setNavigator: navigator => dispatch(setNavigator(navigator))
}))
export class PrivateScreen extends React.PureComponent {
render() {
return (<LoginView {...this.props} />);
}
}
2017-08-22 01:24:41 +00:00
@connect(() => ({
2017-08-21 00:11:46 +00:00
// logged: state.login.isAuthenticated
}), dispatch => ({
setNavigator: navigator => dispatch(setNavigator(navigator))
}))
export const HomeScreen = class extends React.PureComponent {
2017-08-22 01:24:41 +00:00
static propTypes = {
setNavigator: PropTypes.func.isRequired,
2017-08-22 01:24:41 +00:00
navigator: PropTypes.object.isRequired
}
2017-08-21 00:11:46 +00:00
componentWillMount() {
this.props.setNavigator(this.props.navigator);
this.props.navigator.resetTo({
screen: 'public'
});
}
render() {
return (<Text>oieee</Text>);
}
};