From f747882565fd474c0bf9cbab7b4a08a033e6386f Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 10 Jan 2025 20:03:21 +0800 Subject: [PATCH] feat(rn-search): impl search feeds and list view Signed-off-by: Innei --- .../src/components/ui/form/TextField.tsx | 3 + .../discover/search-tabs/SearchFeed.tsx | 129 +++++++++++++++++- .../modules/discover/search-tabs/__base.tsx | 17 ++- apps/mobile/src/modules/discover/search.tsx | 9 +- apps/mobile/src/modules/login/email.tsx | 10 +- apps/mobile/src/screens/(modal)/add.tsx | 3 +- apps/mobile/src/screens/(modal)/follow.tsx | 33 ++++- 7 files changed, 189 insertions(+), 15 deletions(-) diff --git a/apps/mobile/src/components/ui/form/TextField.tsx b/apps/mobile/src/components/ui/form/TextField.tsx index 4895a8cad..0e9e7f5ac 100644 --- a/apps/mobile/src/components/ui/form/TextField.tsx +++ b/apps/mobile/src/components/ui/form/TextField.tsx @@ -3,6 +3,8 @@ import { forwardRef } from "react" import type { StyleProp, TextInputProps, ViewStyle } from "react-native" import { StyleSheet, Text, TextInput, View } from "react-native" +import { accentColor } from "@/src/theme/colors" + import { FormLabel } from "./Label" interface TextFieldProps { @@ -35,6 +37,7 @@ export const TextField = forwardRef( style={wrapperStyle} > { const { searchValueAtom } = useSearchPageContext() const searchValue = useAtomValue(searchValueAtom) - const { data, isLoading } = useQuery({ + const { data, isLoading, refetch } = useQuery({ queryKey: ["searchFeed", searchValue], queryFn: () => { return apiClient.discover.$post({ @@ -38,6 +46,8 @@ export const SearchFeed = () => { return ( } data={data?.data} @@ -52,5 +62,118 @@ const renderItem = ({ item }: { item: SearchResultItem }) => ( ) const SearchFeedItem = memo(({ item }: { item: SearchResultItem }) => { - return {item.feed?.title} + const isSubscribed = useSubscriptionByFeedId(item.feed?.id ?? "") + return ( + + { + if (item.feed?.id) { + router.push(`/follow?id=${item.feed.id}`) + } + }} + > + {/* Headline */} + + + + + + + {item.feed?.title} + + {!!item.feed?.description && ( + + {item.feed?.description} + + )} + + {/* Subscribe */} + {isSubscribed && ( + + + Subscribed + + + )} + + + {/* Preview */} + + + {item.entries?.map((entry) => ( + // + // {entry.title} + // + + ))} + + + + + ) }) +const formatter = new Intl.DateTimeFormat("en-US", { + year: "numeric", + month: "short", + day: "numeric", +}) +const PreviewItem = ({ entry }: { entry: NonNullable[number] }) => { + const { width } = useWindowDimensions() + const firstMedia = entry.media?.[0] + + return ( + + {/* Left */} + + + {entry.title} + + + {formatter.format(new Date(entry.publishedAt))} + + + + {/* Right */} + {!!firstMedia && ( + + + + )} + + ) +} diff --git a/apps/mobile/src/modules/discover/search-tabs/__base.tsx b/apps/mobile/src/modules/discover/search-tabs/__base.tsx index e482077e6..cf9a5d0ba 100644 --- a/apps/mobile/src/modules/discover/search-tabs/__base.tsx +++ b/apps/mobile/src/modules/discover/search-tabs/__base.tsx @@ -1,6 +1,6 @@ import { forwardRef } from "react" import type { ScrollViewProps } from "react-native" -import { ScrollView, useWindowDimensions, View } from "react-native" +import { RefreshControl, ScrollView, useWindowDimensions, View } from "react-native" import type { FlatListPropsWithLayout } from "react-native-reanimated" import Animated, { LinearTransition } from "react-native-reanimated" import { useSafeAreaInsets } from "react-native-safe-area-context" @@ -41,7 +41,11 @@ export const BaseSearchPageRootView = ({ children }: { children: React.ReactNode ) } -export function BaseSearchPageFlatList({ ...props }: FlatListPropsWithLayout) { +export function BaseSearchPageFlatList({ + refreshing, + onRefresh, + ...props +}: FlatListPropsWithLayout & { refreshing: boolean; onRefresh: () => void }) { const insets = useSafeAreaInsets() const searchBarHeight = useSearchBarHeight() const offsetTop = searchBarHeight - insets.top @@ -51,10 +55,17 @@ export function BaseSearchPageFlatList({ ...props }: FlatListPropsWithLayout< itemLayoutAnimation={LinearTransition} className="flex-1" style={{ width: windowWidth }} - contentContainerStyle={{ paddingTop: offsetTop }} + contentContainerStyle={{ paddingTop: offsetTop + 8 }} scrollIndicatorInsets={{ bottom: insets.bottom, top: offsetTop }} automaticallyAdjustContentInsets contentInsetAdjustmentBehavior="always" + refreshControl={ + + } {...props} /> ) diff --git a/apps/mobile/src/modules/discover/search.tsx b/apps/mobile/src/modules/discover/search.tsx index 04f6da96f..3039f3545 100644 --- a/apps/mobile/src/modules/discover/search.tsx +++ b/apps/mobile/src/modules/discover/search.tsx @@ -56,7 +56,10 @@ const DiscoverHeaderImpl = () => { const headerHeight = getDefaultHeaderHeight(frame, false, insets.top) return ( - + @@ -70,7 +73,7 @@ const PlaceholerSearchBar = () => { return ( { router.push("/search") }} @@ -183,7 +186,7 @@ const SearchInput = () => { }, [isFocused]) return ( - + {focusOrHasValue && ( + return ( + + ) } export function EmailLogin() { diff --git a/apps/mobile/src/screens/(modal)/add.tsx b/apps/mobile/src/screens/(modal)/add.tsx index 28ed25057..ee30f6ea4 100644 --- a/apps/mobile/src/screens/(modal)/add.tsx +++ b/apps/mobile/src/screens/(modal)/add.tsx @@ -4,7 +4,7 @@ import { Text, TextInput, TouchableOpacity, View } from "react-native" import { ModalHeaderCloseButton } from "@/src/components/common/ModalSharedComponents" import { Search2CuteReIcon } from "@/src/icons/search_2_cute_re" -import { useColor } from "@/src/theme/colors" +import { accentColor, useColor } from "@/src/theme/colors" export default function Add() { const [url, setUrl] = useState("") @@ -33,6 +33,7 @@ export default function Add() { Feed URL feedSyncServices.fetchFeedById({ id: id as string }), + enabled: !feed, + }) + + if (isLoading) { + return ( + + + + ) + } + + return +} +function FollowImpl() { + const { id } = useLocalSearchParams() const feed = useFeed(id as string) - // const hasSub = useSubscriptionByFeedId(feed?.id || "") - // const isSubscribed = !!feedQuery.data?.subscription || hasSub + const isSubscribed = useSubscriptionByFeedId(feed?.id || "") const form = useForm>({ resolver: zodResolver(formSchema), @@ -73,11 +94,15 @@ export default function Follow() { const { isValid, isDirty } = form.formState + if (!feed?.id) { + return Feed ({id}) not found + } + return ( (