Skip to content

Commit 2ba7a38

Browse files
committed
navReducer: Transplant away INITIAL_FETCH_COMPLETE 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 `INITIAL_FETCH_COMPLETE` case into instructions to navigate to the main-tabs screen, if not already there. Make the action creator into a thunk action creator and dispatch the navigation action from there, to reduce repetition.
1 parent cf1b65a commit 2ba7a38

File tree

3 files changed

+13
-36
lines changed

3 files changed

+13
-36
lines changed

src/message/fetchActions.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
} from '../types';
1111
import type { InitialData } from '../api/initialDataTypes';
1212
import * as api from '../api';
13+
import { resetToMainTabs } from '../actions';
1314
import { isClientError } from '../api/apiErrors';
1415
import {
1516
getAuth,
@@ -18,6 +19,7 @@ import {
1819
getLastMessageId,
1920
getCaughtUpForNarrow,
2021
getFetchingForNarrow,
22+
getNavigationRoutes,
2123
} from '../selectors';
2224
import config from '../config';
2325
import {
@@ -156,10 +158,20 @@ const initialFetchStart = (): Action => ({
156158
type: INITIAL_FETCH_START,
157159
});
158160

159-
const initialFetchComplete = (): Action => ({
161+
const initialFetchCompletePlain = (): Action => ({
160162
type: INITIAL_FETCH_COMPLETE,
161163
});
162164

165+
export const initialFetchComplete = () => async (dispatch: Dispatch, getState: GetState) => {
166+
if (getNavigationRoutes()[0] !== 'main') {
167+
// If we're anywhere in the normal UI of the app, then remain
168+
// where we are. Only reset the nav state if we're elsewhere,
169+
// and in that case, go to the main screen.
170+
dispatch(resetToMainTabs());
171+
}
172+
dispatch(initialFetchCompletePlain());
173+
};
174+
163175
/** Private; exported only for tests. */
164176
export const isFetchNeededAtAnchor = (
165177
state: GlobalState,

src/nav/__tests__/navReducer-test.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/nav/navReducer.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
import type { NavigationAction } from 'react-navigation';
33

44
import type { NavigationState, Action } from '../types';
5-
import { getNavigationRoutes } from './navSelectors';
65
import AppNavigator from './AppNavigator';
7-
import { INITIAL_FETCH_COMPLETE } from '../actionConstants';
86

97
/**
108
* Get the initial state for the given route.
@@ -29,12 +27,6 @@ export const initialState = getStateForRoute('loading');
2927

3028
export default (state: NavigationState = initialState, action: Action): NavigationState => {
3129
switch (action.type) {
32-
case INITIAL_FETCH_COMPLETE:
33-
// If we're anywhere in the normal UI of the app, then remain
34-
// where we are. Only reset the nav state if we're elsewhere,
35-
// and in that case, go to the main screen.
36-
return getNavigationRoutes()[0].routeName === 'main' ? state : getStateForRoute('main');
37-
3830
default: {
3931
// The `react-navigation` libdef says this only takes a NavigationAction,
4032
// but docs say pass arbitrary action. $FlowFixMe

0 commit comments

Comments
 (0)