Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/Expensify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {Component} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {recordCurrentRoute} from './lib/actions/App';

// import {Beforeunload} from 'react-beforeunload';
import SignInPage from './page/SignInPage';
Expand Down Expand Up @@ -40,7 +41,6 @@ class Expensify extends Component {
// Initialize this client as being an active client
ActiveClientManager.init();

this.recordCurrentRoute = this.recordCurrentRoute.bind(this);
this.removeLoadingState = this.removeLoadingState.bind(this);

this.state = {
Expand All @@ -65,15 +65,6 @@ class Expensify extends Component {
});
}

/**
* Keep the current route match stored in Ion so other libs can access it
*
* @param {object} params.match
*/
recordCurrentRoute({match}) {
Ion.set(IONKEYS.CURRENT_URL, match.url);
}

render() {
// Until the authToken has been initialized from Ion, display a blank page
if (this.state.isLoading) {
Expand All @@ -94,7 +85,7 @@ class Expensify extends Component {
{/* If there is ever a property for redirecting, we do the redirect here */}
{/* Leave this as a ternary or else iOS throws an error about text not being wrapped in <Text> */}
{redirectTo ? <Redirect to={redirectTo} /> : null}
<Route path="*" render={this.recordCurrentRoute} />
<Route path="*" render={recordCurrentRoute} />

<Switch>
<Route path={['/signin/exitTo/:exitTo*', '/signin']} component={SignInPage} />
Expand Down
37 changes: 37 additions & 0 deletions src/lib/actions/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Ion from '../Ion';
import IONKEYS from '../../IONKEYS';

let currentRedirectTo;
Ion.connect({
key: IONKEYS.APP_REDIRECT_TO,
callback: val => currentRedirectTo = val,
});

/**
* Keep the current route match stored in Ion so other libs can access it
* Also reset the app_redirect_to in Ion so that if we go back to the current url the state will update
*
* @param {object} match
*/
function recordCurrentRoute({match}) {
Ion.set(IONKEYS.CURRENT_URL, match.url);
if (match.url === currentRedirectTo) {
Ion.set(IONKEYS.APP_REDIRECT_TO, '');
}
}


/**
* Redirect the app to a new page by updating the state in Ion
*
* @param {mixed} url
*/
function redirect(url) {
const formattedURL = (typeof url === 'string' && url.startsWith('/')) ? url : `/${url}`;
Ion.set(IONKEYS.APP_REDIRECT_TO, formattedURL);
}

export {
recordCurrentRoute,
redirect,
};
4 changes: 3 additions & 1 deletion src/lib/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import promiseAllSettled from '../promiseAllSettled';
import ExpensiMark from '../ExpensiMark';
import Notification from '../Notification';
import * as PersonalDetails from './PersonalDetails';
import {redirect} from './App';

let currentUserEmail;
let currentUserAccountID;
Expand Down Expand Up @@ -211,12 +212,13 @@ function updateReportWithNewAction(reportID, reportAction) {
return;
}


console.debug('[NOTIFICATION] Creating notification');
Notification.showCommentNotification({
reportAction,
onClick: () => {
// Navigate to this report onClick
Ion.set(IONKEYS.APP_REDIRECT_TO, `/${reportID}`);
redirect(reportID);
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/actions/SignInRedirect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Ion from '../Ion';
import IONKEYS from '../../IONKEYS';
import ROUTES from '../../ROUTES';
import {redirect} from './App';

/**
* Redirects to the sign in page and handles adding any exitTo params to the URL.
Expand All @@ -24,7 +25,7 @@ function redirectToSignIn() {
const urlWithExitTo = url === '/'
? ROUTES.SIGNIN
: `${ROUTES.SIGNIN}/exitTo${url}`;
return Ion.set(IONKEYS.APP_REDIRECT_TO, urlWithExitTo);
return redirect(urlWithExitTo);
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/page/home/sidebar/ChatSwitcherView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import KeyboardShortcut from '../../../lib/KeyboardShortcut';
import ChatSwitcherList from './ChatSwitcherList';
import ChatSwitcherSearchForm from './ChatSwitcherSearchForm';
import {fetchOrCreateChatReport} from '../../../lib/actions/Report';
import {redirect} from '../../../lib/actions/App';

const propTypes = {
// A method that is triggered when the TextInput gets focus
Expand Down Expand Up @@ -126,7 +127,7 @@ class ChatSwitcherView extends React.Component {
fetchChatReportAndRedirect(option) {
Ion.get(IONKEYS.MY_PERSONAL_DETAILS, 'login')
.then(currentLogin => fetchOrCreateChatReport([currentLogin, option.login]))
.then(reportID => Ion.set(IONKEYS.APP_REDIRECT_TO, `/${reportID}`));
.then(reportID => redirect(reportID));
this.reset();
}

Expand Down
3 changes: 2 additions & 1 deletion src/page/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ChatSwitcherView from './ChatSwitcherView';
import SafeAreaInsetPropTypes from '../../SafeAreaInsetPropTypes';
import compose from '../../../lib/compose';
import {withRouter} from '../../../lib/Router';
import {redirect} from '../../../lib/actions/App';

const propTypes = {
// These are from withRouter
Expand Down Expand Up @@ -125,7 +126,7 @@ export default compose(

// If we're on the home page, then redirect to the first report ID
if (currentURL === '/' && firstReportID) {
Ion.set(IONKEYS.APP_REDIRECT_TO, `/${firstReportID}`);
redirect(firstReportID);
}
});
}),
Expand Down