From 6a51c8f341ef898ea2c9109c970dd6d9d58b54b0 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 5 Jun 2025 18:40:12 +0800 Subject: [PATCH] feat(mobile): optimize rsshub form screen --- .../src/modules/discover/DiscoverFeedForm.tsx | 18 +------ apps/mobile/src/components/ui/form/Select.tsx | 6 +-- .../src/modules/discover/FeedSummary.tsx | 4 +- .../src/screens/(modal)/RsshubFormScreen.tsx | 48 +++++++++++-------- packages/internal/utils/src/path-parser.ts | 15 +++++- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/discover/DiscoverFeedForm.tsx b/apps/desktop/layer/renderer/src/modules/discover/DiscoverFeedForm.tsx index b1530ae26..7b3dc39cb 100644 --- a/apps/desktop/layer/renderer/src/modules/discover/DiscoverFeedForm.tsx +++ b/apps/desktop/layer/renderer/src/modules/discover/DiscoverFeedForm.tsx @@ -100,23 +100,7 @@ export const DiscoverFeedForm = ({ rootClassName?: string }) => { const { t } = useTranslation() - const keys = useMemo( - () => - parseRegexpPathParams(route.path, { - excludeNames: [ - "routeParams", - "functionalFlag", - "fulltext", - "disableEmbed", - "date", - "language", - "lang", - "sort", - ], - forceExcludeNames: routeParams ? ["routeParams"] : [], - }), - [route.path, routeParams], - ) + const keys = useMemo(() => parseRegexpPathParams(route.path), [route.path]) const formPlaceholder = useMemo>(() => { if (!route.example) return {} diff --git a/apps/mobile/src/components/ui/form/Select.tsx b/apps/mobile/src/components/ui/form/Select.tsx index d73955b98..15197a734 100644 --- a/apps/mobile/src/components/ui/form/Select.tsx +++ b/apps/mobile/src/components/ui/form/Select.tsx @@ -100,11 +100,9 @@ export function Select({ } return ( - + - - - {Trigger} + {Trigger} ) } diff --git a/apps/mobile/src/modules/discover/FeedSummary.tsx b/apps/mobile/src/modules/discover/FeedSummary.tsx index a8053761e..7817a8de2 100644 --- a/apps/mobile/src/modules/discover/FeedSummary.tsx +++ b/apps/mobile/src/modules/discover/FeedSummary.tsx @@ -73,7 +73,9 @@ export const FeedSummary = ({ {item.feed?.title} - {item.feed?.url} + + {item.feed?.url} + {!simple && !!item.feed?.description && ( diff --git a/apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx b/apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx index 168b151b4..4568bb61b 100644 --- a/apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx +++ b/apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx @@ -27,6 +27,7 @@ import { useNavigation } from "@/src/lib/navigation/hooks" import { useSetModalScreenOptions } from "@/src/lib/navigation/ScreenOptionsContext" import type { NavigationControllerView } from "@/src/lib/navigation/types" import { toast } from "@/src/lib/toast" +import { FeedSummary } from "@/src/modules/discover/FeedSummary" import { FollowScreen } from "./FollowScreen" @@ -64,23 +65,8 @@ export const RsshubFormScreen: NavigationControllerView = ({ } function FormImpl({ route, routePrefix, name }: RsshubFormParams) { - const { name: routeName } = route - const keys = useMemo( - () => - parseRegexpPathParams(route.path, { - excludeNames: [ - "routeParams", - "functionalFlag", - "fulltext", - "disableEmbed", - "date", - "language", - "lang", - "sort", - ], - }), - [route.path], - ) + const { name: routeName, topFeeds } = route + const keys = useMemo(() => parseRegexpPathParams(route.path), [route.path]) const formPlaceholder = useMemo>(() => { if (!route.example) return {} @@ -119,6 +105,16 @@ function FormImpl({ route, routePrefix, name }: RsshubFormParams) { // eslint-disable-next-line unicorn/prefer-structured-clone const nextErrors = JSON.parse(JSON.stringify(form.formState.errors)) + const data = form.watch() as Record + const fullPath = useMemo(() => { + try { + return regexpPathToPath(route.path, data) + } catch (err: unknown) { + console.info((err as Error).message) + return route.path + } + }, [route.path, data]) + return ( @@ -131,13 +127,16 @@ function FormImpl({ route, routePrefix, name }: RsshubFormParams) { routePrefix={routePrefix} errors={nextErrors} /> + + {`rsshub://${routePrefix}${fullPath}`} + {keys.length === 0 && ( - + This feed has no parameters. )} {keys.length > 0 && ( - + {keys.map((keyItem) => { const parameters = normalizeRSSHubParameters(route.parameters[keyItem.name]!) @@ -198,10 +197,17 @@ function FormImpl({ route, routePrefix, name }: RsshubFormParams) { })} )} + {!!topFeeds?.length && ( + + {topFeeds.map((feed) => ( + + ))} + + )} {!!route.description && ( - + )} @@ -218,7 +224,7 @@ const Maintainers = ({ maintainers }: { maintainers?: string[] }) => { } return ( - + This feed is provided by RSSHub, with credit to{" "} diff --git a/packages/internal/utils/src/path-parser.ts b/packages/internal/utils/src/path-parser.ts index e7cc51185..fb98d19a2 100644 --- a/packages/internal/utils/src/path-parser.ts +++ b/packages/internal/utils/src/path-parser.ts @@ -110,7 +110,20 @@ export const parseRegexpPathParams = ( regexpPath: string, options?: ParseRegexpPathParamsOptions, ) => { - const { excludeNames = [], forceExcludeNames = [] } = options || {} + const { + excludeNames = [ + "routeParams", + "functionalFlag", + "fulltext", + "disableEmbed", + "embed", + "date", + "language", + "lang", + "sort", + ], + forceExcludeNames = ["routeParams"], + } = options || {} const transformedPath = transformUriPath(regexpPath) const { tokens } = parse(transformedPath)