Skip to content

Commit

Permalink
flow: Annotate some more exported React components.
Browse files Browse the repository at this point in the history
This is easier to do now that we've converted these to function
components in this series.

This will help move us along toward Flow's new "Types-First" mode;
switching entirely is zulip#4907.

Prefer the `Node` type exported from React over `React$Node`.
They're equivalent, but Greg prefers `Node` as it seems cleaner; see
  https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Flow.20types-first/near/1239060.
  • Loading branch information
chrisbobbe committed Aug 13, 2021
1 parent 18f31ba commit a741086
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/account-info/AccountDetails.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import type { UserOrBot } from '../types';
Expand Down Expand Up @@ -33,7 +34,7 @@ type Props = $ReadOnly<{|
user: UserOrBot,
|}>;

export default function AccountDetails(props: Props) {
export default function AccountDetails(props: Props): Node {
const { user } = props;

const ownUser = useSelector(getOwnUser);
Expand Down
3 changes: 2 additions & 1 deletion src/account-info/AccountDetailsScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useCallback } from 'react';
import type { Node } from 'react';

import type { RouteProp } from '../react-navigation';
import type { AppNavigationProp } from '../nav/AppNavigator';
Expand Down Expand Up @@ -30,7 +31,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'account-details', {| userId: UserId |}>,
|}>;

