feat(trending): support language filter

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2024-12-04 23:35:31 +08:00
parent 5a30f38408
commit 1cb5b73eb5
7 changed files with 42 additions and 33 deletions
+9 -2
View File
@@ -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<Models.TrendingAggregates>(`${v1ApiPrefix}/trendings`)
export const getTrendingAggregates = async (params: { language: string }) => {
const data = await apiFetch<Models.TrendingAggregates>(
`${v1ApiPrefix}/trendings?language=${params.language}`,
{
params: {
language: params.language,
},
},
)
return camelcaseKeys(data as any, { deep: true }) as Models.TrendingAggregates
}
@@ -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 (
<div className={cn(!hideTitle && "mt-8 w-full max-w-[1200px]")}>
{!hideTitle && (
<div className="relative text-center text-lg font-bold">
<div className="center relative flex text-lg font-bold">
<span>{t("discover.popular")}</span>
<div className="absolute bottom-0 right-0">
<TrendingButton language={selectedLang} />
</div>
{isFetching && (
<div className="pointer-events-none absolute inset-x-0 top-0 flex items-center justify-center gap-8">
<span className="opacity-0" aria-hidden>
{t("discover.popular")}
</span>
<LoadingCircle size="small" className="center flex" />
</div>
)}
+21 -25
View File
@@ -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 (
<Tooltip>
<TooltipContent>{t("words.trending")}</TooltipContent>
<TooltipTrigger asChild>
<ActionButton
onClick={() => {
present({
title: "Trending",
content: TrendContent,
CustomModalComponent: DrawerModalLayout,
})
}}
className={cn(
"size-6 text-accent duration-200 hover:shadow-none",
"absolute bottom-1 right-3",
className,
)}
>
<i className="i-mgc-trending-up-cute-re" />
</ActionButton>
</TooltipTrigger>
</Tooltip>
<Button
variant={"outline"}
onClick={() => {
present({
title: t("words.trending"),
content: () => <TrendContent language={language} />,
CustomModalComponent: !isMobile() ? DrawerModalLayout : undefined,
})
}}
buttonClassName={cn("px-2", className)}
>
<i className="i-mgc-trending-up-cute-re mr-1" />
{t("words.trending")}
</Button>
)
}
const TrendContent = () => {
const TrendContent: FC<TrendingProps> = ({ language }) => {
const { data } = useQuery({
queryKey: ["trending"],
queryFn: () => {
return getTrendingAggregates()
return getTrendingAggregates({ language })
},
})
@@ -107,8 +107,6 @@ export function Component() {
{t(tab.name)}
</TabsTrigger>
))}
{/* <Trend className="relative bottom-0 left-1.5 mr-3.5 w-6" /> */}
</TabsList>
</ScrollArea.ScrollArea>
{currentTabs.map((tab) => (
+1 -1
View File
@@ -403,7 +403,7 @@
"words.starred": "收藏",
"words.title": "标题",
"words.transform": "转换",
"words.trending": "热门",
"words.trending": "趋势",
"words.undo": "撤销",
"words.unread": "未读",
"words.user": "用户",
-1
View File
@@ -401,7 +401,6 @@
"words.starred": "收藏",
"words.title": "標題",
"words.transform": "轉換",
"words.trending": "熱門",
"words.undo": "取消動作",
"words.unread": "未讀",
"words.user": "使用者",
-1
View File
@@ -401,7 +401,6 @@
"words.starred": "收藏",
"words.title": "標題",
"words.transform": "轉換",
"words.trending": "熱門",
"words.undo": "撤銷",
"words.unread": "未讀",
"words.user": "使用者",