Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start type checking MessageList's props. #4465

Merged
merged 16 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
17748d8
MessageList: Stop accepting `typingUsers` prop from parent.
chrisbobbe Jun 16, 2021
a74cb23
MessageList: Stop accepting `fetching` prop from parent.
chrisbobbe Jun 16, 2021
134dc95
ChatScreen [nfc]: Pass messages and initialScrollMessageId to Message…
chrisbobbe Feb 3, 2021
9f9dc2d
MessageList [nfc]: Require `messages` and `initialScrollMessageId`.
chrisbobbe Feb 3, 2021
6ed1918
messagesSelectors: Add `getHtmlPieceDescriptorsForMessages`.
chrisbobbe Feb 8, 2021
d7d6d35
MessageList [nfc]: Stop using `getHtmlPieceDescriptorsForShownMessages`.
chrisbobbe Feb 8, 2021
66d16ab
SearchMessagesCard: Use memoized function to get HTML piece descriptors.
chrisbobbe Feb 8, 2021
f803542
SearchMessagesCard [nfc]: Inline `htmlPieceDescriptors`.
chrisbobbe Feb 8, 2021
13c91b6
MessageList [nfc]: Express a conditional a different way.
chrisbobbe Feb 8, 2021
f7519f2
SearchMessagesCard [nfc]: Don't pass htmlPieceDescriptorsForShownMess…
chrisbobbe Jun 16, 2021
c655202
MessageList [nfc]: Remove outer prop htmlPieceDescriptorsForShownMess…
chrisbobbe Jun 16, 2021
923f633
MessageList types: Copy `startEditMessage` to `OuterProps`, where it …
chrisbobbe Feb 3, 2021
932173a
action sheet: Add type wrapper for `connectActionSheet`.
chrisbobbe Feb 3, 2021
767fbf9
MessageList: Use our type-wrapper for `connectActionSheet`.
chrisbobbe Feb 3, 2021
ac97c91
MessageList: Fix type-checking of props.
chrisbobbe Feb 3, 2021
21fd83a
MessageList [nfc]: Spread `OuterProps` in `Props`, to remove repeated…
chrisbobbe Jun 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MessageList: Fix type-checking of props.
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 Jun 16, 2021
commit ac97c91cb8de468112ae01077786965d572b1866
3 changes: 3 additions & 0 deletions src/search/SearchMessagesCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export default class SearchMessagesCard extends PureComponent<Props> {
messages={messages}
narrow={narrow}
showMessagePlaceholders={false}
// TODO: handle editing a message from the search results,
// or make this prop optional
startEditMessage={() => undefined}
/>
</View>
);
Expand Down
64 changes: 34 additions & 30 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 @@ -304,32 +304,36 @@ type OuterProps = {|
startEditMessage: (editMessage: EditMessage) => void,
gnprice marked this conversation as resolved.
Show resolved Hide resolved
|};

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),
mutedUsers: getMutedUsers(state),
ownUser: getOwnUser(state),
subscriptions: getSubscriptions(state),
theme: getSettings(state).theme,
twentyFourHourTime: getRealm(state).twentyFourHourTime,
};
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),
mutedUsers: getMutedUsers(state),
ownUser: getOwnUser(state),
subscriptions: getSubscriptions(state),
theme: getSettings(state).theme,
twentyFourHourTime: getRealm(state).twentyFourHourTime,
};

return {
backgroundData,
fetching: getFetchingForNarrow(state, props.narrow),
htmlPieceDescriptorsForShownMessages: getHtmlPieceDescriptorsForMessages(
props.messages,
props.narrow,
),
typingUsers: getCurrentTypingUsers(state, props.narrow),
};
})(connectActionSheet(withGetText(MessageList)));
return {
backgroundData,
fetching: getFetchingForNarrow(state, props.narrow),
htmlPieceDescriptorsForShownMessages: getHtmlPieceDescriptorsForMessages(
props.messages,
props.narrow,
),
typingUsers: getCurrentTypingUsers(state, props.narrow),
};
},
)(connectActionSheet(withGetText(MessageListInner)));

export default MessageList;