diff --git a/src/view/shell/desktop/Search.tsx b/src/view/shell/desktop/Search.tsx index 38da4e2467..937b5132bc 100644 --- a/src/view/shell/desktop/Search.tsx +++ b/src/view/shell/desktop/Search.tsx @@ -1,8 +1,8 @@ +import {memo, useCallback, useDeferredValue, useState} from 'react' import React from 'react' import { ActivityIndicator, - StyleSheet, - TouchableOpacity, + type StyleProp, View, type ViewStyle, } from 'react-native' @@ -10,95 +10,76 @@ import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {StackActions, useNavigation} from '@react-navigation/native' -import {usePalette} from '#/lib/hooks/usePalette' import {type NavigationProp} from '#/lib/routes/types' import {useModerationOpts} from '#/state/preferences/moderation-opts' import {useActorAutocompleteQuery} from '#/state/queries/actor-autocomplete' -import {Link} from '#/view/com/util/Link' -import {Text} from '#/view/com/util/text/Text' import {SearchProfileCard} from '#/screens/Search/components/SearchProfileCard' -import {atoms as a} from '#/alf' +import {atoms as a, useTheme} from '#/alf' import {SearchInput} from '#/components/forms/SearchInput' +import {Link, type LinkProps} from '#/components/Link' +import {Text} from '#/components/Typography' let SearchLinkCard = ({ label, to, - onPress, style, }: { label: string - to?: string - onPress?: () => void - style?: ViewStyle + to: LinkProps['to'] + style?: StyleProp }): React.ReactNode => { - const pal = usePalette('default') - - const inner = ( - - - {label} - - - ) - - if (onPress) { - return ( - - {inner} - - ) - } + const t = useTheme() return ( - - - - {label} - - + + {({focused, hovered, pressed}) => ( + + {label} + + )} ) } -SearchLinkCard = React.memo(SearchLinkCard) +SearchLinkCard = memo(SearchLinkCard) export {SearchLinkCard} export function DesktopSearch() { const {_} = useLingui() - const pal = usePalette('default') + const t = useTheme() const navigation = useNavigation() - const [isActive, setIsActive] = React.useState(false) - const [query, setQuery] = React.useState('') + const [isActive, setIsActive] = useState(false) + const [query, setQuery] = useState('') + const deferredQuery = useDeferredValue(query) const {data: autocompleteData, isFetching} = useActorAutocompleteQuery( - query, + deferredQuery, true, ) const moderationOpts = useModerationOpts() - const onChangeText = React.useCallback((text: string) => { + const onChangeText = useCallback((text: string) => { setQuery(text) setIsActive(text.length > 0) }, []) - const onPressCancelSearch = React.useCallback(() => { + const onPressCancelSearch = useCallback(() => { setQuery('') setIsActive(false) }, [setQuery]) - const onSubmit = React.useCallback(() => { + const onSubmit = useCallback(() => { setIsActive(false) - if (!query.length) return - navigation.dispatch(StackActions.push('Search', {q: query})) - }, [query, navigation]) + if (!deferredQuery.length) return + navigation.dispatch(StackActions.push('Search', {q: deferredQuery})) + }, [deferredQuery, navigation]) const onSearchProfileCardPress = React.useCallback(() => { setQuery('') @@ -106,62 +87,48 @@ export function DesktopSearch() { }, []) return ( - + - {query !== '' && isActive && moderationOpts && ( + {deferredQuery !== '' && isActive && moderationOpts && ( + 0 || isFetching) && a.border_b, + ]} + /> {isFetching && !autocompleteData?.length ? ( - + ) : ( - <> - 0 - ? {borderBottomWidth: 1} - : undefined - } + autocompleteData?.map(item => ( + - {autocompleteData?.map(item => ( - - ))} - + )) )} )} ) } - -const styles = StyleSheet.create({ - container: { - position: 'relative', - width: '100%', - }, - resultsContainer: { - marginTop: 10, - flexDirection: 'column', - width: '100%', - borderWidth: 1, - borderRadius: 6, - }, -})