Add server working
This commit is contained in:
parent
cef50fe7c0
commit
3b93c11001
|
@ -30,7 +30,7 @@ const SetUsernameStack = () => (
|
||||||
|
|
||||||
// App
|
// App
|
||||||
const Stack = createStackNavigator();
|
const Stack = createStackNavigator();
|
||||||
const App = ({ root }) => {
|
const App = React.memo(({ root }) => {
|
||||||
if (!root || root === 'background') {
|
if (!root || root === 'background') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ const App = ({ root }) => {
|
||||||
component={AuthLoadingView}
|
component={AuthLoadingView}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{root === 'outside' ? (
|
{root === 'outside' || root === 'newServer' ? (
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
name='OutsideStack'
|
name='OutsideStack'
|
||||||
component={OutsideStack}
|
component={OutsideStack}
|
||||||
|
@ -74,7 +74,7 @@ const App = ({ root }) => {
|
||||||
</NavigationContainer>
|
</NavigationContainer>
|
||||||
</SafeAreaProvider>
|
</SafeAreaProvider>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
root: state.app.root
|
root: state.app.root
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { APP, APP_STATE } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
root: null,
|
root: null,
|
||||||
|
text: null,
|
||||||
ready: false,
|
ready: false,
|
||||||
foreground: true,
|
foreground: true,
|
||||||
background: false
|
background: false
|
||||||
|
@ -24,7 +25,8 @@ export default function app(state = initialState, action) {
|
||||||
case APP.START:
|
case APP.START:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
root: action.root
|
root: action.root,
|
||||||
|
text: action.text,
|
||||||
};
|
};
|
||||||
case APP.INIT:
|
case APP.INIT:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { createStackNavigator } from '@react-navigation/stack';
|
import { createStackNavigator } from '@react-navigation/stack';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { ThemeContext } from '../theme';
|
import { ThemeContext } from '../theme';
|
||||||
import { defaultHeader, themedHeader } from '../utils/navigation';
|
import { defaultHeader, themedHeader } from '../utils/navigation';
|
||||||
|
@ -16,16 +17,18 @@ import AuthenticationWebView from '../views/AuthenticationWebView';
|
||||||
|
|
||||||
// Outside
|
// Outside
|
||||||
const Outside = createStackNavigator();
|
const Outside = createStackNavigator();
|
||||||
const OutsideStack = () => {
|
const _OutsideStack = ({ root }) => {
|
||||||
const { theme } = React.useContext(ThemeContext);
|
const { theme } = React.useContext(ThemeContext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Outside.Navigator screenOptions={{ ...defaultHeader, ...themedHeader(theme) }}>
|
<Outside.Navigator screenOptions={{ ...defaultHeader, ...themedHeader(theme) }}>
|
||||||
<Outside.Screen
|
{root === 'outside' ? (
|
||||||
name='OnboardingView'
|
<Outside.Screen
|
||||||
component={OnboardingView}
|
name='OnboardingView'
|
||||||
options={OnboardingView.navigationOptions}
|
component={OnboardingView}
|
||||||
/>
|
options={OnboardingView.navigationOptions}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<Outside.Screen
|
<Outside.Screen
|
||||||
name='NewServerView'
|
name='NewServerView'
|
||||||
component={NewServerView}
|
component={NewServerView}
|
||||||
|
@ -60,6 +63,12 @@ const OutsideStack = () => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = state => ({
|
||||||
|
root: state.app.root
|
||||||
|
});
|
||||||
|
|
||||||
|
const OutsideStack = connect(mapStateToProps)(_OutsideStack);
|
||||||
|
|
||||||
// OutsideStackModal
|
// OutsideStackModal
|
||||||
const OutsideModal = createStackNavigator();
|
const OutsideModal = createStackNavigator();
|
||||||
const OutsideStackModal = () => {
|
const OutsideStackModal = () => {
|
||||||
|
|
|
@ -64,17 +64,6 @@ const styles = StyleSheet.create({
|
||||||
});
|
});
|
||||||
|
|
||||||
class NewServerView extends React.Component {
|
class NewServerView extends React.Component {
|
||||||
// TODO: ?
|
|
||||||
// static navigationOptions = ({ screenProps, navigation }) => {
|
|
||||||
// const previousServer = navigation.getParam('previousServer', null);
|
|
||||||
// const close = navigation.getParam('close', () => {});
|
|
||||||
// return {
|
|
||||||
// headerLeft: previousServer ? <CloseModalButton navigation={navigation} onPress={close} testID='new-server-view-close' /> : undefined,
|
|
||||||
// title: I18n.t('Workspaces'),
|
|
||||||
// ...themedHeader(screenProps.theme)
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
static navigationOptions = {
|
static navigationOptions = {
|
||||||
title: I18n.t('Workspaces')
|
title: I18n.t('Workspaces')
|
||||||
}
|
}
|
||||||
|
@ -86,15 +75,16 @@ class NewServerView extends React.Component {
|
||||||
connectServer: PropTypes.func.isRequired,
|
connectServer: PropTypes.func.isRequired,
|
||||||
selectServer: PropTypes.func.isRequired,
|
selectServer: PropTypes.func.isRequired,
|
||||||
currentServer: PropTypes.string,
|
currentServer: PropTypes.string,
|
||||||
|
previousServer: PropTypes.string,
|
||||||
initAdd: PropTypes.func,
|
initAdd: PropTypes.func,
|
||||||
finishAdd: PropTypes.func
|
finishAdd: PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
// TODO: add server logic
|
props.navigation.setOptions({
|
||||||
// this.previousServer = props.route.params?.previousServer;
|
headerLeft: () => <CloseModalButton navigation={props.navigation} onPress={this.close} testID='new-server-view-close' />
|
||||||
// props.navigation.setParams({ close: this.close, previousServer: this.previousServer });
|
});
|
||||||
|
|
||||||
// Cancel
|
// Cancel
|
||||||
this.options = [I18n.t('Cancel')];
|
this.options = [I18n.t('Cancel')];
|
||||||
|
@ -114,8 +104,8 @@ class NewServerView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { initAdd } = this.props;
|
const { initAdd, previousServer } = this.props;
|
||||||
if (this.previousServer) {
|
if (previousServer) {
|
||||||
initAdd();
|
initAdd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,8 +116,8 @@ class NewServerView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleBackPress = () => {
|
handleBackPress = () => {
|
||||||
const { navigation } = this.props;
|
const { navigation, previousServer } = this.props;
|
||||||
if (navigation.isFocused() && this.previousServer) {
|
if (navigation.isFocused() && previousServer) {
|
||||||
this.close();
|
this.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -139,9 +129,11 @@ class NewServerView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
close = () => {
|
close = () => {
|
||||||
const { selectServer, currentServer, finishAdd } = this.props;
|
const {
|
||||||
if (this.previousServer !== currentServer) {
|
selectServer, currentServer, finishAdd, previousServer
|
||||||
selectServer(this.previousServer);
|
} = this.props;
|
||||||
|
if (previousServer !== currentServer) {
|
||||||
|
selectServer(previousServer);
|
||||||
}
|
}
|
||||||
finishAdd();
|
finishAdd();
|
||||||
}
|
}
|
||||||
|
@ -349,7 +341,8 @@ class NewServerView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
connecting: state.server.connecting
|
connecting: state.server.connecting,
|
||||||
|
previousServer: state.app.text
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
|
|
|
@ -10,6 +10,7 @@ import RNUserDefaults from 'rn-user-defaults';
|
||||||
|
|
||||||
import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms';
|
import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms';
|
||||||
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
|
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
|
||||||
|
import { appStart as appStartAction } from '../../actions';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import Touch from '../../utils/touch';
|
import Touch from '../../utils/touch';
|
||||||
import RocketChat from '../../lib/rocketchat';
|
import RocketChat from '../../lib/rocketchat';
|
||||||
|
@ -123,17 +124,17 @@ class ServerDropdown extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
addServer = () => {
|
addServer = () => {
|
||||||
const { server, navigation } = this.props;
|
const { server, appStart } = this.props;
|
||||||
|
|
||||||
this.close();
|
this.close();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigation.navigate('NewServerView', { previousServer: server });
|
appStart('newServer', server);
|
||||||
}, ANIMATION_DURATION);
|
}, ANIMATION_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
select = async(server) => {
|
select = async(server) => {
|
||||||
const {
|
const {
|
||||||
server: currentServer, selectServerRequest, navigation, split
|
server: currentServer, selectServerRequest, navigation, split, appStart
|
||||||
} = this.props;
|
} = this.props;
|
||||||
this.close();
|
this.close();
|
||||||
if (currentServer !== server) {
|
if (currentServer !== server) {
|
||||||
|
@ -143,7 +144,7 @@ class ServerDropdown extends Component {
|
||||||
}
|
}
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigation.navigate('NewServerView', { previousServer: currentServer });
|
appStart('newServer', server);
|
||||||
this.newServerTimeout = setTimeout(() => {
|
this.newServerTimeout = setTimeout(() => {
|
||||||
EventEmitter.emit('NewServer', { server });
|
EventEmitter.emit('NewServer', { server });
|
||||||
}, ANIMATION_DURATION);
|
}, ANIMATION_DURATION);
|
||||||
|
@ -285,7 +286,8 @@ const mapStateToProps = state => ({
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
toggleServerDropdown: () => dispatch(toggleServerDropdownAction()),
|
toggleServerDropdown: () => dispatch(toggleServerDropdownAction()),
|
||||||
selectServerRequest: server => dispatch(selectServerRequestAction(server))
|
selectServerRequest: server => dispatch(selectServerRequestAction(server)),
|
||||||
|
appStart: (param, text) => dispatch(appStartAction(param, text))
|
||||||
});
|
});
|
||||||
|
|
||||||
export default withNavigation(connect(mapStateToProps, mapDispatchToProps)(withTheme(withSplit(ServerDropdown))));
|
export default withNavigation(connect(mapStateToProps, mapDispatchToProps)(withTheme(withSplit(ServerDropdown))));
|
||||||
|
|
Loading…
Reference in New Issue