From d16ca5083f4830c75e48001776c7fc005edaa8cf Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 7 Jul 2025 20:17:12 +0300 Subject: [PATCH] fix type error, extract and plat-split a component --- .../Search/components/AutocompleteResults.tsx | 13 ++---- .../components/SearchLinkCard.native.tsx | 42 +++++++++++++++++++ .../Search/components/SearchLinkCard.tsx | 42 +++++++++++++++++++ src/view/shell/desktop/Search.tsx | 9 ++-- 4 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 src/screens/Search/components/SearchLinkCard.native.tsx create mode 100644 src/screens/Search/components/SearchLinkCard.tsx diff --git a/src/screens/Search/components/AutocompleteResults.tsx b/src/screens/Search/components/AutocompleteResults.tsx index c84f654838..cfdb6b4821 100644 --- a/src/screens/Search/components/AutocompleteResults.tsx +++ b/src/screens/Search/components/AutocompleteResults.tsx @@ -5,11 +5,10 @@ import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useModerationOpts} from '#/state/preferences/moderation-opts' -import {SearchLinkCard} from '#/view/shell/desktop/Search' import {SearchProfileCard} from '#/screens/Search/components/SearchProfileCard' -import {atoms as a, native} from '#/alf' +import {atoms as a} from '#/alf' import * as Layout from '#/components/Layout' -import {IS_NATIVE} from '#/env' +import {SearchLinkCard} from './SearchLinkCard' let AutocompleteResults = ({ isAutocompleteFetching, @@ -43,12 +42,8 @@ let AutocompleteResults = ({ keyboardDismissMode="on-drag"> {autocompleteData?.map(item => ( diff --git a/src/screens/Search/components/SearchLinkCard.native.tsx b/src/screens/Search/components/SearchLinkCard.native.tsx new file mode 100644 index 0000000000..613bfef978 --- /dev/null +++ b/src/screens/Search/components/SearchLinkCard.native.tsx @@ -0,0 +1,42 @@ +import {type StyleProp, View, type ViewStyle} from 'react-native' + +import {atoms as a, useTheme} from '#/alf' +import {Button} from '#/components/Button' +import {type LinkProps} from '#/components/Link' +import {Text} from '#/components/Typography' + +export function SearchLinkCard({ + label, + onPress, + style, +}: { + label: string + /** + * @platform web + */ + to: LinkProps['to'] + /** + * @platform native + */ + onPress: () => void + style?: StyleProp +}) { + const t = useTheme() + + return ( + + ) +} diff --git a/src/screens/Search/components/SearchLinkCard.tsx b/src/screens/Search/components/SearchLinkCard.tsx new file mode 100644 index 0000000000..8e5695b4b7 --- /dev/null +++ b/src/screens/Search/components/SearchLinkCard.tsx @@ -0,0 +1,42 @@ +import {type StyleProp, View, type ViewStyle} from 'react-native' + +import {atoms as a, useTheme} from '#/alf' +import {Link, type LinkProps} from '#/components/Link' +import {Text} from '#/components/Typography' + +export function SearchLinkCard({ + label, + to, + style, +}: { + label: string + /** + * @platform web + */ + to: LinkProps['to'] + /** + * @platform native + */ + onPress: () => void + style?: StyleProp +}) { + const t = useTheme() + + return ( + + {({focused, hovered, pressed}) => ( + + {label} + + )} + + ) +} diff --git a/src/view/shell/desktop/Search.tsx b/src/view/shell/desktop/Search.tsx index 93d753cd05..1f7b88d7f2 100644 --- a/src/view/shell/desktop/Search.tsx +++ b/src/view/shell/desktop/Search.tsx @@ -1,4 +1,4 @@ -import {memo, useDeferredValue, useRef, useState} from 'react' +import {useDeferredValue, useRef, useState} from 'react' import { ActivityIndicator, type StyleProp, @@ -9,7 +9,6 @@ import { import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {StackActions, useNavigation} from '@react-navigation/native' -import type React from 'react' import {type NavigationProp} from '#/lib/routes/types' import {useModerationOpts} from '#/state/preferences/moderation-opts' @@ -21,7 +20,7 @@ import {MagnifyingGlass2_Stroke2_Corner0_Rounded as SearchIcon} from '#/componen import {Link, type LinkProps} from '#/components/Link' import {Text} from '#/components/Typography' -let SearchLinkCard = ({ +function SearchLinkCard({ label, to, style, @@ -29,7 +28,7 @@ let SearchLinkCard = ({ label: string to: LinkProps['to'] style?: StyleProp -}): React.ReactNode => { +}) { const t = useTheme() return ( @@ -50,8 +49,6 @@ let SearchLinkCard = ({ ) } -SearchLinkCard = memo(SearchLinkCard) -export {SearchLinkCard} export function DesktopSearch() { const {_} = useLingui()