From 912ef59f75a0309cba81b2fbce6764eed944936e Mon Sep 17 00:00:00 2001 From: Innei Date: Sat, 21 Sep 2024 22:14:49 +0800 Subject: [PATCH] refactor: extract `ViewSelectorRadioGroup` Signed-off-by: Innei --- .../src/modules/discover/feed-form.tsx | 41 ++--------- .../src/modules/settings/tabs/lists.tsx | 73 +++++++------------ .../modules/shared/ViewSelectorRadioGroup.tsx | 46 ++++++++++++ locales/common/en.json | 3 + 4 files changed, 84 insertions(+), 79 deletions(-) create mode 100644 apps/renderer/src/modules/shared/ViewSelectorRadioGroup.tsx diff --git a/apps/renderer/src/modules/discover/feed-form.tsx b/apps/renderer/src/modules/discover/feed-form.tsx index 3827c0705..d271ecc1a 100644 --- a/apps/renderer/src/modules/discover/feed-form.tsx +++ b/apps/renderer/src/modules/discover/feed-form.tsx @@ -24,7 +24,6 @@ import { Input } from "~/components/ui/input" import { LoadingCircle } from "~/components/ui/loading" import { useCurrentModal } from "~/components/ui/modal" import { Switch } from "~/components/ui/switch" -import { views } from "~/constants" import { useAuthQuery, useI18n } from "~/hooks/common" import { apiClient } from "~/lib/api-fetch" import { tipcClient } from "~/lib/client" @@ -38,6 +37,8 @@ import { useFeedByIdOrUrl } from "~/store/feed" import { useSubscriptionByFeedId } from "~/store/subscription" import { feedUnreadActions } from "~/store/unread" +import { ViewSelectorRadioGroup } from "../shared/ViewSelectorRadioGroup" + const formSchema = z.object({ view: z.string(), category: z.string().nullable().optional(), @@ -271,38 +272,12 @@ const FeedInnerForm = ({ render={() => ( {t("feed_form.view")} - - - {views.map((view) => ( -
- - -
- ))} -
-
+ +
)} diff --git a/apps/renderer/src/modules/settings/tabs/lists.tsx b/apps/renderer/src/modules/settings/tabs/lists.tsx index 5245cc9f9..9d41c5e2b 100644 --- a/apps/renderer/src/modules/settings/tabs/lists.tsx +++ b/apps/renderer/src/modules/settings/tabs/lists.tsx @@ -10,7 +10,6 @@ import { z } from "zod" import { FeedCertification } from "~/components/feed-certification" import { Avatar, AvatarImage } from "~/components/ui/avatar" import { Button } from "~/components/ui/button" -import { Card, CardHeader } from "~/components/ui/card" import { Divider } from "~/components/ui/divider" import { Form, @@ -34,16 +33,18 @@ import { TableRow, } from "~/components/ui/table" import { views } from "~/constants" -import { useAuthQuery } from "~/hooks/common" +import { useAuthQuery, useI18n } from "~/hooks/common" import { apiClient } from "~/lib/api-fetch" import { cn } from "~/lib/utils" import type { ListModel } from "~/models" +import { ViewSelectorRadioGroup } from "~/modules/shared/ViewSelectorRadioGroup" import { Queries } from "~/queries" import { feedActions, useFeedById } from "~/store/feed" export const SettingLists = () => { - const { t: appT } = useTranslation() - const { t } = useTranslation("settings") + // const { t: appT } = useTranslation() + const t = useI18n() + // const { t } = useTranslation("settings") const listList = useAuthQuery(Queries.lists.list()) const { present } = useModalStack() @@ -51,18 +52,18 @@ export const SettingLists = () => { return (
-

{t("lists.info")}

+

{t.settings("lists.info")}

@@ -72,19 +73,19 @@ export const SettingLists = () => { - {t("lists.title")} + {t.settings("lists.title")} - {t("lists.view")} + {t.settings("lists.view")} - {t("lists.fee")} + {t.settings("lists.fee")} - {t("lists.feeds")} + {t.settings("lists.feeds")} - {t("lists.edit")} + {t.settings("lists.edit")} @@ -110,7 +111,7 @@ export const SettingLists = () => { {views[row.view].icon} - {appT(views[row.view].name)} + {t(views[row.view].name)}
@@ -124,7 +125,7 @@ export const SettingLists = () => { variant="ghost" onClick={() => { present({ - title: t("lists.feeds.manage"), + title: t.settings("lists.feeds.manage"), content: () => , }) }} @@ -137,7 +138,7 @@ export const SettingLists = () => { variant="ghost" onClick={() => { present({ - title: t("lists.edit"), + title: t.settings("lists.edit"), content: ({ dismiss }) => ( ), @@ -155,7 +156,7 @@ export const SettingLists = () => { ) : (
-

{t("lists.noLists")}

+

{t.settings("lists.noLists")}

)} @@ -173,9 +174,10 @@ const formSchema = z.object({ }) const ListCreationModalContent = ({ dismiss, id }: { dismiss: () => void; id?: string }) => { - const { t: appT } = useTranslation() const { t } = useTranslation("settings") + const appT = useI18n() + const list = useFeedById(id) as ListModel const form = useForm>({ @@ -224,7 +226,7 @@ const ListCreationModalContent = ({ dismiss, id }: { dismiss: () => void; id?: s return (
- + void; id?: s render={() => ( {t("lists.view")} - - - {views.map((view) => ( -
- - -
- ))} -
-
+ +
)} @@ -338,9 +317,11 @@ const ListCreationModalContent = ({ dismiss, id }: { dismiss: () => void; id?: s )} /> - +
+ +
) diff --git a/apps/renderer/src/modules/shared/ViewSelectorRadioGroup.tsx b/apps/renderer/src/modules/shared/ViewSelectorRadioGroup.tsx new file mode 100644 index 000000000..b53008c38 --- /dev/null +++ b/apps/renderer/src/modules/shared/ViewSelectorRadioGroup.tsx @@ -0,0 +1,46 @@ +import { forwardRef } from "react" + +import { Card, CardHeader } from "~/components/ui/card" +import { views } from "~/constants" +import { useI18n } from "~/hooks/common" +import { cn } from "~/lib/utils" + +export const ViewSelectorRadioGroup = forwardRef< + HTMLInputElement, + React.InputHTMLAttributes +>(({ className, ...rest }, ref) => { + const t = useI18n() + + return ( + + + {views.map((view) => ( +
+ + +
+ ))} +
+
+ ) +}) diff --git a/locales/common/en.json b/locales/common/en.json index cac928eec..f6a497fa7 100644 --- a/locales/common/en.json +++ b/locales/common/en.json @@ -12,6 +12,7 @@ "tips.load-lng-error": "Failed to load language pack", "words.back": "Back", "words.copy": "Copy", + "words.create": "Create", "words.edit": "Edit", "words.entry": "Entry", "words.id": "ID", @@ -25,5 +26,7 @@ "words.result_one": "result", "words.result_other": "results", "words.space": " ", + "words.submit": "Submit", + "words.update": "Update", "words.which.all": "All" }