Skip to content

Commit

Permalink
MessageList: Fix type-checking of props.
Browse files Browse the repository at this point in the history
This is the problem we've run into a few times [1] [2] where adding
`() => <C />;` to the file magically causes C's callers even
*outside* the file to start getting their props type-checked, where
they weren't before.

Instead of doing that, annotate the export with
`ComponentType<OuterProps>`, which Greg noticed also worked [3],
since we happen to have `OuterProps` lying around anyway.

[1] fcde700
[2] https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Flow.20and.20.60connect.60/near/1098203
[3] https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Flow.20and.20.60connect.60/near/1098230
  • Loading branch information
chrisbobbe committed Apr 16, 2021
1 parent 3d1dd5a commit 31feae8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
3 changes: 3 additions & 0 deletions src/search/SearchMessagesCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export default class SearchMessagesCard extends PureComponent<Props> {
disableFetching
showMessagePlaceholders={false}
suppressTypingIndicator
// TODO: handle editing a message from the search results,
// or don't let callers pass this.
startEditMessage={() => undefined}
/>
</View>
);
Expand Down
68 changes: 36 additions & 32 deletions src/webview/MessageList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @flow strict-local */
import React, { Component } from 'react';
import React, { Component, type ComponentType } from 'react';
import { Platform, NativeModules } from 'react-native';
import { WebView } from 'react-native-webview';
import type { WebViewNavigation } from 'react-native-webview';
Expand Down Expand Up @@ -142,7 +142,7 @@ const assetsUrl =
*/
const webviewAssetsUrl = new URL('webview/', assetsUrl);

class MessageList extends Component<Props> {
class MessageListInner extends Component<Props> {
static contextType = ThemeContext;
context: ThemeData;

Expand Down Expand Up @@ -335,33 +335,37 @@ type OuterProps = {|
suppressTypingIndicator?: true,
|};

export default connect<SelectorProps, _, _>((state, props: OuterProps) => {
// TODO Ideally this ought to be a caching selector that doesn't change
// when the inputs don't. Doesn't matter in a practical way here, because
// we have a `shouldComponentUpdate` that doesn't look at this prop... but
// it'd be better to set an example of the right general pattern.
const backgroundData: BackgroundData = {
alertWords: state.alertWords,
allImageEmojiById: getAllImageEmojiById(state),
auth: getAuth(state),
debug: getDebug(state),
flags: getFlags(state),
mute: getMute(state),
ownUser: getOwnUser(state),
subscriptions: getSubscriptions(state),
theme: getSettings(state).theme,
twentyFourHourTime: getRealm(state).twentyFourHourTime,
};

return {
backgroundData,
fetching: props.disableFetching
? { older: false, newer: false }
: getFetchingForNarrow(state, props.narrow),
htmlPieceDescriptorsForShownMessages: getHtmlPieceDescriptorsForMessages(
props.messages,
props.narrow,
),
typingUsers: props.suppressTypingIndicator ? [] : getCurrentTypingUsers(state, props.narrow),
};
})(connectActionSheet(withGetText(MessageList)));
const MessageList: ComponentType<OuterProps> = connect<SelectorProps, _, _>(
(state, props: OuterProps) => {
// TODO Ideally this ought to be a caching selector that doesn't change
// when the inputs don't. Doesn't matter in a practical way here, because
// we have a `shouldComponentUpdate` that doesn't look at this prop... but
// it'd be better to set an example of the right general pattern.
const backgroundData: BackgroundData = {
alertWords: state.alertWords,
allImageEmojiById: getAllImageEmojiById(state),
auth: getAuth(state),
debug: getDebug(state),
flags: getFlags(state),
mute: getMute(state),
ownUser: getOwnUser(state),
subscriptions: getSubscriptions(state),
theme: getSettings(state).theme,
twentyFourHourTime: getRealm(state).twentyFourHourTime,
};

return {
backgroundData,
fetching: props.disableFetching
? { older: false, newer: false }
: getFetchingForNarrow(state, props.narrow),
htmlPieceDescriptorsForShownMessages: getHtmlPieceDescriptorsForMessages(
props.messages,
props.narrow,
),
typingUsers: props.suppressTypingIndicator ? [] : getCurrentTypingUsers(state, props.narrow),
};
},
)(connectActionSheet(withGetText(MessageListInner)));

export default MessageList;

0 comments on commit 31feae8

Please sign in to comment.