From e8ee30398ad26b8c9f1e587f3be0bd58c5719b8e Mon Sep 17 00:00:00 2001 From: DS Boyce <260543580+ds-boyce@users.noreply.github.com> Date: Wed, 1 Apr 2026 09:11:27 -0700 Subject: [PATCH] Update Search to use ALF atoms (#10146) Co-authored-by: Samuel Newman --- src/view/shell/desktop/Search.tsx | 128 ++++++++++++++---------------- 1 file changed, 59 insertions(+), 69 deletions(-) diff --git a/src/view/shell/desktop/Search.tsx b/src/view/shell/desktop/Search.tsx index ede77640dc..cb69eb0dfd 100644 --- a/src/view/shell/desktop/Search.tsx +++ b/src/view/shell/desktop/Search.tsx @@ -1,7 +1,6 @@ import {memo, useCallback, useState} from 'react' import { - ActivityIndicator, - StyleSheet, + type StyleProp, TouchableOpacity, View, type ViewStyle, @@ -9,15 +8,17 @@ import { import {useLingui} from '@lingui/react/macro' 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} from '#/components/Link' +import {Loader} from '#/components/Loader' +import {Text} from '#/components/Typography' + +const WHITESPACE_RE = /\s+/gu let SearchLinkCard = ({ label, @@ -28,20 +29,17 @@ let SearchLinkCard = ({ label: string to?: string onPress?: () => void - style?: ViewStyle + style?: StyleProp }): React.ReactNode => { - const pal = usePalette('default') + const t = useTheme() const inner = ( - - - {label} - + + {label} ) - if (onPress) { + if (onPress || !to) { return ( - - - {label} - - + + {label} ) } @@ -71,8 +64,8 @@ SearchLinkCard = memo(SearchLinkCard) export {SearchLinkCard} export function DesktopSearch() { + const t = useTheme() const {t: l} = useLingui() - const pal = usePalette('default') const navigation = useNavigation() const [isActive, setIsActive] = useState(false) const [query, setQuery] = useState('') @@ -80,6 +73,7 @@ export function DesktopSearch() { query, true, ) + const tQuery = query.replace(WHITESPACE_RE, ' ').trim() const moderationOpts = useModerationOpts() @@ -95,9 +89,9 @@ export function DesktopSearch() { const onSubmit = useCallback(() => { setIsActive(false) - if (!query.length) return - navigation.dispatch(StackActions.push('Search', {q: query})) - }, [query, navigation]) + if (!tQuery.length) return + navigation.dispatch(StackActions.push('Search', {q: tQuery})) + }, [tQuery, navigation]) const onSearchProfileCardPress = useCallback(() => { setQuery('') @@ -105,62 +99,58 @@ export function DesktopSearch() { }, []) return ( - + - {query !== '' && isActive && moderationOpts && ( + {tQuery !== '' && isActive && moderationOpts && ( + 0 ? a.border_b : undefined} + /> {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, - }, -})