Skip to content

Commit 4736d8f

Browse files
committed
account actions [nfc]: Make loginSuccess thunk action a GlobalThunkAction
Just as much as accountSwitch, this thunk action does touch the global `state.accounts`, by either adding a new account at the front of the array, or -- just like accountSwitch -- moving an existing account to the front. So, make it so callers treat it as a GlobalThunkAction, and have it act like one in its implementation.
1 parent dd20816 commit 4736d8f

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

src/account/accountActions.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow strict-local */
22
import * as NavigationService from '../nav/NavigationService';
3-
import type { PerAccountAction, AllAccountsAction, ThunkAction, GlobalThunkAction } from '../types';
3+
import type { PerAccountAction, AllAccountsAction, GlobalThunkAction } from '../types';
44
import {
55
ACCOUNT_SWITCH,
66
ACCOUNT_REMOVE,
@@ -57,15 +57,19 @@ const loginSuccessPlain = (realm: URL, email: string, apiKey: string): AllAccoun
5757
});
5858

5959
export const loginSuccess =
60-
(realm: URL, email: string, apiKey: string): ThunkAction<Promise<void>> =>
61-
async (dispatch, getState) => {
60+
(realm: URL, email: string, apiKey: string): GlobalThunkAction<Promise<void>> =>
61+
async (dispatch, getState, { activeAccountDispatch }) => {
6262
NavigationService.dispatch(resetToMainTabs());
6363
dispatch(loginSuccessPlain(realm, email, apiKey));
6464

65-
await dispatch(registerAndStartPolling());
65+
// Now dispatch some actions on the new, post-login active account.
66+
// Because we just dispatched `loginSuccessPlain`, that new account is
67+
// now the active account, so `activeAccountDispatch` will act on it.
68+
69+
await activeAccountDispatch(registerAndStartPolling());
6670

6771
// TODO(#3881): Lots of issues with outbox sending
68-
dispatch(sendOutbox());
72+
activeAccountDispatch(sendOutbox());
6973

70-
dispatch(initNotifications());
74+
activeAccountDispatch(initNotifications());
7175
};

src/start/AuthScreen.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
import type { RouteProp } from '../react-navigation';
1515
import type { AppNavigationProp } from '../nav/AppNavigator';
1616
import isAppOwnDomain from '../isAppOwnDomain';
17-
import type { Dispatch } from '../types';
17+
import type { GlobalDispatch } from '../types';
1818
import {
1919
IconApple,
2020
IconPrivate,
@@ -24,7 +24,7 @@ import {
2424
IconTerminal,
2525
} from '../common/Icons';
2626
import type { SpecificIconType } from '../common/Icons';
27-
import { connect } from '../react-redux';
27+
import { connectGlobal } from '../react-redux';
2828
import styles from '../styles';
2929
import Centerer from '../common/Centerer';
3030
import Screen from '../common/Screen';
@@ -191,7 +191,7 @@ type SelectorProps = $ReadOnly<{||}>;
191191
type Props = $ReadOnly<{|
192192
...OuterProps,
193193

194-
dispatch: Dispatch,
194+
dispatch: GlobalDispatch,
195195
...SelectorProps,
196196
|}>;
197197

@@ -376,6 +376,6 @@ class AuthScreenInner extends PureComponent<Props> {
376376
}
377377
}
378378

379-
const AuthScreen: ComponentType<OuterProps> = connect<{||}, _, _>()(AuthScreenInner);
379+
const AuthScreen: ComponentType<OuterProps> = connectGlobal<{||}, _, _>()(AuthScreenInner);
380380

381381
export default AuthScreen;

src/start/DevAuthScreen.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { ActivityIndicator, View, FlatList } from 'react-native';
66

77
import type { RouteProp } from '../react-navigation';
88
import type { AppNavigationProp } from '../nav/AppNavigator';
9-
import type { DevUser, Dispatch } from '../types';
9+
import type { DevUser, GlobalDispatch } from '../types';
1010
import styles, { createStyleSheet } from '../styles';
11-
import { connect } from '../react-redux';
11+
import { connectGlobal } from '../react-redux';
1212
import ErrorMsg from '../common/ErrorMsg';
1313
import ZulipTextIntl from '../common/ZulipTextIntl';
1414
import Screen from '../common/Screen';
@@ -42,7 +42,7 @@ type SelectorProps = $ReadOnly<{||}>;
4242
type Props = $ReadOnly<{|
4343
...OuterProps,
4444

45-
dispatch: Dispatch,
45+
dispatch: GlobalDispatch,
4646
...SelectorProps,
4747
|}>;
4848

@@ -141,6 +141,6 @@ class DevAuthScreenInner extends PureComponent<Props, State> {
141141
}
142142
}
143143

144-
const DevAuthScreen: ComponentType<OuterProps> = connect<{||}, _, _>()(DevAuthScreenInner);
144+
const DevAuthScreen: ComponentType<OuterProps> = connectGlobal<{||}, _, _>()(DevAuthScreenInner);
145145

146146
export default DevAuthScreen;

src/start/PasswordAuthScreen.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { View } from 'react-native';
55

66
import type { RouteProp } from '../react-navigation';
77
import type { AppNavigationProp } from '../nav/AppNavigator';
8-
import type { Dispatch } from '../types';
8+
import type { GlobalDispatch } from '../types';
99
import { createStyleSheet } from '../styles';
10-
import { connect } from '../react-redux';
10+
import { connectGlobal } from '../react-redux';
1111
import * as api from '../api';
1212
import ErrorMsg from '../common/ErrorMsg';
1313
import Input from '../common/Input';
@@ -42,7 +42,7 @@ type SelectorProps = $ReadOnly<{||}>;
4242
type Props = $ReadOnly<{|
4343
...OuterProps,
4444

45-
dispatch: Dispatch,
45+
dispatch: GlobalDispatch,
4646
...SelectorProps,
4747
|}>;
4848

@@ -153,7 +153,7 @@ class PasswordAuthScreenInner extends PureComponent<Props, State> {
153153
}
154154
}
155155

156-
const PasswordAuthScreen: ComponentType<OuterProps> = connect<{||}, _, _>()(
156+
const PasswordAuthScreen: ComponentType<OuterProps> = connectGlobal<{||}, _, _>()(
157157
PasswordAuthScreenInner,
158158
);
159159

0 commit comments

Comments
 (0)