1
1
import type { ForwardedRef , ReactNode , RefObject } from 'react' ;
2
2
import React , { forwardRef , useState } from 'react' ;
3
- import type { StyleProp , TextInputProps , ViewStyle } from 'react-native' ;
4
3
import { View } from 'react-native' ;
4
+ import type { StyleProp , TextInputProps , ViewStyle } from 'react-native' ;
5
+ import { useOnyx } from 'react-native-onyx' ;
5
6
import FormHelpMessage from '@components/FormHelpMessage' ;
6
7
import type { SelectionListHandle } from '@components/SelectionList/types' ;
7
8
import TextInput from '@components/TextInput' ;
8
9
import type { BaseTextInputRef } from '@components/TextInput/BaseTextInput/types' ;
10
+ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' ;
9
11
import useLocalize from '@hooks/useLocalize' ;
10
12
import useNetwork from '@hooks/useNetwork' ;
11
13
import useThemeStyles from '@hooks/useThemeStyles' ;
14
+ import { parseForLiveMarkdown } from '@libs/SearchAutocompleteUtils' ;
12
15
import handleKeyPress from '@libs/SearchInputOnKeyPress' ;
13
16
import shouldDelayFocus from '@libs/shouldDelayFocus' ;
14
17
import variables from '@styles/variables' ;
15
18
import CONST from '@src/CONST' ;
19
+ import ONYXKEYS from '@src/ONYXKEYS' ;
16
20
17
- type SearchRouterInputProps = {
21
+ type SearchAutocompleteInputProps = {
18
22
/** Value of TextInput */
19
23
value : string ;
20
24
@@ -24,8 +28,8 @@ type SearchRouterInputProps = {
24
28
/** Callback invoked when the user submits the input */
25
29
onSubmit ?: ( ) => void ;
26
30
27
- /** SearchRouterList ref for managing TextInput and SearchRouterList focus */
28
- routerListRef ?: RefObject < SelectionListHandle > ;
31
+ /** SearchAutocompleteList ref for managing TextInput and SearchAutocompleteList focus */
32
+ autocompleteListRef ?: RefObject < SelectionListHandle > ;
29
33
30
34
/** Whether the input is full width */
31
35
isFullWidth : boolean ;
@@ -56,14 +60,14 @@ type SearchRouterInputProps = {
56
60
57
61
/** Whether the search reports API call is running */
58
62
isSearchingForReports ?: boolean ;
59
- } & Pick < TextInputProps , 'caretHidden' | 'autoFocus' > ;
63
+ } & Pick < TextInputProps , 'caretHidden' | 'autoFocus' | 'selection' > ;
60
64
61
- function SearchRouterInput (
65
+ function SearchAutocompleteInput (
62
66
{
63
67
value,
64
68
onSearchQueryChange,
65
69
onSubmit = ( ) => { } ,
66
- routerListRef ,
70
+ autocompleteListRef ,
67
71
isFullWidth,
68
72
disabled = false ,
69
73
shouldShowOfflineMessage = false ,
@@ -76,13 +80,19 @@ function SearchRouterInput(
76
80
outerWrapperStyle,
77
81
rightComponent,
78
82
isSearchingForReports,
79
- } : SearchRouterInputProps ,
83
+ selection,
84
+ } : SearchAutocompleteInputProps ,
80
85
ref : ForwardedRef < BaseTextInputRef > ,
81
86
) {
82
87
const styles = useThemeStyles ( ) ;
83
88
const { translate} = useLocalize ( ) ;
84
89
const [ isFocused , setIsFocused ] = useState < boolean > ( false ) ;
85
90
const { isOffline} = useNetwork ( ) ;
91
+ const currentUserPersonalDetails = useCurrentUserPersonalDetails ( ) ;
92
+
93
+ const [ loginList ] = useOnyx ( ONYXKEYS . LOGIN_LIST ) ;
94
+ const emailList = Object . keys ( loginList ?? { } ) ;
95
+
86
96
const offlineMessage : string = isOffline && shouldShowOfflineMessage ? `${ translate ( 'common.youAppearToBeOffline' ) } ${ translate ( 'search.resultsAreLimited' ) } ` : '' ;
87
97
88
98
const inputWidth = isFullWidth ? styles . w100 : { width : variables . popoverWidth } ;
@@ -95,7 +105,7 @@ function SearchRouterInput(
95
105
fsClass = "fs-unmask"
96
106
>
97
107
< TextInput
98
- testID = "search-router -text-input"
108
+ testID = "search-autocomplete -text-input"
99
109
value = { value }
100
110
onChangeText = { onSearchQueryChange }
101
111
autoFocus = { autoFocus }
@@ -113,21 +123,29 @@ function SearchRouterInput(
113
123
maxLength = { CONST . SEARCH_QUERY_LIMIT }
114
124
onSubmitEditing = { onSubmit }
115
125
shouldUseDisabledStyles = { false }
116
- textInputContainerStyles = { [ styles . borderNone , styles . pb0 ] }
126
+ textInputContainerStyles = { [ styles . borderNone , styles . pb0 , styles . pr3 ] }
117
127
inputStyle = { [ inputWidth , styles . pl3 , styles . pr3 ] }
118
128
onFocus = { ( ) => {
119
129
setIsFocused ( true ) ;
120
- routerListRef ?. current ?. updateExternalTextInputFocus ( true ) ;
130
+ autocompleteListRef ?. current ?. updateExternalTextInputFocus ( true ) ;
121
131
onFocus ?.( ) ;
122
132
} }
123
133
onBlur = { ( ) => {
124
134
setIsFocused ( false ) ;
125
- routerListRef ?. current ?. updateExternalTextInputFocus ( false ) ;
135
+ autocompleteListRef ?. current ?. updateExternalTextInputFocus ( false ) ;
126
136
onBlur ?.( ) ;
127
137
} }
128
138
isLoading = { ! ! isSearchingForReports }
129
139
ref = { ref }
130
140
onKeyPress = { handleKeyPress ( onSubmit ) }
141
+ isMarkdownEnabled
142
+ multiline = { false }
143
+ parser = { ( input : string ) => {
144
+ 'worklet' ;
145
+
146
+ return parseForLiveMarkdown ( input , emailList , currentUserPersonalDetails . displayName ?? '' ) ;
147
+ } }
148
+ selection = { selection }
131
149
/>
132
150
</ View >
133
151
{ ! ! rightComponent && < View style = { styles . pr3 } > { rightComponent } </ View > }
@@ -141,6 +159,7 @@ function SearchRouterInput(
141
159
) ;
142
160
}
143
161
144
- SearchRouterInput . displayName = 'SearchRouterInput ' ;
162
+ SearchAutocompleteInput . displayName = 'SearchAutocompleteInput ' ;
145
163
146
- export default forwardRef ( SearchRouterInput ) ;
164
+ export type { SearchAutocompleteInputProps } ;
165
+ export default forwardRef ( SearchAutocompleteInput ) ;
0 commit comments