Skip to content

Commit db8b0de

Browse files
committed
SharingScreen: Put share-to tabs behind useHaveServerDataGate
There are a few things wrong with the code before this change: - The share-to tabs need more than the guarantee of a logged-in user. They depend on server data like `realm.mandatoryTopics`. - Rendering `null` over the whole screen is likely to give an unpleasant white flicker. - The "server data gate" encapsulates some subtle logic around when we use `connect` vs. `useSelector`, and in principle we want that to apply here.
1 parent 6d62335 commit db8b0de

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/sharing/SharingScreen.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* @flow strict-local */
2-
import React from 'react';
2+
import React, { useEffect } from 'react';
33
import type { Node } from 'react';
44
import {
55
createMaterialTopTabNavigator,
@@ -21,6 +21,7 @@ import { getHasAuth } from '../selectors';
2121
import { navigateToAccountPicker } from '../nav/navActions';
2222
import ShareToStream from './ShareToStream';
2323
import ShareToPm from './ShareToPm';
24+
import { useHaveServerDataGate } from '../withHaveServerDataGate';
2425

2526
export type SharingNavigatorParamList = {|
2627
'share-to-stream': RouteParamsOf<typeof ShareToStream>,
@@ -53,19 +54,20 @@ export default function SharingScreen(props: Props): Node {
5354
const { params } = props.route;
5455
const hasAuth = useGlobalSelector(getHasAuth);
5556

56-
// If there is no active logged-in account, abandon the sharing attempt,
57-
// and present the account picker screen to the user.
58-
if (!hasAuth) {
59-
NavigationService.dispatch(navigateToAccountPicker());
60-
return null;
61-
}
57+
useEffect(() => {
58+
if (!hasAuth) {
59+
// If there is no active logged-in account, abandon the sharing attempt,
60+
// and present the account picker screen to the user.
61+
NavigationService.dispatch(navigateToAccountPicker());
62+
}
63+
}, [hasAuth]);
6264

6365
return (
6466
<Screen canGoBack={false} title="Share on Zulip" shouldShowLoadingBanner={false}>
6567
<Tab.Navigator {...materialTopTabNavigatorConfig()} swipeEnabled>
6668
<Tab.Screen
6769
name="share-to-stream"
68-
component={ShareToStream}
70+
component={useHaveServerDataGate(ShareToStream)}
6971
initialParams={params}
7072
options={{
7173
tabBarLabel: ({ color }) => (
@@ -75,7 +77,7 @@ export default function SharingScreen(props: Props): Node {
7577
/>
7678
<Tab.Screen
7779
name="share-to-pm"
78-
component={ShareToPm}
80+
component={useHaveServerDataGate(ShareToPm)}
7981
initialParams={params}
8082
options={{
8183
tabBarLabel: ({ color }) => (

0 commit comments

Comments
 (0)