@@ -73,114 +73,132 @@ export type MessageSearchListProps = {
7373 refreshList : ( ) => void ;
7474 showResultCount ?: boolean ;
7575} ;
76- export const MessageSearchList : React . FC < MessageSearchListProps > = ( {
77- EmptySearchIndicator,
78- loading,
79- loadMore,
80- messages,
81- refreshing,
82- refreshList,
83- showResultCount = false ,
84- } ) => {
85- const {
86- theme : {
87- colors : { black, border, grey, white_snow } ,
88- } ,
89- } = useTheme ( ) ;
90- const navigation = useNavigation ( ) ;
91-
92- if ( loading && ! refreshing && ( ! messages || messages . length === 0 ) ) {
93- return (
94- < View style = { styles . indicatorContainer } >
95- < Spinner />
96- </ View >
97- ) ;
98- }
99- if ( ! messages && ! refreshing ) return null ;
76+ export const MessageSearchList : React . FC < MessageSearchListProps > = React . forwardRef (
77+ (
78+ props ,
79+ scrollRef : React . Ref < FlatList <
80+ MessageResponse <
81+ LocalAttachmentType ,
82+ LocalChannelType ,
83+ LocalCommandType ,
84+ LocalMessageType ,
85+ LocalReactionType ,
86+ LocalUserType
87+ >
88+ > | null > ,
89+ ) => {
90+ const {
91+ EmptySearchIndicator,
92+ loading,
93+ loadMore,
94+ messages,
95+ refreshing,
96+ refreshList,
97+ showResultCount = false ,
98+ } = props ;
99+ const {
100+ theme : {
101+ colors : { black, border, grey, white_snow } ,
102+ } ,
103+ } = useTheme ( ) ;
104+ const navigation = useNavigation ( ) ;
100105
101- return (
102- < >
103- { messages && showResultCount && (
104- < View
105- style = { {
106- backgroundColor : white_snow ,
107- paddingHorizontal : 10 ,
108- paddingVertical : 2 ,
109- } }
110- >
111- < Text style = { { color : grey } } >
112- { `${ messages . length >= MESSAGE_SEARCH_LIMIT ? MESSAGE_SEARCH_LIMIT : messages . length } ${
113- messages . length >= MESSAGE_SEARCH_LIMIT ? '+ ' : ' '
114- } result${ messages . length === 1 ? '' : 's' } `}
115- </ Text >
106+ if ( loading && ! refreshing && ( ! messages || messages . length === 0 ) ) {
107+ return (
108+ < View style = { styles . indicatorContainer } >
109+ < Spinner />
116110 </ View >
117- ) }
118- < FlatList
119- contentContainerStyle = { styles . contentContainer }
120- // TODO: Remove the following filter once we have two way scroll functionality on threads.
121- data = { messages ? messages . filter ( ( { parent_id } ) => ! parent_id ) : [ ] }
122- keyboardDismissMode = 'on-drag'
123- ListEmptyComponent = { EmptySearchIndicator }
124- onEndReached = { loadMore }
125- onRefresh = { refreshList }
126- refreshing = { refreshing }
127- renderItem = { ( { item } ) => (
128- < TouchableOpacity
129- onPress = { ( ) => {
130- navigation . navigate ( 'ChannelScreen' , {
131- channelId : item . channel ?. id ,
132- messageId : item . id ,
133- } ) ;
111+ ) ;
112+ }
113+ if ( ! messages && ! refreshing ) return null ;
114+
115+ return (
116+ < >
117+ { messages && showResultCount && (
118+ < View
119+ style = { {
120+ backgroundColor : white_snow ,
121+ paddingHorizontal : 10 ,
122+ paddingVertical : 2 ,
134123 } }
135- style = { [ styles . itemContainer , { borderBottomColor : border } ] }
136- testID = 'channel-preview-button'
137124 >
138- < Avatar image = { item . user ?. image } name = { item . user ?. name } size = { 40 } />
139- < View style = { styles . flex } >
140- < View style = { styles . row } >
141- < Text numberOfLines = { 1 } style = { [ styles . titleContainer , { color : black } ] } >
142- < Text style = { styles . title } > { `${ item . user ?. name } ` } </ Text >
143- { ! ! item . channel ?. name && (
144- < Text style = { styles . detailsText } >
145- in
146- < Text style = { styles . title } > { ` ${ item . channel ?. name } ` } </ Text >
147- </ Text >
148- ) }
149- </ Text >
150- </ View >
151- < View style = { styles . row } >
152- < Text
153- numberOfLines = { 1 }
154- style = { [
155- styles . message ,
156- {
157- color : grey ,
158- } ,
159- ] }
160- >
161- { item . text }
162- </ Text >
163- < Text
164- style = { [
165- styles . date ,
166- {
167- color : grey ,
168- } ,
169- ] }
170- >
171- { dayjs ( item . created_at ) . calendar ( undefined , {
172- lastDay : 'DD/MM' , // The day before ( Yesterday at 2:30 AM )
173- lastWeek : 'DD/MM' , // Last week ( Last Monday at 2:30 AM )
174- sameDay : 'h:mm A' , // The same day ( Today at 2:30 AM )
175- sameElse : 'DD/MM/YYYY' , // Everything else ( 17/10/2011 )
176- } ) }
177- </ Text >
178- </ View >
179- </ View >
180- </ TouchableOpacity >
125+ < Text style = { { color : grey } } >
126+ { `${
127+ messages . length >= MESSAGE_SEARCH_LIMIT ? MESSAGE_SEARCH_LIMIT : messages . length
128+ } ${ messages . length >= MESSAGE_SEARCH_LIMIT ? '+ ' : ' ' } result${
129+ messages . length === 1 ? '' : 's'
130+ } `}
131+ </ Text >
132+ </ View >
181133 ) }
182- style = { styles . flex }
183- />
184- </ >
185- ) ;
186- } ;
134+ < FlatList
135+ contentContainerStyle = { styles . contentContainer }
136+ // TODO: Remove the following filter once we have two way scroll functionality on threads.
137+ data = { messages ? messages . filter ( ( { parent_id } ) => ! parent_id ) : [ ] }
138+ keyboardDismissMode = 'on-drag'
139+ ListEmptyComponent = { EmptySearchIndicator }
140+ onEndReached = { loadMore }
141+ onRefresh = { refreshList }
142+ ref = { scrollRef }
143+ refreshing = { refreshing }
144+ renderItem = { ( { item } ) => (
145+ < TouchableOpacity
146+ onPress = { ( ) => {
147+ navigation . navigate ( 'ChannelScreen' , {
148+ channelId : item . channel ?. id ,
149+ messageId : item . id ,
150+ } ) ;
151+ } }
152+ style = { [ styles . itemContainer , { borderBottomColor : border } ] }
153+ testID = 'channel-preview-button'
154+ >
155+ < Avatar image = { item . user ?. image } name = { item . user ?. name } size = { 40 } />
156+ < View style = { styles . flex } >
157+ < View style = { styles . row } >
158+ < Text numberOfLines = { 1 } style = { [ styles . titleContainer , { color : black } ] } >
159+ < Text style = { styles . title } > { `${ item . user ?. name } ` } </ Text >
160+ { ! ! item . channel ?. name && (
161+ < Text style = { styles . detailsText } >
162+ in
163+ < Text style = { styles . title } > { ` ${ item . channel ?. name } ` } </ Text >
164+ </ Text >
165+ ) }
166+ </ Text >
167+ </ View >
168+ < View style = { styles . row } >
169+ < Text
170+ numberOfLines = { 1 }
171+ style = { [
172+ styles . message ,
173+ {
174+ color : grey ,
175+ } ,
176+ ] }
177+ >
178+ { item . text }
179+ </ Text >
180+ < Text
181+ style = { [
182+ styles . date ,
183+ {
184+ color : grey ,
185+ } ,
186+ ] }
187+ >
188+ { dayjs ( item . created_at ) . calendar ( undefined , {
189+ lastDay : 'DD/MM' , // The day before ( Yesterday at 2:30 AM )
190+ lastWeek : 'DD/MM' , // Last week ( Last Monday at 2:30 AM )
191+ sameDay : 'h:mm A' , // The same day ( Today at 2:30 AM )
192+ sameElse : 'DD/MM/YYYY' , // Everything else ( 17/10/2011 )
193+ } ) }
194+ </ Text >
195+ </ View >
196+ </ View >
197+ </ TouchableOpacity >
198+ ) }
199+ style = { styles . flex }
200+ />
201+ </ >
202+ ) ;
203+ } ,
204+ ) ;
0 commit comments