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 = (view) => {
|
|
|
|
// if (!store.getState().login.authenticated) {
|
|
|
|
// return store.getState().navigator.resetTo({
|
|
|
|
// screen: 'Login'
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// return view;
|
|
|
|
// };
|
|
|
|
|
|
|
|
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 {
|
|
|
|
// componentWillMount() {
|
|
|
|
// this.props.setNavigator(this.props.navigator);
|
|
|
|
// if (this.props.currentServer) {
|
|
|
|
// return this.props.navigator.navigate('private');
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
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 {
|
|
|
|
componentWillMount() {
|
|
|
|
// this.props.setNavigator(this.props.navigator);
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
// if (this.props.logged) {
|
|
|
|
// return (<Text>oi</Text>);
|
|
|
|
// }
|
|
|
|
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 => ({
|
|
|
|
// navigate: routeName => dispatch(NavigationActions.navigate({ routeName })),
|
|
|
|
setNavigator: navigator => dispatch(setNavigator(navigator))
|
|
|
|
}))
|
|
|
|
export const HomeScreen = class extends React.PureComponent {
|
2017-08-22 01:24:41 +00:00
|
|
|
static propTypes = {
|
|
|
|
setNavigator: PropTypes.fun.isRequired,
|
|
|
|
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>);
|
|
|
|
}
|
|
|
|
};
|