diff --git a/apps/mobile/src/modules/discover/DiscoverContent.tsx b/apps/mobile/src/modules/discover/DiscoverContent.tsx index ac6fb9730..245d81886 100644 --- a/apps/mobile/src/modules/discover/DiscoverContent.tsx +++ b/apps/mobile/src/modules/discover/DiscoverContent.tsx @@ -7,18 +7,18 @@ import { Pressable, StyleSheet, Text, View } from "react-native" import { Grid } from "@/src/components/ui/grid" import { useNavigation } from "@/src/lib/navigation/hooks" -import { GoodLuck } from "@/src/modules/discover/GoodLuck" import { Recommendations } from "@/src/modules/discover/Recommendations" +import { Trending } from "@/src/modules/discover/Trending" import { RecommendationCategoryScreen } from "@/src/screens/(stack)/recommendation/RecommendationCategoryScreen" export function DiscoverContent() { return ( - Good Luck + Trending - + Categories diff --git a/apps/mobile/src/modules/discover/FeedSummary.tsx b/apps/mobile/src/modules/discover/FeedSummary.tsx index 049f7a4ad..3e98b363f 100644 --- a/apps/mobile/src/modules/discover/FeedSummary.tsx +++ b/apps/mobile/src/modules/discover/FeedSummary.tsx @@ -19,10 +19,12 @@ export const FeedSummary = ({ item, children, className, + simple, }: { item: SearchResultItem children?: React.ReactNode className?: string + simple?: boolean }) => { const navigation = useNavigation() @@ -75,22 +77,24 @@ export const FeedSummary = ({ {item.feed?.url} - {!!item.feed?.description && ( + {!simple && !!item.feed?.description && ( {item.feed?.description} )} - - {/* Preview */} - - - {item.entries?.map((entry) => )} - - + {!simple && !!item.entries && ( + + + {item.entries?.map((entry) => ( + + ))} + + + )} {children} ) diff --git a/apps/mobile/src/modules/discover/GoodLuck.tsx b/apps/mobile/src/modules/discover/GoodLuck.tsx deleted file mode 100644 index c38068837..000000000 --- a/apps/mobile/src/modules/discover/GoodLuck.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import { RSSHubCategories } from "@follow/constants" -import type { RSSHubRouteDeclaration } from "@follow/models/src/rsshub" -import { useQuery } from "@tanstack/react-query" -import { shuffle } from "es-toolkit/compat" -import { useMemo } from "react" -import { View } from "react-native" - -import { PlatformActivityIndicator } from "@/src/components/ui/loading/PlatformActivityIndicator" - -import { fetchRsshubPopular } from "./api" -import { RecommendationListItem } from "./RecommendationListItem" - -export const GoodLuck = () => { - const randomTab = useMemo( - () => RSSHubCategories[Math.floor(Math.random() * RSSHubCategories.length)]!, - [], - ) - const { data, isLoading } = useQuery({ - queryKey: ["rsshub-popular", "cache", randomTab], - queryFn: () => fetchRsshubPopular(randomTab, "all").then((res) => res.data), - }) - - const arr = useMemo(() => { - if (!data) return [] - const keys = shuffle(Object.keys(data)).slice(0, 2) - - return keys.map((key) => { - const route = data[key] - return { - key, - route, - } - }) - }, [data]) - - return ( - - {isLoading ? ( - - - - ) : ( - arr.map((item) => ( - - )) - )} - - ) -} diff --git a/apps/mobile/src/modules/discover/Trending.tsx b/apps/mobile/src/modules/discover/Trending.tsx new file mode 100644 index 000000000..4405e5ba7 --- /dev/null +++ b/apps/mobile/src/modules/discover/Trending.tsx @@ -0,0 +1,29 @@ +import { useQuery } from "@tanstack/react-query" +import { View } from "react-native" + +import { PlatformActivityIndicator } from "@/src/components/ui/loading/PlatformActivityIndicator" + +import { fetchFeedTrending } from "./api" +import { TrendingFeedCard } from "./TrendingFeedCard" + +export const Trending = () => { + const { data, isLoading } = useQuery({ + queryKey: ["trending", "feeds"], + queryFn: () => + fetchFeedTrending({ + limit: 20, + }).then((res) => res.data), + }) + + return ( + + {isLoading ? ( + + + + ) : ( + data?.map((item) => ) + )} + + ) +} diff --git a/apps/mobile/src/modules/discover/TrendingFeedCard.tsx b/apps/mobile/src/modules/discover/TrendingFeedCard.tsx new file mode 100644 index 000000000..883f377f4 --- /dev/null +++ b/apps/mobile/src/modules/discover/TrendingFeedCard.tsx @@ -0,0 +1,37 @@ +import { Text, View } from "react-native" + +import { User3CuteReIcon } from "@/src/icons/user_3_cute_re" +import type { apiClient } from "@/src/lib/api-fetch" +import { useSubscriptionByFeedId } from "@/src/store/subscription/hooks" +import { useColor } from "@/src/theme/colors" + +import { FeedSummary } from "./FeedSummary" + +type SearchResultItem = Awaited>["data"][number] + +export const TrendingFeedCard = ({ item }: { item: SearchResultItem }) => { + const isSubscribed = useSubscriptionByFeedId(item.feed?.id ?? "") + const iconColor = useColor("text") + + return ( + + + + + {item.analytics?.subscriptionCount} followers + + + {isSubscribed ? ( + + Followed + + ) : ( + + Follow + + )} + + + + ) +} diff --git a/apps/mobile/src/modules/discover/api.ts b/apps/mobile/src/modules/discover/api.ts index 5deeabe55..b1a538a98 100644 --- a/apps/mobile/src/modules/discover/api.ts +++ b/apps/mobile/src/modules/discover/api.ts @@ -11,3 +11,21 @@ export const fetchRsshubPopular = (category: DiscoverCategories, lang: Language) }, }) } + +export const fetchFeedTrending = ({ + lang, + view, + limit, +}: { + lang?: "eng" | "cmn" + view?: number + limit: number +}) => { + return apiClient.trending.feeds.$get({ + query: { + language: lang, + view, + limit, + }, + }) +} diff --git a/apps/mobile/src/modules/discover/search-tabs/SearchFeedCard.tsx b/apps/mobile/src/modules/discover/search-tabs/SearchFeedCard.tsx index b1d4929f8..4147e398f 100644 --- a/apps/mobile/src/modules/discover/search-tabs/SearchFeedCard.tsx +++ b/apps/mobile/src/modules/discover/search-tabs/SearchFeedCard.tsx @@ -17,52 +17,46 @@ export const SearchFeedCard = ({ item }: { item: SearchResultItem }) => { const iconColor = useColor("text") return ( - - - <> - - - - - {item.analytics?.subscriptionCount} followers - - - - {item.analytics?.updatesPerWeek ? ( - <> - - - {item.analytics.updatesPerWeek} entries/week - - - ) : item.analytics?.latestEntryPublishedAt ? ( - <> - - Updated - - - ) : null} - + + <> + + + + {item.analytics?.subscriptionCount} followers - {/* Subscribe */} + + {item.analytics?.updatesPerWeek ? ( + <> + + + {item.analytics.updatesPerWeek} entries/week + + + ) : item.analytics?.latestEntryPublishedAt ? ( + <> + + Updated + + + ) : null} + + + {/* Subscribe */} + {isSubscribed ? ( - - - Followed - + + Followed ) : ( - - - Follow - + + Follow )} - - - + + + ) }