feat(i18n): discover categories and mark all read undo button (#1506)
* feat(discover): categories i18n * revert * update some translations * undo button * type safe
This commit is contained in:
@@ -1,101 +1,25 @@
|
||||
export const RSSHubCategoryOptions: {
|
||||
name: string
|
||||
value: string
|
||||
}[] = [
|
||||
{
|
||||
name: "All",
|
||||
value: "all",
|
||||
},
|
||||
{
|
||||
name: "Social Media",
|
||||
value: "social-media",
|
||||
},
|
||||
{
|
||||
name: "New Media",
|
||||
value: "new-media",
|
||||
},
|
||||
{
|
||||
name: "News",
|
||||
value: "traditional-media",
|
||||
},
|
||||
{
|
||||
name: "BBS",
|
||||
value: "bbs",
|
||||
},
|
||||
{
|
||||
name: "Blog",
|
||||
value: "blog",
|
||||
},
|
||||
{
|
||||
name: "Programming",
|
||||
value: "programming",
|
||||
},
|
||||
{
|
||||
name: "Design",
|
||||
value: "design",
|
||||
},
|
||||
{
|
||||
name: "Live",
|
||||
value: "live",
|
||||
},
|
||||
{
|
||||
name: "Multimedia",
|
||||
value: "multimedia",
|
||||
},
|
||||
{
|
||||
name: "Picture",
|
||||
value: "picture",
|
||||
},
|
||||
{
|
||||
name: "ACG",
|
||||
value: "anime",
|
||||
},
|
||||
{
|
||||
name: "Application Updates",
|
||||
value: "program-update",
|
||||
},
|
||||
{
|
||||
name: "University",
|
||||
value: "university",
|
||||
},
|
||||
{
|
||||
name: "Forecast",
|
||||
value: "forecast",
|
||||
},
|
||||
{
|
||||
name: "Travel",
|
||||
value: "travel",
|
||||
},
|
||||
{
|
||||
name: "Shopping",
|
||||
value: "shopping",
|
||||
},
|
||||
{
|
||||
name: "Gaming",
|
||||
value: "game",
|
||||
},
|
||||
{
|
||||
name: "Reading",
|
||||
value: "reading",
|
||||
},
|
||||
{
|
||||
name: "Government",
|
||||
value: "government",
|
||||
},
|
||||
{
|
||||
name: "Study",
|
||||
value: "study",
|
||||
},
|
||||
{
|
||||
name: "Scientific Journal",
|
||||
value: "journal",
|
||||
},
|
||||
{
|
||||
name: "Finance",
|
||||
value: "finance",
|
||||
},
|
||||
]
|
||||
|
||||
export const RSSHubCategoryMap: Record<string, string> = Object.fromEntries(
|
||||
RSSHubCategoryOptions.map((item) => [item.value, item.name]),
|
||||
)
|
||||
export const RSSHubCategories = [
|
||||
"all",
|
||||
"social-media",
|
||||
"new-media",
|
||||
"traditional-media",
|
||||
"bbs",
|
||||
"blog",
|
||||
"programming",
|
||||
"design",
|
||||
"live",
|
||||
"multimedia",
|
||||
"picture",
|
||||
"anime",
|
||||
"program-update",
|
||||
"university",
|
||||
"forecast",
|
||||
"travel",
|
||||
"shopping",
|
||||
"game",
|
||||
"reading",
|
||||
"government",
|
||||
"study",
|
||||
"journal",
|
||||
"finance",
|
||||
] as const
|
||||
|
||||
@@ -3,11 +3,12 @@ import clsx from "clsx"
|
||||
import { upperFirst } from "lodash-es"
|
||||
import type { FC } from "react"
|
||||
import { memo, useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
|
||||
import { RSSHubCategoryMap } from "./constants"
|
||||
import { RSSHubCategories } from "./constants"
|
||||
import { RecommendationContent } from "./recommendation-content"
|
||||
import styles from "./recommendations.module.css"
|
||||
import type { RSSHubRouteDeclaration } from "./types"
|
||||
@@ -19,6 +20,7 @@ interface RecommendationCardProps {
|
||||
}
|
||||
export const RecommendationCard: FC<RecommendationCardProps> = memo(
|
||||
({ data, routePrefix, setCategory }) => {
|
||||
const { t } = useTranslation()
|
||||
const { present } = useModalStack()
|
||||
|
||||
const { maintainers, categories } = useMemo(() => {
|
||||
@@ -36,7 +38,7 @@ export const RecommendationCard: FC<RecommendationCardProps> = memo(
|
||||
categories.delete("popular")
|
||||
return {
|
||||
maintainers: Array.from(maintainers),
|
||||
categories: Array.from(categories),
|
||||
categories: Array.from(categories) as typeof RSSHubCategories | string[],
|
||||
}
|
||||
}, [data])
|
||||
|
||||
@@ -130,17 +132,19 @@ export const RecommendationCard: FC<RecommendationCardProps> = memo(
|
||||
{categories.map((c) => (
|
||||
<button
|
||||
onClick={() => {
|
||||
if (!RSSHubCategoryMap[c]) return
|
||||
if (!RSSHubCategories.includes(c)) return
|
||||
setCategory(c)
|
||||
}}
|
||||
key={c}
|
||||
type="button"
|
||||
className={clsx(
|
||||
"cursor-pointer rounded bg-muted/50 px-1.5 duration-200 hover:bg-muted",
|
||||
!RSSHubCategoryMap[c] && "pointer-events-none opacity-50",
|
||||
!RSSHubCategories.includes(c) && "pointer-events-none opacity-50",
|
||||
)}
|
||||
>
|
||||
{RSSHubCategoryMap[c] || upperFirst(c)}
|
||||
{RSSHubCategories.includes(c)
|
||||
? t(`discover.category.${c as (typeof RSSHubCategories)[number]}`)
|
||||
: upperFirst(c)}
|
||||
</button>
|
||||
))}
|
||||
</span>
|
||||
|
||||
@@ -19,7 +19,7 @@ import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { Queries } from "~/queries"
|
||||
|
||||
import { RSSHubCategoryOptions } from "./constants"
|
||||
import { RSSHubCategories } from "./constants"
|
||||
import styles from "./recommendations.module.css"
|
||||
import { RecommendationCard } from "./recommendations-card"
|
||||
|
||||
@@ -35,7 +35,7 @@ const LanguageOptions = [
|
||||
] as const
|
||||
|
||||
type Language = (typeof LanguageOptions)[number]["value"]
|
||||
type DiscoverCategories = (typeof RSSHubCategoryOptions)[number]["value"]
|
||||
type DiscoverCategories = (typeof RSSHubCategories)[number] | string
|
||||
|
||||
const fetchRsshubPopular = (category: DiscoverCategories, lang: Language) => {
|
||||
return Queries.discover.rsshubCategory({
|
||||
@@ -166,13 +166,9 @@ export function Recommendations({
|
||||
>
|
||||
<Tabs value={category} onValueChange={handleCategoryChange}>
|
||||
<TabsList>
|
||||
{RSSHubCategoryOptions.map((category) => (
|
||||
<TabsTrigger
|
||||
data-value={category.value}
|
||||
key={category.value}
|
||||
value={category.value}
|
||||
>
|
||||
{category.name}
|
||||
{RSSHubCategories.map((category) => (
|
||||
<TabsTrigger data-value={category} key={category} value={category}>
|
||||
{t(`discover.category.${category}`)}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
|
||||
@@ -32,6 +32,7 @@ export const MarkAllReadWithOverlay = forwardRef<
|
||||
containerRef: React.RefObject<HTMLDivElement>
|
||||
}
|
||||
>(({ filter, className, which = "all", shortcut, containerRef }, ref) => {
|
||||
const { t } = useTranslation()
|
||||
const { t: commonT } = useTranslation("common")
|
||||
|
||||
const [show, setShow] = useState(false)
|
||||
@@ -63,7 +64,7 @@ export const MarkAllReadWithOverlay = forwardRef<
|
||||
action: {
|
||||
label: (
|
||||
<span className="flex items-center gap-1">
|
||||
Undo
|
||||
{t("mark_all_read_button.undo")}
|
||||
<Kbd className="inline-flex items-center border border-border bg-transparent dark:text-white">
|
||||
Meta+Z
|
||||
</Kbd>
|
||||
|
||||
@@ -39,6 +39,29 @@
|
||||
"boost.feed_being_boosted": "Feed being boosted",
|
||||
"boost.remaining_boosts_to_level_up": "{{remainingBoostsToLevelUp}} more boost will unlock the next level of benefits!",
|
||||
"discover.any_url_or_keyword": "Any URL or Keyword",
|
||||
"discover.category.all": "All",
|
||||
"discover.category.anime": "ACG",
|
||||
"discover.category.bbs": "BBS",
|
||||
"discover.category.blog": "Blog",
|
||||
"discover.category.design": "Design",
|
||||
"discover.category.finance": "Finance",
|
||||
"discover.category.forecast": "Forecast",
|
||||
"discover.category.game": "Gaming",
|
||||
"discover.category.government": "Government",
|
||||
"discover.category.journal": "Scientific Journal",
|
||||
"discover.category.live": "Live",
|
||||
"discover.category.multimedia": "Multimedia",
|
||||
"discover.category.new-media": "New Media",
|
||||
"discover.category.picture": "Picture",
|
||||
"discover.category.program-update": "Application Updates",
|
||||
"discover.category.programming": "Programming",
|
||||
"discover.category.reading": "Reading",
|
||||
"discover.category.shopping": "Shopping",
|
||||
"discover.category.social-media": "Social Media",
|
||||
"discover.category.study": "Study",
|
||||
"discover.category.traditional-media": "News",
|
||||
"discover.category.travel": "Travel",
|
||||
"discover.category.university": "University",
|
||||
"discover.default_option": " (default)",
|
||||
"discover.feed_description": "The description of this feed is as follows, and you can fill out the parameter form with the relevant information.",
|
||||
"discover.feed_maintainers": "This feed is provided by RSSHub, with credit to <maintainers />",
|
||||
|
||||
@@ -39,6 +39,29 @@
|
||||
"boost.feed_being_boosted": "已助力",
|
||||
"boost.remaining_boosts_to_level_up": "再助力 {{remainingBoostsToLevelUp}} 次即可解锁下一级福利!",
|
||||
"discover.any_url_or_keyword": "任意链接或关键词",
|
||||
"discover.category.all": "全部",
|
||||
"discover.category.anime": "二次元",
|
||||
"discover.category.bbs": "论坛",
|
||||
"discover.category.blog": "博客",
|
||||
"discover.category.design": "设计",
|
||||
"discover.category.finance": "金融",
|
||||
"discover.category.forecast": "预报预警",
|
||||
"discover.category.game": "游戏",
|
||||
"discover.category.government": "政务消息",
|
||||
"discover.category.journal": "科学期刊",
|
||||
"discover.category.live": "直播",
|
||||
"discover.category.multimedia": "音视频",
|
||||
"discover.category.new-media": "新媒体",
|
||||
"discover.category.picture": "图片",
|
||||
"discover.category.program-update": "程序更新",
|
||||
"discover.category.programming": "编程",
|
||||
"discover.category.reading": "阅读",
|
||||
"discover.category.shopping": "购物",
|
||||
"discover.category.social-media": "社交媒体",
|
||||
"discover.category.study": "学习",
|
||||
"discover.category.traditional-media": "传统媒体",
|
||||
"discover.category.travel": "出行旅游",
|
||||
"discover.category.university": "大学通知",
|
||||
"discover.default_option": " (默认)",
|
||||
"discover.feed_description": "根据描述完善目标订阅源的相关信息",
|
||||
"discover.feed_maintainers": "由 RSSHub 提供,感谢贡献者 <maintainers />",
|
||||
|
||||
Reference in New Issue
Block a user