export default function AccountDetailsScreen(props: Props) {
export default function AccountDetailsScreen(props: Props): Node {
const dispatch = useDispatch();
const user = useSelector(state => getUserForId(state, props.route.params.userId));
const isActive = useSelector(state => getUserIsActive(state, props.route.params.userId));
Expand Down
3 changes: 2 additions & 1 deletion src/common/ZulipStatusBar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow strict-local */

import React from 'react';
import type { Node } from 'react';
import { Platform, StatusBar } from 'react-native';
// $FlowFixMe[untyped-import]
import Color from 'color';
Expand Down Expand Up @@ -42,7 +43,7 @@ type Props = $ReadOnly<{|
* top inset grows to accommodate a visible status bar, and shrinks to
* give more room to the app's content when the status bar is hidden.
*/
export default function ZulipStatusBar(props: Props) {
export default function ZulipStatusBar(props: Props): Node {
const { hidden = false } = props;
const theme = useSelector(state => getSettings(state).theme);
const orientation = useSelector(state => getSession(state).orientation);
Expand Down
3 changes: 2 additions & 1 deletion src/emoji/Emoji.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { Image } from 'react-native';
import { createIconSet } from 'react-native-vector-icons';

Expand All @@ -23,7 +24,7 @@ const componentStyles = createStyleSheet({
image: { width: 20, height: 20 },
});

export default function Emoji(props: Props) {
export default function Emoji(props: Props): Node {
const { code } = props;
const imageEmoji = useSelector(state =>
props.type === 'image' ? getAllImageEmojiByCode(state)[props.code] : undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/emoji/EmojiPickerScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow strict-local */

import React, { useState, useCallback } from 'react';
import type { Node } from 'react';
import { FlatList } from 'react-native';

import type { RouteProp } from '../react-navigation';
Expand All @@ -24,7 +25,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'emoji-picker', {| messageId: number |}>,
|}>;

export default function EmojiPickerScreen(props: Props) {
export default function EmojiPickerScreen(props: Props): Node {
const { route } = props;
const { messageId } = route.params;

Expand Down
3 changes: 2 additions & 1 deletion src/message/MentionedUserNotSubscribed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow strict-local */

import React, { useCallback } from 'react';
import type { Node } from 'react';
import { View, TouchableOpacity } from 'react-native';

import type { Stream, UserOrBot, Subscription } from '../types';
Expand Down Expand Up @@ -49,7 +50,7 @@ const styles = createStyleSheet({
},
});

export default function MentionedUserNotSubscribed(props: Props) {
export default function MentionedUserNotSubscribed(props: Props): Node {
const { user, stream, onDismiss } = props;
const auth = useSelector(getAuth);

Expand Down
3 changes: 2 additions & 1 deletion src/message/NotSubscribed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow strict-local */

import React, { useCallback } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import type { Stream, Narrow } from '../types';
Expand All @@ -14,7 +15,7 @@ type Props = $ReadOnly<{|
narrow: Narrow,
|}>;

export default function NotSubscribed(props: Props) {
export default function NotSubscribed(props: Props): Node {
const auth = useSelector(getAuth);
const stream: $ReadOnly<{ ...Stream, ... }> = useSelector(state =>
getStreamInNarrow(state, props.narrow),
Expand Down
3 changes: 2 additions & 1 deletion src/nav/ZulipNavigationContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useContext, useEffect } from 'react';
import type { Node } from 'react';
import { NavigationContainer, DefaultTheme, DarkTheme } from '@react-navigation/native';

import { useSelector } from '../react-redux';
Expand All @@ -20,7 +21,7 @@ type Props = $ReadOnly<{||}>;
* - Call `createAppContainer` with the appropriate `initialRouteName`
* and `initialRouteParams` which we get from data in Redux.
*/
export default function ZulipAppContainer(props: Props) {
export default function ZulipAppContainer(props: Props): Node {
const themeName = useSelector(state => getSettings(state).theme);

useEffect(
Expand Down
3 changes: 2 additions & 1 deletion src/streams/EditStreamScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useCallback } from 'react';
import type { Node } from 'react';

import type { RouteProp } from '../react-navigation';
import type { AppNavigationProp } from '../nav/AppNavigator';
Expand All @@ -15,7 +16,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'edit-stream', {| streamId: number |}>,
|}>;

export default function EditStreamScreen(props: Props) {
export default function EditStreamScreen(props: Props): Node {
const dispatch = useDispatch();
const stream = useSelector(state => getStreamForId(state, props.route.params.streamId));

Expand Down
3 changes: 2 additions & 1 deletion src/streams/InviteUsersScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useState, useCallback } from 'react';
import type { Node } from 'react';

import type { RouteProp } from '../react-navigation';
import type { AppNavigationProp } from '../nav/AppNavigator';
Expand All @@ -17,7 +18,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'invite-users', {| streamId: number |}>,
|}>;

export default function InviteUsersScreen(props: Props) {
export default function InviteUsersScreen(props: Props): Node {
const auth = useSelector(getAuth);
const stream = useSelector(state => getStreamForId(state, props.route.params.streamId));

Expand Down
3 changes: 2 additions & 1 deletion src/streams/StreamSettingsScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useCallback } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import type { RouteProp } from '../react-navigation';
Expand All @@ -26,7 +27,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'stream-settings', {| streamId: number |}>,
|}>;

export default function StreamSettingsScreen(props: Props) {
export default function StreamSettingsScreen(props: Props): Node {
const dispatch = useDispatch();

const auth = useSelector(getAuth);
Expand Down
3 changes: 2 additions & 1 deletion src/streams/SubscriptionsCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow strict-local */

import React, { useCallback } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import type { RouteProp } from '../react-navigation';
Expand All @@ -26,7 +27,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'subscribed', void>,
|}>;

export default function SubscriptionsCard(props: Props) {
export default function SubscriptionsCard(props: Props): Node {
const dispatch = useDispatch();
const subscriptions = useSelector(getSubscribedStreams);
const unreadByStream = useSelector(getUnreadByStream);
Expand Down
3 changes: 2 additions & 1 deletion src/subscriptions/StreamListCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow strict-local */

import React, { useCallback } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';

import type { RouteProp } from '../react-navigation';
Expand Down Expand Up @@ -30,7 +31,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'allStreams', void>,
|}>;

export default function StreamListCard(props: Props) {
export default function StreamListCard(props: Props): Node {
const dispatch = useDispatch();
const auth = useSelector(getAuth);
const canCreateStreams = useSelector(getCanCreateStreams);
Expand Down
3 changes: 2 additions & 1 deletion src/title/ActivityText.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow strict-local */

import React from 'react';
import type { Node } from 'react';
import type { TextStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';

import type { UserOrBot } from '../types';
Expand All @@ -14,7 +15,7 @@ type Props = $ReadOnly<{|
user: UserOrBot,
|}>;

export default function ActivityText(props: Props) {
export default function ActivityText(props: Props): Node {
const { style } = props;
const presence = useSelector(state => getPresence(state)[props.user.email]);
const userStatus = useSelector(state => getUserStatus(state)[props.user.user_id]);
Expand Down
3 changes: 2 additions & 1 deletion src/topics/TopicListScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow strict-local */

import React, { useState, useCallback, useEffect } from 'react';
import type { Node } from 'react';

import type { RouteProp } from '../react-navigation';
import type { AppNavigationProp } from '../nav/AppNavigator';
Expand All @@ -17,7 +18,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'topic-list', {| streamId: number |}>,
|}>;

export default function TopicListScreen(props: Props) {
export default function TopicListScreen(props: Props): Node {
const dispatch = useDispatch();
const stream = useSelector(state => getStreamForId(state, props.route.params.streamId));
const topics = useSelector(state => getTopicsForStream(state, props.route.params.streamId));
Expand Down
3 changes: 2 additions & 1 deletion src/user-status/UserStatusScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import React, { useState, useContext, useCallback } from 'react';
import type { Node } from 'react';
import { FlatList, View } from 'react-native';
import { TranslationContext } from '../boot/TranslationProvider';
import { createStyleSheet } from '../styles';
Expand Down Expand Up @@ -33,7 +34,7 @@ type Props = $ReadOnly<{|
route: RouteProp<'user-status', void>,
|}>;

export default function UserStatusScreen(props: Props) {
export default function UserStatusScreen(props: Props): Node {
const dispatch = useDispatch();
const userStatusText = useSelector(getSelfUserStatusText);

Expand Down

0 comments on commit a741086

Please sign in to comment.