diff --git a/app/sagas/deepLinking.js b/app/sagas/deepLinking.js index 2069cbd0..ffa04040 100644 --- a/app/sagas/deepLinking.js +++ b/app/sagas/deepLinking.js @@ -5,12 +5,12 @@ import RNUserDefaults from 'rn-user-defaults'; import Navigation from '../lib/Navigation'; import * as types from '../actions/actionsTypes'; -import { selectServerRequest } from '../actions/server'; +import { selectServerRequest, serverInitAdd } from '../actions/server'; import { inviteLinksSetToken, inviteLinksRequest } from '../actions/inviteLinks'; import database from '../lib/database'; import RocketChat from '../lib/rocketchat'; import EventEmitter from '../utils/events'; -import { appStart, ROOT_INSIDE } from '../actions/app'; +import { appStart, ROOT_INSIDE, ROOT_NEW_SERVER } from '../actions/app'; import { localAuthenticate } from '../utils/localAuthentication'; import { goRoom } from '../utils/goRoom'; @@ -106,7 +106,8 @@ const handleOpen = function* handleOpen({ params }) { if (!result.success) { return; } - Navigation.navigate('NewServerView', { previousServer: server }); + yield put(appStart({ root: ROOT_NEW_SERVER })); + yield put(serverInitAdd(server)); yield delay(1000); EventEmitter.emit('NewServer', { server: host }); diff --git a/app/views/NewServerView.js b/app/views/NewServerView.js index f49ddbab..5d2726cd 100644 --- a/app/views/NewServerView.js +++ b/app/views/NewServerView.js @@ -12,6 +12,7 @@ import parse from 'url-parse'; import EventEmitter from '../utils/events'; import { selectServerRequest, serverRequest } from '../actions/server'; +import { inviteLinksClear as inviteLinksClearAction } from '../actions/inviteLinks'; import sharedStyles from './Styles'; import Button from '../containers/Button'; import TextInput from '../containers/TextInput'; @@ -72,16 +73,13 @@ class NewServerView extends React.Component { connectServer: PropTypes.func.isRequired, selectServer: PropTypes.func.isRequired, adding: PropTypes.bool, - previousServer: PropTypes.string + previousServer: PropTypes.string, + inviteLinksClear: PropTypes.func } constructor(props) { super(props); - if (props.adding) { - props.navigation.setOptions({ - headerLeft: () => - }); - } + this.setHeader(); this.state = { text: '', @@ -92,11 +90,27 @@ class NewServerView extends React.Component { BackHandler.addEventListener('hardwareBackPress', this.handleBackPress); } + componentDidUpdate(prevProps) { + const { adding } = this.props; + if (prevProps.adding !== adding) { + this.setHeader(); + } + } + componentWillUnmount() { EventEmitter.removeListener('NewServer', this.handleNewServerEvent); BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress); } + setHeader = () => { + const { adding, navigation } = this.props; + if (adding) { + navigation.setOptions({ + headerLeft: () => + }); + } + } + handleBackPress = () => { const { navigation, previousServer } = this.props; if (navigation.isFocused() && previousServer) { @@ -111,7 +125,8 @@ class NewServerView extends React.Component { } close = () => { - const { selectServer, previousServer } = this.props; + const { selectServer, previousServer, inviteLinksClear } = this.props; + inviteLinksClear(); selectServer(previousServer); } @@ -324,7 +339,8 @@ const mapStateToProps = state => ({ const mapDispatchToProps = dispatch => ({ connectServer: (server, certificate) => dispatch(serverRequest(server, certificate)), - selectServer: server => dispatch(selectServerRequest(server)) + selectServer: server => dispatch(selectServerRequest(server)), + inviteLinksClear: () => dispatch(inviteLinksClearAction()) }); export default connect(mapStateToProps, mapDispatchToProps)(withTheme(NewServerView));