Skip to content

Commit 459dec1

Browse files
gnpricechrisbobbe
authored andcommitted
account [nfc]: Specialize getAccountStatuses as a view-model
This selector has only this one call site; it doesn't seem that we actually need it more generally. Move it so that it doesn't accidentally acquire additional call sites unnecessarily, so that we're free to revise it as needed to include other data this part of the UI needs.
1 parent 4dca971 commit 459dec1

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

src/account/AccountItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ZulipTextIntl from '../common/ZulipTextIntl';
1010
import { IconDone, IconTrash } from '../common/Icons';
1111
import { useGlobalSelector } from '../react-redux';
1212
import { getIsActiveAccount } from './accountsSelectors';
13-
import type { AccountStatus } from './accountsSelectors';
13+
import type { AccountStatus } from './AccountPickScreen';
1414

1515
const styles = createStyleSheet({
1616
wrapper: {

src/account/AccountList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { View, FlatList } from 'react-native';
55

66
import ViewPlaceholder from '../common/ViewPlaceholder';
77
import AccountItem from './AccountItem';
8-
import type { AccountStatus } from './accountsSelectors';
8+
import type { AccountStatus } from './AccountPickScreen';
99

1010
type Props = $ReadOnly<{|
1111
accountStatuses: $ReadOnlyArray<AccountStatus>,

src/account/AccountPickScreen.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import React, { useContext, useCallback } from 'react';
44
import type { Node } from 'react';
55
import invariant from 'invariant';
66

7+
import { createSelector } from 'reselect';
78
import { fetchServerSettings } from '../message/fetchActions';
89
import { TranslationContext } from '../boot/TranslationProvider';
910
import type { RouteProp } from '../react-navigation';
1011
import type { AppNavigationProp } from '../nav/AppNavigator';
1112
import { useGlobalSelector, useGlobalDispatch } from '../react-redux';
12-
import { getAccountStatuses, getAccountsByIdentity, getGlobalSettings } from '../selectors';
13+
import { getAccountsByIdentity, getGlobalSettings } from '../selectors';
1314
import Centerer from '../common/Centerer';
1415
import ZulipButton from '../common/ZulipButton';
1516
import Logo from '../common/Logo';
@@ -19,6 +20,23 @@ import AccountList from './AccountList';
1920
import { accountSwitch, removeAccount } from '../actions';
2021
import { showConfirmationDialog, showErrorAlert } from '../utils/info';
2122
import { tryStopNotifications } from '../notification/notifTokens';
23+
import type { Identity } from '../types';
24+
import type { GlobalSelector } from '../reduxTypes';
25+
import { getAccounts } from '../directSelectors';
26+
27+
/** The data needed for each item in the list-of-accounts UI. */
28+
export type AccountStatus = {| ...Identity, isLoggedIn: boolean |};
29+
30+
/**
31+
* The data needed for the list of accounts in this UI.
32+
*
33+
* This serves as a view-model for the use of this component.
34+
*/
35+
const getAccountStatuses: GlobalSelector<$ReadOnlyArray<AccountStatus>> = createSelector(
36+
getAccounts,
37+
accounts =>
38+
accounts.map(({ realm, email, apiKey }) => ({ realm, email, isLoggedIn: apiKey !== '' })),
39+
);
2240

2341
type Props = $ReadOnly<{|
2442
navigation: AppNavigationProp<'account-pick'>,

src/account/accountsSelectors.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@ import { getAccounts } from '../directSelectors';
1616
import { identityOfAccount, keyOfIdentity, identityOfAuth, authOfAccount } from './accountMisc';
1717
import { ZulipVersion } from '../utils/zulipVersion';
1818

19-
/** See `getAccountStatuses`. */
20-
export type AccountStatus = {| ...Identity, isLoggedIn: boolean |};
21-
22-
/**
23-
* The list of known accounts, with a boolean for logged-in vs. not.
24-
*
25-
* This should be used in preference to `getAccounts` where we don't
26-
* actually need the API keys, but just need to know whether we have them.
27-
*/
28-
export const getAccountStatuses: GlobalSelector<$ReadOnlyArray<AccountStatus>> = createSelector(
29-
getAccounts,
30-
accounts =>
31-
accounts.map(({ realm, email, apiKey }) => ({ realm, email, isLoggedIn: apiKey !== '' })),
32-
);
33-
3419
/** The list of known accounts, reduced to `Identity`. */
3520
export const getIdentities: GlobalSelector<$ReadOnlyArray<Identity>> = createSelector(
3621
getAccounts,

0 commit comments

Comments
 (0)