Skip to content

Commit 5a9ef21

Browse files
committed
AppNavigator [nfc]: Stop getting some values from the parent component.
Instead, have AppNavigator grab them itself, with react-redux.
1 parent 4eb5d32 commit 5a9ef21

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/nav/AppNavigator.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import {
88
TransitionPresets,
99
} from '@react-navigation/stack';
1010

11+
import { useSelector } from '../react-redux';
12+
import { hasAuth as getHasAuth, getAccounts, getHaveServerData } from '../selectors';
1113
import getInitialRouteInfo from './getInitialRouteInfo';
1214
import type { GlobalParamList } from './globalTypes';
13-
import type { Account, Narrow, Message, SharedData } from '../types';
15+
import type { Narrow, Message, SharedData } from '../types';
1416
import type { ApiResponseServerSettings } from '../api/settings/getServerSettings';
1517
import AccountPickScreen from '../account/AccountPickScreen';
1618
import RealmScreen from '../start/RealmScreen';
@@ -88,14 +90,13 @@ export type AppNavigationRouteProp<
8890

8991
const Stack = createStackNavigator<GlobalParamList, AppNavigatorParamList, AppNavigationProp<>>();
9092

91-
type Props = $ReadOnly<{|
92-
hasAuth: boolean,
93-
accounts: Account[],
94-
haveServerData: boolean,
95-
|}>;
93+
type Props = $ReadOnly<{||}>;
9694

9795
export default function AppNavigator(props: Props) {
98-
const { hasAuth, accounts, haveServerData } = props;
96+
const hasAuth = useSelector(getHasAuth);
97+
const accounts = useSelector(getAccounts);
98+
const haveServerData = useSelector(getHaveServerData);
99+
99100
const { initialRouteName, initialRouteParams } = getInitialRouteInfo({
100101
hasAuth,
101102
accounts,

src/nav/ZulipNavigationContainer.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ import { connect } from '../react-redux';
66
import type { ThemeData } from '../styles';
77
import { ThemeContext } from '../styles';
88
import * as NavigationService from './NavigationService';
9-
import type { Dispatch, Account, ThemeName } from '../types';
10-
import { hasAuth as getHasAuth, getAccounts, getHaveServerData, getSettings } from '../selectors';
9+
import type { Dispatch, ThemeName } from '../types';
10+
import { getSettings } from '../selectors';
1111
import AppNavigator from './AppNavigator';
1212

1313
type SelectorProps = $ReadOnly<{|
1414
theme: ThemeName,
15-
hasAuth: boolean,
16-
accounts: Account[],
17-
haveServerData: boolean,
1815
|}>;
1916

2017
type Props = $ReadOnly<{|
@@ -41,7 +38,7 @@ class ZulipAppContainer extends PureComponent<Props> {
4138
}
4239

4340
render() {
44-
const { theme: themeName, hasAuth, accounts, haveServerData } = this.props;
41+
const { theme: themeName } = this.props;
4542

4643
const BaseTheme = themeName === 'night' ? DarkTheme : DefaultTheme;
4744

@@ -65,15 +62,12 @@ class ZulipAppContainer extends PureComponent<Props> {
6562
}}
6663
theme={theme}
6764
>
68-
<AppNavigator {...{ hasAuth, accounts, haveServerData }} />
65+
<AppNavigator />
6966
</NavigationContainer>
7067
);
7168
}
7269
}
7370

7471
export default connect(state => ({
7572
theme: getSettings(state).theme,
76-
hasAuth: getHasAuth(state),
77-
accounts: getAccounts(state),
78-
haveServerData: getHaveServerData(state),
7973
}))(ZulipAppContainer);

0 commit comments

Comments
 (0)