Skip to content

Commit

Permalink
feat(i18n): discover categories and mark all read undo button (#1506)
Browse files Browse the repository at this point in the history
* feat(discover): categories i18n

* revert

* update some translations

* undo button

* type safe
  • Loading branch information
ericyzhu authored Nov 11, 2024
1 parent 01b499d commit 06bdf6c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 116 deletions.
126 changes: 25 additions & 101 deletions apps/renderer/src/modules/discover/constants.ts
Original file line number Diff line number Diff line change
@@ -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
14 changes: 9 additions & 5 deletions apps/renderer/src/modules/discover/recommendations-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(() => {
Expand All @@ -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])

Expand Down Expand Up @@ -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>
Expand Down
14 changes: 5 additions & 9 deletions apps/renderer/src/modules/discover/recommendations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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({
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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>
Expand Down
23 changes: 23 additions & 0 deletions locales/app/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 />",
Expand Down
23 changes: 23 additions & 0 deletions locales/app/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 />",
Expand Down

0 comments on commit 06bdf6c

Please sign in to comment.