1
1
/* @flow strict-local */
2
2
3
- import React , { PureComponent } from 'react' ;
3
+ import React from 'react' ;
4
4
import type { Node } from 'react' ;
5
5
import { View } from 'react-native' ;
6
6
7
7
import type { Message , Narrow } from '../types' ;
8
8
import { createStyleSheet } from '../styles' ;
9
9
import LoadingIndicator from '../common/LoadingIndicator' ;
10
10
import SearchEmptyState from '../common/SearchEmptyState' ;
11
- import MessageListWrapper from './MessageListWrapper' ;
11
+ import MessageList from '../webview/MessageList' ;
12
+ import { useTopicModalHandler } from '../boot/TopicModalProvider' ;
12
13
13
14
const styles = createStyleSheet ( {
14
15
results : {
@@ -22,29 +23,42 @@ type Props = $ReadOnly<{|
22
23
isFetching : boolean ,
23
24
| } > ;
24
25
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 ( ) ;
35
29
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 } /> ;
38
35
}
36
+ }
39
37
40
- if ( messages . length === 0 ) {
41
- return < SearchEmptyState text = "No results" /> ;
42
- }
38
+ if ( ! messages ) {
39
+ return null ;
40
+ }
43
41
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" /> ;
49
44
}
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
+ ) ;
50
64
}
0 commit comments