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