From 1cb5b73eb5901f242d79f357d52bca7af5d8c8b3 Mon Sep 17 00:00:00 2001 From: Innei Date: Wed, 4 Dec 2024 23:35:31 +0800 Subject: [PATCH] feat(trending): support language filter Signed-off-by: Innei --- apps/renderer/src/api/trending.ts | 11 ++++- .../src/modules/discover/recommendations.tsx | 12 ++++- apps/renderer/src/modules/trending/index.tsx | 46 +++++++++---------- .../(layer)/(subview)/discover/index.tsx | 2 - locales/app/zh-CN.json | 2 +- locales/app/zh-HK.json | 1 - locales/app/zh-TW.json | 1 - 7 files changed, 42 insertions(+), 33 deletions(-) diff --git a/apps/renderer/src/api/trending.ts b/apps/renderer/src/api/trending.ts index 92a81212b..061491e0a 100644 --- a/apps/renderer/src/api/trending.ts +++ b/apps/renderer/src/api/trending.ts @@ -4,7 +4,14 @@ import camelcaseKeys from "camelcase-keys" import { apiFetch } from "~/lib/api-fetch" const v1ApiPrefix = "/v1" -export const getTrendingAggregates = async () => { - const data = await apiFetch(`${v1ApiPrefix}/trendings`) +export const getTrendingAggregates = async (params: { language: string }) => { + const data = await apiFetch( + `${v1ApiPrefix}/trendings?language=${params.language}`, + { + params: { + language: params.language, + }, + }, + ) return camelcaseKeys(data as any, { deep: true }) as Models.TrendingAggregates } diff --git a/apps/renderer/src/modules/discover/recommendations.tsx b/apps/renderer/src/modules/discover/recommendations.tsx index 7b118e5fc..dc98204e2 100644 --- a/apps/renderer/src/modules/discover/recommendations.tsx +++ b/apps/renderer/src/modules/discover/recommendations.tsx @@ -13,6 +13,7 @@ import { useGeneralSettingKey } from "~/atoms/settings/general" import { useAuthQuery } from "~/hooks/common" import { Queries } from "~/queries" +import { TrendingButton } from "../trending" import { RSSHubCategories } from "./constants" import styles from "./recommendations.module.css" import { RecommendationCard } from "./recommendations-card" @@ -42,6 +43,7 @@ const fetchRsshubPopular = (category: DiscoverCategories, lang: Language) => { lang, }) } +let firstLoad = true export function Recommendations({ hideTitle, className, @@ -62,9 +64,13 @@ export function Recommendations({ meta: { persist: true, }, + staleTime: 1000 * 60 * 60 * 24, // 1 day + refetchOnMount: firstLoad ? "always" : true, placeholderData: keepPreviousData, }) + firstLoad = false + const { data, isLoading, isFetching } = rsshubPopular const keys = useMemo(() => { @@ -136,14 +142,18 @@ export function Recommendations({ return (
{!hideTitle && ( -
+
{t("discover.popular")} +
+ +
{isFetching && (
{t("discover.popular")} +
)} diff --git a/apps/renderer/src/modules/trending/index.tsx b/apps/renderer/src/modules/trending/index.tsx index ffd6abab8..f38687f73 100644 --- a/apps/renderer/src/modules/trending/index.tsx +++ b/apps/renderer/src/modules/trending/index.tsx @@ -1,10 +1,10 @@ import type { User } from "@auth/core/types" +import { isMobile } from "@follow/components/hooks/useMobile.js" import { PhUsersBold } from "@follow/components/icons/users.jsx" import { Avatar, AvatarFallback, AvatarImage } from "@follow/components/ui/avatar/index.jsx" import { ActionButton, Button } from "@follow/components/ui/button/index.js" import { LoadingWithIcon } from "@follow/components/ui/loading/index.jsx" import { ScrollArea } from "@follow/components/ui/scroll-area/index.js" -import { Tooltip, TooltipContent, TooltipTrigger } from "@follow/components/ui/tooltip/index.jsx" import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js" import type { FeedModel, Models } from "@follow/models" import { stopPropagation } from "@follow/utils/dom" @@ -22,38 +22,34 @@ import { FeedIcon } from "~/modules/feed/feed-icon" import { usePresentUserProfileModal } from "../profile/hooks" -export const Trend = ({ className }: { className?: string }) => { +interface TrendingProps { + language: string +} +export const TrendingButton = ({ language, className }: TrendingProps & { className?: string }) => { const { present } = useModalStack() const { t } = useTranslation() return ( - - {t("words.trending")} - - { - present({ - title: "Trending", - content: TrendContent, - CustomModalComponent: DrawerModalLayout, - }) - }} - className={cn( - "size-6 text-accent duration-200 hover:shadow-none", - "absolute bottom-1 right-3", - className, - )} - > - - - - + ) } -const TrendContent = () => { +const TrendContent: FC = ({ language }) => { const { data } = useQuery({ queryKey: ["trending"], queryFn: () => { - return getTrendingAggregates() + return getTrendingAggregates({ language }) }, }) diff --git a/apps/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx b/apps/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx index 042531d36..5bf082a0b 100644 --- a/apps/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx +++ b/apps/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx @@ -107,8 +107,6 @@ export function Component() { {t(tab.name)} ))} - - {/* */} {currentTabs.map((tab) => ( diff --git a/locales/app/zh-CN.json b/locales/app/zh-CN.json index b2210b899..89b7c5d9e 100644 --- a/locales/app/zh-CN.json +++ b/locales/app/zh-CN.json @@ -403,7 +403,7 @@ "words.starred": "收藏", "words.title": "标题", "words.transform": "转换", - "words.trending": "热门", + "words.trending": "趋势", "words.undo": "撤销", "words.unread": "未读", "words.user": "用户", diff --git a/locales/app/zh-HK.json b/locales/app/zh-HK.json index 2a4a533c3..8bbe364a9 100644 --- a/locales/app/zh-HK.json +++ b/locales/app/zh-HK.json @@ -401,7 +401,6 @@ "words.starred": "收藏", "words.title": "標題", "words.transform": "轉換", - "words.trending": "熱門", "words.undo": "取消動作", "words.unread": "未讀", "words.user": "使用者", diff --git a/locales/app/zh-TW.json b/locales/app/zh-TW.json index 37a2e9d4f..775c75704 100644 --- a/locales/app/zh-TW.json +++ b/locales/app/zh-TW.json @@ -401,7 +401,6 @@ "words.starred": "收藏", "words.title": "標題", "words.transform": "轉換", - "words.trending": "熱門", "words.undo": "撤銷", "words.unread": "未讀", "words.user": "使用者",