Skip to content

Commit

Permalink
navReducer: Transplant away ACCOUNT_SWITCH logic.
Browse files Browse the repository at this point in the history
Soon, we'll dismantle `navReducer`, as its purpose is incompatible
with a design where we manage navigation state separately from our
Redux-stored data (zulip#3804).

So, convert the `navReducer`'s `ACCOUNT_SWITCH` case into
instructions to navigate to the loading screen.

Make the action creator into a thunk action creator and dispatch the
navigation action from there, to reduce repetition.
  • Loading branch information
chrisbobbe authored and gnprice committed Oct 22, 2020
1 parent e41a953 commit c3ffa52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/account/accountActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import {
LOGIN_SUCCESS,
LOGOUT,
} from '../actionConstants';
import { resetToAccountPicker } from '../nav/navActions';
import { resetToAccountPicker, resetToLoading } from '../nav/navActions';
import type { ZulipVersion } from '../utils/zulipVersion';

export const accountSwitch = (index: number): Action => ({
const accountSwitchPlain = (index: number): Action => ({
type: ACCOUNT_SWITCH,
index,
});

export const accountSwitch = (index: number) => (dispatch: Dispatch, getState: GetState) => {
dispatch(resetToLoading());
dispatch(accountSwitchPlain(index));
};

export const realmAdd = (
realm: URL,
zulipFeatureLevel: number,
Expand Down
3 changes: 1 addition & 2 deletions src/nav/navReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NavigationAction } from 'react-navigation';

import type { NavigationState, Action } from '../types';
import AppNavigator from './AppNavigator';
import { INITIAL_FETCH_COMPLETE, ACCOUNT_SWITCH, LOGIN_SUCCESS } from '../actionConstants';
import { INITIAL_FETCH_COMPLETE, LOGIN_SUCCESS } from '../actionConstants';

/**
* Get the initial state for the given route.
Expand All @@ -28,7 +28,6 @@ export const initialState = getStateForRoute('loading');

export default (state: NavigationState = initialState, action: Action): NavigationState => {
switch (action.type) {
case ACCOUNT_SWITCH:
case LOGIN_SUCCESS:
return getStateForRoute('loading');

Expand Down

0 comments on commit c3ffa52

Please sign in to comment.