* init Signed-off-by: Innei <i@innei.in> * feat: feed column Signed-off-by: Innei <i@innei.in> * feat: float bar Signed-off-by: Innei <tukon479@gmail.com> * feat: profile button Signed-off-by: Innei <tukon479@gmail.com> * chore: comment Signed-off-by: Innei <tukon479@gmail.com> * feat: layout Signed-off-by: Innei <tukon479@gmail.com> * feat: split mobile entry content Signed-off-by: Innei <tukon479@gmail.com> * feat: add history stack Signed-off-by: Innei <tukon479@gmail.com> * feat: return back Signed-off-by: Innei <tukon479@gmail.com> * fix: return back position Signed-off-by: Innei <tukon479@gmail.com> * feat: entry list header Signed-off-by: Innei <tukon479@gmail.com> * feat: sync selector Signed-off-by: Innei <tukon479@gmail.com> * feat: modal stack mobile Signed-off-by: Innei <tukon479@gmail.com> * fix: modal selector Signed-off-by: Innei <tukon479@gmail.com> * cleanup Signed-off-by: Innei <tukon479@gmail.com> * fix: sheet and optimize entry readers Signed-off-by: Innei <tukon479@gmail.com> * fix: scroller Signed-off-by: Innei <tukon479@gmail.com> * feat: entry contents Signed-off-by: Innei <tukon479@gmail.com> * feat: entry content Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * feat: user profile sheet Signed-off-by: Innei <tukon479@gmail.com> * fix: entry content header Signed-off-by: Innei <tukon479@gmail.com> * fix: entry header Signed-off-by: Innei <tukon479@gmail.com> * chore: auto-fix linting and formatting issues * fix: return back Signed-off-by: Innei <tukon479@gmail.com> * feat: image view Signed-off-by: Innei <tukon479@gmail.com> * feat: audio Signed-off-by: Innei <tukon479@gmail.com> * feat: inline player Signed-off-by: Innei <tukon479@gmail.com> * feat: pull to refresh Signed-off-by: Innei <tukon479@gmail.com> * cleanup Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * chore: auto-fix linting and formatting issues * chore: fix import, remove no support display * chore: auto-fix linting and formatting issues * feat: achievement modal in mobile Signed-off-by: Innei <tukon479@gmail.com> * fix: subview mobile Signed-off-by: Innei <tukon479@gmail.com> * feat: power Signed-off-by: Innei <tukon479@gmail.com> * feat: wallet mobile design Signed-off-by: Innei <tukon479@gmail.com> * feat: pwa support (#1575) Co-authored-by: hyoban <hyoban@users.noreply.github.com> * chore: auto-fix linting and formatting issues * fix import * discover * fix: border color Signed-off-by: Innei <tukon479@gmail.com> * fix: modal async Signed-off-by: Innei <tukon479@gmail.com> * feat: mobile setting Signed-off-by: Innei <tukon479@gmail.com> * fix: entry header width Signed-off-by: Innei <tukon479@gmail.com> * fix: remove unused hide filter * feat: settings Signed-off-by: Innei <tukon479@gmail.com> * feat: setting done Signed-off-by: Innei <tukon479@gmail.com> * action card * fix discover feed form * popular filter * inbox table * fix: picture masonry pull to refresh Signed-off-by: Innei <tukon479@gmail.com> * fix: scroll element Signed-off-by: Innei <tukon479@gmail.com> * fix: radio in mobile Signed-off-by: Innei <tukon479@gmail.com> * feat: to scientific notation Signed-off-by: Innei <tukon479@gmail.com> * fix: login Signed-off-by: Innei <tukon479@gmail.com> * ResponsiveSelect for action card * chore: remove theme color Signed-off-by: Innei <tukon479@gmail.com> * type check * type check * fix: setting import circular Signed-off-by: Innei <tukon479@gmail.com> * refactor: remove hijack pushState Signed-off-by: Innei <tukon479@gmail.com> * fix: float bar Signed-off-by: Innei <tukon479@gmail.com> * fix: scroll end trigger Signed-off-by: Innei <tukon479@gmail.com> * fix: dark theme color Signed-off-by: Innei <tukon479@gmail.com> * fix: overscroll-behavior only in destop Signed-off-by: Innei <tukon479@gmail.com> * fix: ux Signed-off-by: Innei <tukon479@gmail.com> * fix: color Signed-off-by: Innei <tukon479@gmail.com> * fix: list scroll area Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * merge * update * update favicon link * fix: reload prompt on mobile * test Signed-off-by: Innei <i@innei.in> * test Signed-off-by: Innei <i@innei.in> * fix: ios Signed-off-by: Innei <i@innei.in> * try patch precaching * try * try * build * try * try * feat: ctx menu on safari Signed-off-by: Innei <tukon479@gmail.com> * try * clear timeout Signed-off-by: Innei <tukon479@gmail.com> * try * fix * deny og * fix patch * pre cache exclude * feat: add all Signed-off-by: Innei <tukon479@gmail.com> * i18n Signed-off-by: Innei <tukon479@gmail.com> * feat: slide Signed-off-by: Innei <tukon479@gmail.com> * feat: ico Signed-off-by: Innei <tukon479@gmail.com> * fix: build Signed-off-by: Innei <tukon479@gmail.com> * test network first Signed-off-by: Innei <tukon479@gmail.com> * test Signed-off-by: Innei <tukon479@gmail.com> * fix: icon padding * test Signed-off-by: Innei <tukon479@gmail.com> * use react-ios-pwa-prompt * fix: icon path * update * fix: prompt Signed-off-by: Innei <tukon479@gmail.com> * feat: redesign toc Signed-off-by: Innei <tukon479@gmail.com> * ctx Signed-off-by: Innei <tukon479@gmail.com> * ready to prod Signed-off-by: Innei <tukon479@gmail.com> * feat: startup screen Signed-off-by: Innei <tukon479@gmail.com> * feat: floatbar Signed-off-by: Innei <tukon479@gmail.com> * fix: switch view Signed-off-by: Innei <tukon479@gmail.com> * fix: keep scroll map Signed-off-by: Innei <tukon479@gmail.com> * enable hoverOnlyWhenSupported * fix: count Signed-off-by: Innei <tukon479@gmail.com> * fix: hoverOnlyWhenSupported only in web Signed-off-by: Innei <tukon479@gmail.com> * fix Signed-off-by: Innei <tukon479@gmail.com> * chore: auto-fix linting and formatting issues --------- Signed-off-by: Innei <i@innei.in> Signed-off-by: Innei <tukon479@gmail.com> Co-authored-by: Innei <Innei@users.noreply.github.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: hyoban <hyoban@users.noreply.github.com> Co-authored-by: lawvs <18554747+lawvs@users.noreply.github.com> Co-authored-by: lawvs <lawvs@users.noreply.github.com>
198 lines
5.7 KiB
TypeScript
198 lines
5.7 KiB
TypeScript
import { LoadingCircle } from "@follow/components/ui/loading/index.js"
|
|
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
|
import { ResponsiveSelect } from "@follow/components/ui/select/responsive.js"
|
|
import { Tabs, TabsList, TabsTrigger } from "@follow/components/ui/tabs/index.js"
|
|
import { cn, isASCII } from "@follow/utils/utils"
|
|
import { keepPreviousData } from "@tanstack/react-query"
|
|
import { useMemo, useRef, useState } from "react"
|
|
import { flushSync } from "react-dom"
|
|
import { useTranslation } from "react-i18next"
|
|
import { useEventCallback } from "usehooks-ts"
|
|
|
|
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
|
import { useAuthQuery } from "~/hooks/common"
|
|
import { Queries } from "~/queries"
|
|
|
|
import { RSSHubCategories } from "./constants"
|
|
import styles from "./recommendations.module.css"
|
|
import { RecommendationCard } from "./recommendations-card"
|
|
|
|
const LanguageOptions = [
|
|
{
|
|
label: "All",
|
|
value: "all",
|
|
},
|
|
{
|
|
label: "English",
|
|
value: "en",
|
|
},
|
|
{
|
|
label: "中文",
|
|
value: "zh-CN",
|
|
},
|
|
] as const
|
|
|
|
type Language = (typeof LanguageOptions)[number]["value"]
|
|
type DiscoverCategories = (typeof RSSHubCategories)[number] | string
|
|
|
|
const fetchRsshubPopular = (category: DiscoverCategories, lang: Language) => {
|
|
return Queries.discover.rsshubCategory({
|
|
category: "popular",
|
|
categories: category === "all" ? "popular" : `popular,${category}`,
|
|
lang,
|
|
})
|
|
}
|
|
export function Recommendations({
|
|
hideTitle,
|
|
className,
|
|
headerClassName,
|
|
}: {
|
|
hideTitle?: boolean
|
|
className?: string
|
|
headerClassName?: string
|
|
}) {
|
|
const { t } = useTranslation()
|
|
const lang = useGeneralSettingKey("language")
|
|
|
|
const defaultLang = !lang || ["zh-CN", "zh-HK", "zh-TW"].includes(lang) ? "all" : "en"
|
|
const [category, setCategory] = useState<DiscoverCategories>("all")
|
|
const [selectedLang, setSelectedLang] = useState<Language>(defaultLang)
|
|
|
|
const rsshubPopular = useAuthQuery(fetchRsshubPopular(category, selectedLang), {
|
|
meta: {
|
|
persist: true,
|
|
},
|
|
placeholderData: keepPreviousData,
|
|
})
|
|
|
|
const { data, isLoading, isFetching } = rsshubPopular
|
|
|
|
const keys = useMemo(() => {
|
|
if (!data) {
|
|
return []
|
|
}
|
|
return Object.keys(data).sort((a, b) => {
|
|
const aname = data[a].name
|
|
const bname = data[b].name
|
|
|
|
const aRouteName = data[a].routes[Object.keys(data[a].routes)[0]].name
|
|
const bRouteName = data[b].routes[Object.keys(data[b].routes)[0]].name
|
|
|
|
const ia = isASCII(aname) && isASCII(aRouteName)
|
|
const ib = isASCII(bname) && isASCII(bRouteName)
|
|
|
|
if (ia && ib) {
|
|
return aname.toLowerCase() < bname.toLowerCase() ? -1 : 1
|
|
} else if (ia || ib) {
|
|
return ia > ib ? -1 : 1
|
|
} else {
|
|
return 0
|
|
}
|
|
})
|
|
}, [data])
|
|
|
|
const handleCategoryChange = (value: DiscoverCategories) => {
|
|
flushSync(() => {
|
|
setCategory(value)
|
|
})
|
|
rsshubPopular.refetch()
|
|
}
|
|
|
|
const handleLangChange = (value: string) => {
|
|
flushSync(() => {
|
|
setSelectedLang(value as Language)
|
|
})
|
|
rsshubPopular.refetch()
|
|
}
|
|
|
|
const tabRef = useRef<HTMLDivElement>(null)
|
|
const handleChangeCategoryAndJumpTo = useEventCallback((category: DiscoverCategories) => {
|
|
handleCategoryChange(category)
|
|
|
|
if (tabRef.current) {
|
|
const tab = tabRef.current.querySelector(`[data-value="${category}"]`)
|
|
if (tab) {
|
|
const tabRect = tab.getBoundingClientRect()
|
|
const containerRect = tabRef.current.getBoundingClientRect()
|
|
const scrollLeft =
|
|
tabRect.left -
|
|
containerRect.left +
|
|
tabRef.current.scrollLeft -
|
|
(containerRect.width - tabRect.width) / 2
|
|
|
|
tabRef.current.scrollTo({ left: scrollLeft, behavior: "smooth" })
|
|
}
|
|
}
|
|
})
|
|
|
|
if (isLoading) {
|
|
return null
|
|
}
|
|
|
|
if (!data) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div className={cn(!hideTitle && "mt-8 w-full max-w-[1200px]")}>
|
|
{!hideTitle && (
|
|
<div className="relative text-center text-lg font-bold">
|
|
<span>{t("discover.popular")}</span>
|
|
|
|
{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>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
<div
|
|
className={cn(
|
|
"z-[9] my-3 flex w-full flex-col items-end gap-4 bg-theme-background sm:flex-row sm:items-center",
|
|
headerClassName,
|
|
)}
|
|
>
|
|
<ScrollArea.ScrollArea
|
|
ref={tabRef}
|
|
orientation="horizontal"
|
|
rootClassName="grow min-w-0 max-w-full overflow-visible"
|
|
scrollbarClassName="-mb-3 z-[100]"
|
|
>
|
|
<Tabs value={category} onValueChange={handleCategoryChange}>
|
|
<TabsList>
|
|
{RSSHubCategories.map((category) => (
|
|
<TabsTrigger data-value={category} key={category} value={category}>
|
|
{t(`discover.category.${category}`)}
|
|
</TabsTrigger>
|
|
))}
|
|
</TabsList>
|
|
</Tabs>
|
|
</ScrollArea.ScrollArea>
|
|
|
|
<ResponsiveSelect
|
|
value={selectedLang}
|
|
onValueChange={handleLangChange}
|
|
triggerClassName="w-32"
|
|
size="sm"
|
|
items={LanguageOptions as any}
|
|
/>
|
|
</div>
|
|
|
|
<div className={cn(styles["recommendations-grid"], "mt-6", className)}>
|
|
{keys.map((key) => (
|
|
<RecommendationCard
|
|
key={key}
|
|
data={data[key]}
|
|
routePrefix={key}
|
|
setCategory={handleChangeCategoryAndJumpTo}
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|