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';
|
2017-09-01 19:42:50 +00:00
|
|
|
import { View, Image } from 'react-native';
|
2017-08-21 00:11:46 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-09-01 19:42:50 +00:00
|
|
|
import * as Animatable from 'react-native-animatable';
|
2017-08-21 00:11:46 +00:00
|
|
|
import setNavigator from './actions/navigator';
|
2017-09-01 19:42:50 +00:00
|
|
|
import { appInit } from './actions';
|
2017-08-21 00:11:46 +00:00
|
|
|
import LoginView from './views/login';
|
|
|
|
import ListServerView from './views/serverList';
|
|
|
|
|
2017-09-01 19:42:50 +00:00
|
|
|
|
|
|
|
import styles from './views/Styles';
|
|
|
|
|
2017-08-21 00:11:46 +00:00
|
|
|
import store from './lib/createStore';
|
|
|
|
|
|
|
|
export const authenticated = WrappedComponent => class _p extends React.PureComponent {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.login = store.getState().login;
|
|
|
|
if (!this.login.token || this.login.failure) {
|
|
|
|
return store.getState().navigator.resetTo({
|
2017-09-01 19:42:50 +00:00
|
|
|
screen: 'Login',
|
|
|
|
animated: false
|
2017-08-21 00:11:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
// Wraps the input component in a container, without mutating it. Good!
|
2017-09-01 19:42:50 +00:00
|
|
|
return ((this.login.isAuthenticated || this.login.user) && <WrappedComponent {...this.props} />);
|
2017-08-21 00:11:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
//
|
|
|
|
export class PublicScreen extends React.PureComponent {
|
|
|
|
render() {
|
2017-09-01 19:42:50 +00:00
|
|
|
return ((this.login.isAuthenticated || this.login.user) && <ListServerView {...this.props} />);
|
2017-08-21 00:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@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 => ({
|
2017-09-01 19:42:50 +00:00
|
|
|
setNavigator: navigator => dispatch(setNavigator(navigator)),
|
|
|
|
appInit: () => dispatch(appInit())
|
2017-08-21 00:11:46 +00:00
|
|
|
}))
|
|
|
|
export const HomeScreen = class extends React.PureComponent {
|
2017-08-22 01:24:41 +00:00
|
|
|
static propTypes = {
|
2017-09-01 19:42:50 +00:00
|
|
|
appInit: PropTypes.func.isRequired,
|
2017-08-22 01:43:29 +00:00
|
|
|
setNavigator: PropTypes.func.isRequired,
|
2017-08-22 01:24:41 +00:00
|
|
|
navigator: PropTypes.object.isRequired
|
|
|
|
}
|
2017-09-01 19:42:50 +00:00
|
|
|
static navigatorStyle = {
|
|
|
|
navBarHidden: true,
|
2017-08-22 01:24:41 +00:00
|
|
|
|
2017-09-01 19:42:50 +00:00
|
|
|
rightButtons: [{
|
|
|
|
id: 'close',
|
|
|
|
title: 'Cancel'
|
|
|
|
}]
|
|
|
|
};
|
2017-08-21 00:11:46 +00:00
|
|
|
componentWillMount() {
|
|
|
|
this.props.setNavigator(this.props.navigator);
|
2017-09-01 19:42:50 +00:00
|
|
|
this.props.appInit();
|
|
|
|
//
|
|
|
|
// this.props.navigator.setDrawerEnabled({
|
|
|
|
// side: 'left', // the side of the drawer since you can have two, 'left' / 'right'
|
|
|
|
// enabled: false // should the drawer be enabled or disabled (locked closed)
|
|
|
|
// });
|
2017-08-21 00:11:46 +00:00
|
|
|
}
|
|
|
|
render() {
|
2017-09-01 19:42:50 +00:00
|
|
|
return (<View style={styles.logoContainer}><Animatable.Text animation='pulse' easing='ease-out' iterationCount='infinite' style={{ textAlign: 'center' }}>
|
|
|
|
<Image style={styles.logo} source={require('./images/logo.png')} />
|
|
|
|
</Animatable.Text></View>);
|
2017-08-21 00:11:46 +00:00
|
|
|
}
|
|
|
|
};
|