Skip to content

Commit 531e268

Browse files
Leslie NgoLeslie Ngo
Leslie Ngo
authored and
Leslie Ngo
committed
topic edit modal [nfc]: Convert SearchMessagesCard to function component
to allow calling TopicModalProvider Context hook within.
1 parent b7170cf commit 531e268

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

src/search/SearchMessagesCard.js

+32-34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow strict-local */
22

3-
import React, { PureComponent } from 'react';
3+
import React from 'react';
44
import type { Node } from 'react';
55
import { View } from 'react-native';
66

@@ -22,42 +22,40 @@ type Props = $ReadOnly<{|
2222
isFetching: boolean,
2323
|}>;
2424

25-
export default class SearchMessagesCard extends PureComponent<Props> {
26-
render(): Node {
27-
const { isFetching, messages } = this.props;
25+
export default function SearchMessagesCard(props: Props): Node {
26+
const { narrow, isFetching, messages } = props;
2827

29-
if (isFetching) {
30-
// Display loading indicator only if there are no messages to
31-
// display from a previous search.
32-
if (!messages || messages.length === 0) {
33-
return <LoadingIndicator size={40} />;
34-
}
35-
}
36-
37-
if (!messages) {
38-
return null;
28+
if (isFetching) {
29+
// Display loading indicator only if there are no messages to
30+
// display from a previous search.
31+
if (!messages || messages.length === 0) {
32+
return <LoadingIndicator size={40} />;
3933
}
34+
}
4035

41-
if (messages.length === 0) {
42-
return <SearchEmptyState text="No results" />;
43-
}
36+
if (!messages) {
37+
return null;
38+
}
4439

45-
return (
46-
<View style={styles.results}>
47-
<MessageList
48-
initialScrollMessageId={
49-
// This access is OK only because of the `.length === 0` check
50-
// above.
51-
messages[messages.length - 1].id
52-
}
53-
messages={messages}
54-
narrow={this.props.narrow}
55-
showMessagePlaceholders={false}
56-
// TODO: handle editing a message from the search results,
57-
// or make this prop optional
58-
startEditMessage={() => undefined}
59-
/>
60-
</View>
61-
);
40+
if (messages.length === 0) {
41+
return <SearchEmptyState text="No results" />;
6242
}
43+
44+
return (
45+
<View style={styles.results}>
46+
<MessageList
47+
initialScrollMessageId={
48+
// This access is OK only because of the `.length === 0` check
49+
// above.
50+
messages[messages.length - 1].id
51+
}
52+
messages={messages}
53+
narrow={narrow}
54+
showMessagePlaceholders={false}
55+
// TODO: handle editing a message from the search results,
56+
// or make this prop optional
57+
startEditMessage={() => undefined}
58+
/>
59+
</View>
60+
);
6361
}

0 commit comments

Comments
 (0)