11/* @flow strict-local */
22
3- import React , { PureComponent } from 'react' ;
3+ import React from 'react' ;
44import type { Node } from 'react' ;
55import { View } from 'react-native' ;
66
77import type { Message , Narrow } from '../types' ;
88import { createStyleSheet } from '../styles' ;
99import LoadingIndicator from '../common/LoadingIndicator' ;
1010import SearchEmptyState from '../common/SearchEmptyState' ;
11- import MessageListWrapper from './MessageListWrapper' ;
11+ import MessageList from '../webview/MessageList' ;
12+ import { useTopicModalHandler } from '../boot/TopicModalProvider' ;
1213
1314const styles = createStyleSheet ( {
1415 results : {
@@ -22,29 +23,42 @@ type Props = $ReadOnly<{|
2223 isFetching : boolean ,
2324| } > ;
2425
25- export default class SearchMessagesCard extends PureComponent < Props > {
26- render ( ) : Node {
27- const { isFetching, messages, narrow } = this . props ;
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 } /> ;
33- }
34- }
26+ export default function SearchMessagesCard ( props : Props ) : Node {
27+ const { narrow, isFetching, messages } = props ;
28+ const { startEditTopic } = useTopicModalHandler ( ) ;
3529
36- if ( ! messages ) {
37- return null ;
30+ if ( isFetching ) {
31+ // Display loading indicator only if there are no messages to
32+ // display from a previous search.
33+ if ( ! messages || messages . length === 0 ) {
34+ return < LoadingIndicator size = { 40 } /> ;
3835 }
36+ }
3937
40- if ( messages . length === 0 ) {
41- return < SearchEmptyState text = "No results" /> ;
42- }
38+ if ( ! messages ) {
39+ return null ;
40+ }
4341
44- return (
45- < View style = { styles . results } >
46- < MessageListWrapper messages = { messages } narrow = { narrow } />
47- </ View >
48- ) ;
42+ if ( messages . length === 0 ) {
43+ return < SearchEmptyState text = "No results" /> ;
4944 }
45+
46+ return (
47+ < View style = { styles . results } >
48+ < MessageList
49+ initialScrollMessageId = {
50+ // This access is OK only because of the `.length === 0` check
51+ // above.
52+ messages [ messages . length - 1 ] . id
53+ }
54+ messages = { messages }
55+ narrow = { narrow }
56+ showMessagePlaceholders = { false }
57+ // TODO: handle editing a message from the search results,
58+ // or make this prop optional
59+ startEditMessage = { ( ) => undefined }
60+ startEditTopic = { startEditTopic }
61+ />
62+ </ View >
63+ ) ;
5064}
0 commit comments