Rename to reduce diff

This commit is contained in:
Dan Abramov
2024-04-27 01:29:24 +01:00
parent 47d101d791
commit 0faffb2bb5
+12 -12
View File
@@ -494,7 +494,7 @@ export function SearchScreen(
true, true,
) )
const [showAutocomplete, setShowAutocomplete] = React.useState(false) const [inputIsFocused, setInputIsFocused] = React.useState(false)
const [searchHistory, setSearchHistory] = React.useState<string[]>([]) const [searchHistory, setSearchHistory] = React.useState<string[]>([])
useFocusEffect( useFocusEffect(
@@ -532,9 +532,9 @@ export function SearchScreen(
const onPressCancelSearch = React.useCallback(() => { const onPressCancelSearch = React.useCallback(() => {
scrollToTopWeb() scrollToTopWeb()
if (showAutocomplete) { if (inputIsFocused) {
textInput.current?.blur() textInput.current?.blur()
setShowAutocomplete(false) setInputIsFocused(false)
setSearchText(queryParam) setSearchText(queryParam)
} else { } else {
// If we just `setParams` and set `q` to an empty string, the URL still displays `q=`, which isn't pretty. // If we just `setParams` and set `q` to an empty string, the URL still displays `q=`, which isn't pretty.
@@ -547,7 +547,7 @@ export function SearchScreen(
navigation.setParams({q: ''}) navigation.setParams({q: ''})
} }
} }
}, [showAutocomplete, navigation, queryParam]) }, [inputIsFocused, navigation, queryParam])
const onChangeText = React.useCallback(async (text: string) => { const onChangeText = React.useCallback(async (text: string) => {
scrollToTopWeb() scrollToTopWeb()
@@ -580,7 +580,7 @@ export function SearchScreen(
const onSubmit = React.useCallback(() => { const onSubmit = React.useCallback(() => {
scrollToTopWeb() scrollToTopWeb()
setShowAutocomplete(false) setInputIsFocused(false)
updateSearchHistory(searchText) updateSearchHistory(searchText)
if (isWeb) { if (isWeb) {
@@ -609,7 +609,7 @@ export function SearchScreen(
) )
const handleHistoryItemClick = (item: string) => { const handleHistoryItemClick = (item: string) => {
setShowAutocomplete(false) setInputIsFocused(false)
if (isWeb) { if (isWeb) {
navigation.push('Search', {q: item}) navigation.push('Search', {q: item})
} else { } else {
@@ -673,7 +673,7 @@ export function SearchScreen(
value={searchText} value={searchText}
style={[pal.text, styles.headerSearchInput]} style={[pal.text, styles.headerSearchInput]}
keyboardAppearance={theme.colorScheme} keyboardAppearance={theme.colorScheme}
onFocus={() => setShowAutocomplete(true)} onFocus={() => setInputIsFocused(true)}
onChangeText={onChangeText} onChangeText={onChangeText}
onSubmitEditing={onSubmit} onSubmitEditing={onSubmit}
autoFocus={false} autoFocus={false}
@@ -684,7 +684,7 @@ export function SearchScreen(
autoComplete="off" autoComplete="off"
autoCapitalize="none" autoCapitalize="none"
/> />
{showAutocomplete ? ( {inputIsFocused ? (
<Pressable <Pressable
testID="searchTextInputClearBtn" testID="searchTextInputClearBtn"
onPress={onPressClearQuery} onPress={onPressClearQuery}
@@ -701,7 +701,7 @@ export function SearchScreen(
) : undefined} ) : undefined}
</View> </View>
{(queryParam || showAutocomplete) && ( {(queryParam || inputIsFocused) && (
<View style={styles.headerCancelBtn}> <View style={styles.headerCancelBtn}>
<Pressable <Pressable
onPress={onPressCancelSearch} onPress={onPressCancelSearch}
@@ -715,7 +715,7 @@ export function SearchScreen(
)} )}
</CenteredView> </CenteredView>
{showAutocomplete && searchText.length > 0 ? ( {inputIsFocused && searchText.length > 0 ? (
<> <>
{!autocompleteData || !moderationOpts ? ( {!autocompleteData || !moderationOpts ? (
<Loader /> <Loader />
@@ -750,7 +750,7 @@ export function SearchScreen(
profile={item} profile={item}
moderation={moderateProfile(item, moderationOpts)} moderation={moderateProfile(item, moderationOpts)}
onPress={() => { onPress={() => {
setShowAutocomplete(false) setInputIsFocused(false)
textInput.current?.blur() textInput.current?.blur()
}} }}
/> />
@@ -760,7 +760,7 @@ export function SearchScreen(
</ScrollView> </ScrollView>
)} )}
</> </>
) : !queryParam && showAutocomplete ? ( ) : !queryParam && inputIsFocused ? (
<CenteredView <CenteredView
sideBorders={isTabletOrDesktop} sideBorders={isTabletOrDesktop}
// @ts-ignore web only -prf // @ts-ignore web only -prf