Skip to content

Commit

Permalink
topic edit modal [nfc]: Convert SearchMessagesCard to function component
Browse files Browse the repository at this point in the history
to allow calling TopicModalProvider Context hook within.
  • Loading branch information
Leslie Ngo authored and Leslie Ngo committed Oct 10, 2022
1 parent fd2c743 commit cf5e387
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions src/search/SearchMessagesCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow strict-local */

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

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

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

if (isFetching) {
// Display loading indicator only if there are no messages to
// display from a previous search.
if (!messages || messages.length === 0) {
return <LoadingIndicator size={40} />;
}
}

if (!messages) {
return null;
if (isFetching) {
// Display loading indicator only if there are no messages to
// display from a previous search.
if (!messages || messages.length === 0) {
return <LoadingIndicator size={40} />;
}
}

if (messages.length === 0) {
return <SearchEmptyState text="No results" />;
}
if (!messages) {
return null;
}

return (
<View style={styles.results}>
<MessageList
initialScrollMessageId={
// This access is OK only because of the `.length === 0` check
// above.
messages[messages.length - 1].id
}
messages={messages}
narrow={this.props.narrow}
showMessagePlaceholders={false}
// TODO: handle editing a message from the search results,
// or make this prop optional
startEditMessage={() => undefined}
/>
</View>
);
if (messages.length === 0) {
return <SearchEmptyState text="No results" />;
}

return (
<View style={styles.results}>
<MessageList
initialScrollMessageId={
// This access is OK only because of the `.length === 0` check
// above.
messages[messages.length - 1].id
}
messages={messages}
narrow={narrow}
showMessagePlaceholders={false}
// TODO: handle editing a message from the search results,
// or make this prop optional
startEditMessage={() => undefined}
/>
</View>
);
}

0 comments on commit cf5e387

Please sign in to comment.