Skip to content

Commit d8836e6

Browse files
committed
navReducer: Transplant away LOGIN_SUCCESS logic.
Soon, we'll dismantle `navReducer`, as its purpose is incompatible with a design where we manage navigation state separately from our Redux-stored data (#3804). So, convert the `navReducer`'s `LOGIN_SUCCESS` case into instructions to navigate to the loading screen at the dispatch sites.
1 parent a2493b3 commit d8836e6

File tree

3 files changed

+4
-29
lines changed

3 files changed

+4
-29
lines changed

src/nav/__tests__/navReducer-test.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
import deepFreeze from 'deep-freeze';
22

3-
import { LOGIN_SUCCESS, INITIAL_FETCH_COMPLETE } from '../../actionConstants';
3+
import { INITIAL_FETCH_COMPLETE } from '../../actionConstants';
44
import navReducer, { getStateForRoute } from '../navReducer';
55

66
describe('navReducer', () => {
7-
describe('LOGIN_SUCCESS', () => {
8-
test('replaces the existing route stack with "loading" on sign in', () => {
9-
const prevState = deepFreeze({
10-
index: 2,
11-
routes: [{ key: 'one' }, { key: 'two' }, { key: 'password' }],
12-
});
13-
14-
const action = deepFreeze({
15-
type: LOGIN_SUCCESS,
16-
});
17-
18-
const expectedState = {
19-
index: 0,
20-
routes: [{ routeName: 'loading' }],
21-
};
22-
23-
const newState = navReducer(prevState, action);
24-
25-
expect(newState.index).toEqual(expectedState.index);
26-
expect(newState.routes[0].routeName).toEqual(expectedState.routes[0].routeName);
27-
});
28-
});
29-
307
describe('INITIAL_FETCH_COMPLETE', () => {
318
test('do not mutate navigation state if already at the same route', () => {
329
const prevState = getStateForRoute('main');

src/nav/navReducer.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NavigationAction } from 'react-navigation';
33

44
import type { NavigationState, Action } from '../types';
55
import AppNavigator from './AppNavigator';
6-
import { INITIAL_FETCH_COMPLETE, LOGIN_SUCCESS } from '../actionConstants';
6+
import { INITIAL_FETCH_COMPLETE } from '../actionConstants';
77

88
/**
99
* Get the initial state for the given route.
@@ -28,9 +28,6 @@ export const initialState = getStateForRoute('loading');
2828

2929
export default (state: NavigationState = initialState, action: Action): NavigationState => {
3030
switch (action.type) {
31-
case LOGIN_SUCCESS:
32-
return getStateForRoute('loading');
33-
3431
case INITIAL_FETCH_COMPLETE:
3532
return state.routes[0].routeName === 'main' ? state : getStateForRoute('main');
3633

src/start/AuthScreen.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { getCurrentRealm } from '../selectors';
2929
import RealmInfo from './RealmInfo';
3030
import { encodeParamsForUrl } from '../utils/url';
3131
import * as webAuth from './webAuth';
32-
import { loginSuccess, navigateToDev, navigateToPassword } from '../actions';
32+
import { loginSuccess, navigateToDev, navigateToPassword, resetToLoading } from '../actions';
3333
import IosCompliantAppleAuthButton from './IosCompliantAppleAuthButton';
3434
import openLink from '../utils/openLink';
3535

@@ -234,6 +234,7 @@ class AuthScreen extends PureComponent<Props> {
234234
const { dispatch, realm } = this.props;
235235
const auth = webAuth.authFromCallbackUrl(event.url, otp, realm);
236236
if (auth) {
237+
dispatch(resetToLoading());
237238
dispatch(loginSuccess(auth.realm, auth.email, auth.apiKey));
238239
}
239240
};

0 commit comments

Comments
 (0)