From 6d0557c959ed250ff0061605454324cc88775005 Mon Sep 17 00:00:00 2001 From: Mary Date: Tue, 16 Jan 2024 07:31:01 +0700 Subject: [PATCH 1/2] feat: better autocomplete view --- src/view/screens/Search/Search.tsx | 43 ++++++++++++----- src/view/shell/desktop/Search.tsx | 77 ++++++++++++++++++++++-------- 2 files changed, 86 insertions(+), 34 deletions(-) diff --git a/src/view/screens/Search/Search.tsx b/src/view/screens/Search/Search.tsx index 8e7e204ad2..02a631fa0d 100644 --- a/src/view/screens/Search/Search.tsx +++ b/src/view/screens/Search/Search.tsx @@ -42,7 +42,11 @@ import {useSetDrawerOpen} from '#/state/shell' import {useAnalytics} from '#/lib/analytics/analytics' import {MagnifyingGlassIcon} from '#/lib/icons' import {useModerationOpts} from '#/state/queries/preferences' -import {SearchResultCard} from '#/view/shell/desktop/Search' +import { + MATCH_HANDLE, + SearchLinkCard, + SearchProfileCard, +} from '#/view/shell/desktop/Search' import {useSetMinimalShellMode, useSetDrawerSwipeDisabled} from '#/state/shell' import {isWeb} from '#/platform/detection' import {listenSoftReset} from '#/state/events' @@ -511,6 +515,11 @@ export function SearchScreen( onPressCancelSearch() }, [onPressCancelSearch]) + const queryMaybeHandle = React.useMemo(() => { + const match = MATCH_HANDLE.exec(query) + return match && match[1] + }, [query]) + useFocusEffect( React.useCallback(() => { setMinimalShellMode(false) @@ -617,18 +626,26 @@ export function SearchScreen( dataSet={{stableGutters: '1'}} keyboardShouldPersistTaps="handled" keyboardDismissMode="on-drag"> - {searchResults.length ? ( - searchResults.map((item, i) => ( - - )) - ) : ( - - )} + + + {queryMaybeHandle ? ( + + ) : null} + + {searchResults.map(item => ( + + ))} diff --git a/src/view/shell/desktop/Search.tsx b/src/view/shell/desktop/Search.tsx index df49da55b0..c24940b522 100644 --- a/src/view/shell/desktop/Search.tsx +++ b/src/view/shell/desktop/Search.tsx @@ -29,13 +29,41 @@ import {UserAvatar} from '#/view/com/util/UserAvatar' import {useActorAutocompleteFn} from '#/state/queries/actor-autocomplete' import {useModerationOpts} from '#/state/queries/preferences' -export function SearchResultCard({ - profile, +export const MATCH_HANDLE = + /@?([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,}))/ + +export function SearchLinkCard({ + label, + to, style, +}: { + label: string + to: string + style?: ViewStyle +}) { + const pal = usePalette('default') + + return ( + + + + {label} + + + + ) +} + +export function SearchProfileCard({ + profile, moderation, }: { profile: AppBskyActorDefs.ProfileViewBasic - style: ViewStyle moderation: ProfileModeration }) { const pal = usePalette('default') @@ -50,9 +78,7 @@ export function SearchResultCard({ { + const match = MATCH_HANDLE.exec(query) + return match && match[1] + }, [query]) + return ( ) : ( <> - {searchResults.length ? ( - searchResults.map((item, i) => ( - - )) - ) : ( - - - No results found for {query} - - - )} + + + {queryMaybeHandle ? ( + + ) : null} + + {searchResults.map(item => ( + + ))} )} From f58e1149c91995a49c1b991e574e9942990ad449 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 18 Jan 2024 22:21:47 -0800 Subject: [PATCH 2/2] Change handling for mobile --- src/view/screens/Search/Search.tsx | 9 +++++++-- src/view/shell/desktop/Search.tsx | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/view/screens/Search/Search.tsx b/src/view/screens/Search/Search.tsx index 612eb5cc12..94aab2d961 100644 --- a/src/view/screens/Search/Search.tsx +++ b/src/view/screens/Search/Search.tsx @@ -48,7 +48,7 @@ import { SearchProfileCard, } from '#/view/shell/desktop/Search' import {useSetMinimalShellMode, useSetDrawerSwipeDisabled} from '#/state/shell' -import {isWeb} from '#/platform/detection' +import {isNative, isWeb} from '#/platform/detection' import {listenSoftReset} from '#/state/events' import {s} from '#/lib/styles' @@ -626,7 +626,12 @@ export function SearchScreen( keyboardDismissMode="on-drag"> diff --git a/src/view/shell/desktop/Search.tsx b/src/view/shell/desktop/Search.tsx index c24940b522..4a94837338 100644 --- a/src/view/shell/desktop/Search.tsx +++ b/src/view/shell/desktop/Search.tsx @@ -35,14 +35,36 @@ export const MATCH_HANDLE = export function SearchLinkCard({ label, to, + onPress, style, }: { label: string - to: string + to?: string + onPress?: () => void style?: ViewStyle }) { const pal = usePalette('default') + const inner = ( + + + {label} + + + ) + + if (onPress) { + return ( + + {inner} + + ) + } + return (