feat(mobile): optimize list search result list

This commit is contained in:
DIYgod
2025-04-23 19:40:11 +08:00
parent 4027d0e6eb
commit 01b8037336
3 changed files with 128 additions and 96 deletions
+5
View File
@@ -0,0 +1,5 @@
import { UrlBuilder as UrlBuilderClass } from "@follow/utils/src/url-builder"
import { proxyEnv } from "./proxy-env"
export const UrlBuilder = new UrlBuilderClass(proxyEnv.WEB_URL)
@@ -5,7 +5,6 @@ import { LinearGradient } from "expo-linear-gradient"
import { useAtomValue } from "jotai"
import { Text, useWindowDimensions, View } from "react-native"
import { ScrollView } from "react-native-gesture-handler"
import Animated, { FadeInUp } from "react-native-reanimated"
import { RelativeDateTime } from "@/src/components/ui/datetime/RelativeDateTime"
import { FeedIcon } from "@/src/components/ui/icon/feed-icon"
@@ -72,103 +71,107 @@ const SearchFeedItem = ({ item }: { item: SearchResultItem }) => {
const iconColor = useColor("text")
return (
<Animated.View entering={FadeInUp}>
<ItemPressable
itemStyle={ItemPressableStyle.Plain}
className="py-8"
onPress={() => {
if (item.feed?.id) {
navigation.presentControllerView(FollowScreen, {
id: item.feed.id,
type: "feed",
})
}
}}
>
{/* Headline */}
<View className="flex-row items-center gap-2 pl-4 pr-2">
<View className="size-[32px] overflow-hidden rounded-lg">
<FeedIcon
size={32}
feed={
item.feed
? {
id: item.feed?.id!,
title: item.feed?.title!,
url: item.feed?.url!,
image: item.feed?.image!,
ownerUserId: item.feed?.ownerUserId!,
siteUrl: item.feed?.siteUrl!,
type: FeedViewType.Articles,
}
: undefined
}
/>
</View>
<View className="flex-1">
<Text
className="text-text text-lg font-semibold"
ellipsizeMode="middle"
numberOfLines={1}
>
{item.feed?.title}
<ItemPressable
itemStyle={ItemPressableStyle.Plain}
className="py-8"
onPress={() => {
if (item.feed?.id) {
navigation.presentControllerView(FollowScreen, {
id: item.feed.id,
type: "feed",
})
}
}}
>
{/* Headline */}
<View className="flex-row items-center gap-2 pl-4 pr-2">
<View className="size-[32px] overflow-hidden rounded-lg">
<FeedIcon
size={32}
feed={
item.feed
? {
id: item.feed?.id!,
title: item.feed?.title!,
url: item.feed?.url!,
image: item.feed?.image!,
ownerUserId: item.feed?.ownerUserId!,
siteUrl: item.feed?.siteUrl!,
type: FeedViewType.Articles,
}
: undefined
}
/>
</View>
<View className="flex-1">
<Text
className="text-text text-lg font-semibold"
ellipsizeMode="middle"
numberOfLines={1}
>
{item.feed?.title}
</Text>
{!!item.feed?.description && (
<Text className="text-text/60" ellipsizeMode="tail" numberOfLines={1}>
{item.feed?.description}
</Text>
{!!item.feed?.description && (
<Text className="text-text/60" ellipsizeMode="tail" numberOfLines={1}>
{item.feed?.description}
</Text>
)}
</View>
{/* Subscribe */}
{isSubscribed && (
<View className="ml-auto">
<View className="bg-gray-5/60 rounded-lg px-3 py-2">
<Text className="text-gray-2 text-sm font-medium">Followed</Text>
</View>
</View>
)}
</View>
<View className="mt-3 flex-row items-center gap-1 pl-4 opacity-60">
<RightCuteReIcon width={16} height={16} />
<Text className="text-text">{item.feed?.url}</Text>
</View>
{/* Preview */}
<View className="mt-3">
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerClassName="flex flex-row gap-4 pl-4"
>
{item.entries?.map((entry) => <PreviewItem entry={entry} key={entry.id} />)}
</ScrollView>
</View>
<View className="mt-4 flex-row items-center gap-6 pl-4 opacity-60">
<View className="flex-row items-center gap-2">
<User3CuteReIcon width={16} height={16} color={iconColor} />
<Text className="text-text">{item.subscriptionCount} followers</Text>
{/* Subscribe */}
{isSubscribed ? (
<View className="ml-auto">
<View className="bg-gray-5/60 rounded-lg px-3 py-2">
<Text className="text-gray-2 text-sm font-bold">Followed</Text>
</View>
</View>
<View className="flex-row items-center gap-2">
{item.updatesPerWeek ? (
<>
<SafetyCertificateCuteReIcon width={16} height={16} color={iconColor} />
<Text className="text-text">{item.updatesPerWeek} entries/week</Text>
</>
) : item.entries?.[0]?.publishedAt ? (
<>
<SafeAlertCuteReIcon width={16} height={16} color={iconColor} />
<Text className="text-text">Updated</Text>
<RelativeDateTime
className="text-text"
date={new Date(item.entries[0].publishedAt)}
/>
</>
) : null}
) : (
<View className="ml-auto">
<View className="bg-accent rounded-lg px-3 py-2">
<Text className="text-sm font-bold text-white">Follow</Text>
</View>
</View>
)}
</View>
<View className="mt-3 flex-row items-center gap-1 pl-4 opacity-60">
<RightCuteReIcon width={16} height={16} />
<Text className="text-text">{item.feed?.url}</Text>
</View>
{/* Preview */}
<View className="mt-3">
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerClassName="flex flex-row gap-4 pl-4"
>
{item.entries?.map((entry) => <PreviewItem entry={entry} key={entry.id} />)}
</ScrollView>
</View>
<View className="mt-4 flex-row items-center gap-6 pl-4 opacity-60">
<View className="flex-row items-center gap-2">
<User3CuteReIcon width={16} height={16} color={iconColor} />
<Text className="text-text">{item.subscriptionCount} followers</Text>
</View>
</ItemPressable>
</Animated.View>
<View className="flex-row items-center gap-2">
{item.updatesPerWeek ? (
<>
<SafetyCertificateCuteReIcon width={16} height={16} color={iconColor} />
<Text className="text-text">{item.updatesPerWeek} entries/week</Text>
</>
) : item.entries?.[0]?.publishedAt ? (
<>
<SafeAlertCuteReIcon width={16} height={16} color={iconColor} />
<Text className="text-text">Updated</Text>
<RelativeDateTime
className="text-text"
date={new Date(item.entries[0].publishedAt)}
/>
</>
) : null}
</View>
</View>
</ItemPressable>
)
}
@@ -7,10 +7,14 @@ import { FallbackIcon } from "@/src/components/ui/icon/fallback-icon"
import { Image } from "@/src/components/ui/image/Image"
import { ItemPressableStyle } from "@/src/components/ui/pressable/enum"
import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable"
import { RightCuteReIcon } from "@/src/icons/right_cute_re"
import { User3CuteReIcon } from "@/src/icons/user_3_cute_re"
import { apiClient } from "@/src/lib/api-fetch"
import { useNavigation } from "@/src/lib/navigation/hooks"
import { UrlBuilder } from "@/src/lib/url-builder"
import { FollowScreen } from "@/src/screens/(modal)/FollowScreen"
import { useSubscriptionByListId } from "@/src/store/subscription/hooks"
import { useColor } from "@/src/theme/colors"
import { useSearchPageContext } from "../ctx"
import { ItemSeparator } from "./__base"
@@ -58,10 +62,12 @@ export const SearchList = () => {
const SearchListCard = memo(({ item }: { item: SearchResultItem }) => {
const isSubscribed = useSubscriptionByListId(item.list?.id ?? "")
const navigation = useNavigation()
const iconColor = useColor("text")
return (
<ItemPressable
itemStyle={ItemPressableStyle.Plain}
className="py-2"
className="py-8"
onPress={() => {
if (item.list?.id) {
navigation.presentControllerView(FollowScreen, {
@@ -95,14 +101,32 @@ const SearchListCard = memo(({ item }: { item: SearchResultItem }) => {
)}
</View>
{/* Subscribe */}
{isSubscribed && (
{isSubscribed ? (
<View className="ml-auto">
<View className="bg-gray-5/60 rounded-full px-2 py-1">
<Text className="text-gray-2 text-sm font-medium">Subscribed</Text>
<View className="bg-gray-5/60 rounded-lg px-3 py-2">
<Text className="text-gray-2 text-sm font-bold">Followed</Text>
</View>
</View>
) : (
<View className="ml-auto">
<View className="bg-accent rounded-lg px-3 py-2">
<Text className="text-sm font-bold text-white">Follow</Text>
</View>
</View>
)}
</View>
<View className="mt-3 flex-row items-center gap-1 pl-4 opacity-60">
<RightCuteReIcon width={16} height={16} />
<Text className="text-text text-sm">{UrlBuilder.shareList(item.list?.id ?? "")}</Text>
</View>
<View className="mt-4 flex-row items-center gap-6 pl-4 opacity-60">
<View className="flex-row items-center gap-2">
<User3CuteReIcon width={16} height={16} color={iconColor} />
<Text className="text-text">{item.subscriptionCount} followers</Text>
</View>
</View>
</ItemPressable>
)
})