Skip to content

Commit

Permalink
topic edit modal [nfc]: Rebase branch over function-component-convers…
Browse files Browse the repository at this point in the history
…ion branch.
  • Loading branch information
Leslie Ngo authored and Leslie Ngo committed Sep 28, 2022
1 parent 5cc72d4 commit 943d68e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 56 deletions.
34 changes: 0 additions & 34 deletions src/search/MessageListWrapper.js

This file was deleted.

58 changes: 36 additions & 22 deletions src/search/SearchMessagesCard.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* @flow strict-local */

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

import type { Message, Narrow } from '../types';
import { createStyleSheet } from '../styles';
import LoadingIndicator from '../common/LoadingIndicator';
import SearchEmptyState from '../common/SearchEmptyState';
import MessageListWrapper from './MessageListWrapper';
import MessageList from '../webview/MessageList';
import { useTopicModalHandler } from '../boot/TopicModalProvider';

const styles = createStyleSheet({
results: {
Expand All @@ -22,29 +23,42 @@ type Props = $ReadOnly<{|
isFetching: boolean,
|}>;

export default class SearchMessagesCard extends PureComponent<Props> {
render(): Node {
const { isFetching, messages, narrow } = this.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} />;
}
}
export default function SearchMessagesCard(props: Props): Node {
const { narrow, isFetching, messages } = props;
const { startEditTopic } = useTopicModalHandler();

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}>
<MessageListWrapper messages={messages} narrow={narrow} />
</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}
startEditTopic={startEditTopic}
/>
</View>
);
}

0 comments on commit 943d68e

Please sign in to comment.