Skip to content

Commit 6a51c8f

Browse files
committed
feat(mobile): optimize rsshub form screen
1 parent e88eb0f commit 6a51c8f

File tree

5 files changed

+47
-44
lines changed

5 files changed

+47
-44
lines changed

apps/desktop/layer/renderer/src/modules/discover/DiscoverFeedForm.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,7 @@ export const DiscoverFeedForm = ({
100100
rootClassName?: string
101101
}) => {
102102
const { t } = useTranslation()
103-
const keys = useMemo(
104-
() =>
105-
parseRegexpPathParams(route.path, {
106-
excludeNames: [
107-
"routeParams",
108-
"functionalFlag",
109-
"fulltext",
110-
"disableEmbed",
111-
"date",
112-
"language",
113-
"lang",
114-
"sort",
115-
],
116-
forceExcludeNames: routeParams ? ["routeParams"] : [],
117-
}),
118-
[route.path, routeParams],
119-
)
103+
const keys = useMemo(() => parseRegexpPathParams(route.path), [route.path])
120104

121105
const formPlaceholder = useMemo<Record<string, string>>(() => {
122106
if (!route.example) return {}

apps/mobile/src/components/ui/form/Select.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ export function Select<T>({
100100
}
101101

102102
return (
103-
<View className="flex-1 flex-row items-center">
103+
<View className="flex-1 flex-row items-center justify-between">
104104
<FormLabel className="pl-2" label={label} />
105-
<View className="flex-1" />
106-
107-
{Trigger}
105+
<View className="flex-1">{Trigger}</View>
108106
</View>
109107
)
110108
}

apps/mobile/src/modules/discover/FeedSummary.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export const FeedSummary = ({
7373
<Text className="text-text text-lg font-semibold" numberOfLines={1}>
7474
{item.feed?.title}
7575
</Text>
76-
<Text className="text-text text-sm leading-tight opacity-60">{item.feed?.url}</Text>
76+
<Text className="text-text text-sm leading-tight opacity-60" numberOfLines={1}>
77+
{item.feed?.url}
78+
</Text>
7779
</View>
7880
</View>
7981
{!simple && !!item.feed?.description && (

apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useNavigation } from "@/src/lib/navigation/hooks"
2727
import { useSetModalScreenOptions } from "@/src/lib/navigation/ScreenOptionsContext"
2828
import type { NavigationControllerView } from "@/src/lib/navigation/types"
2929
import { toast } from "@/src/lib/toast"
30+
import { FeedSummary } from "@/src/modules/discover/FeedSummary"
3031

3132
import { FollowScreen } from "./FollowScreen"
3233

@@ -64,23 +65,8 @@ export const RsshubFormScreen: NavigationControllerView<RsshubFormParams> = ({
6465
}
6566

6667
function FormImpl({ route, routePrefix, name }: RsshubFormParams) {
67-
const { name: routeName } = route
68-
const keys = useMemo(
69-
() =>
70-
parseRegexpPathParams(route.path, {
71-
excludeNames: [
72-
"routeParams",
73-
"functionalFlag",
74-
"fulltext",
75-
"disableEmbed",
76-
"date",
77-
"language",
78-
"lang",
79-
"sort",
80-
],
81-
}),
82-
[route.path],
83-
)
68+
const { name: routeName, topFeeds } = route
69+
const keys = useMemo(() => parseRegexpPathParams(route.path), [route.path])
8470

8571
const formPlaceholder = useMemo<Record<string, string>>(() => {
8672
if (!route.example) return {}
@@ -119,6 +105,16 @@ function FormImpl({ route, routePrefix, name }: RsshubFormParams) {
119105
// eslint-disable-next-line unicorn/prefer-structured-clone
120106
const nextErrors = JSON.parse(JSON.stringify(form.formState.errors))
121107

108+
const data = form.watch() as Record<string, string | undefined>
109+
const fullPath = useMemo(() => {
110+
try {
111+
return regexpPathToPath(route.path, data)
112+
} catch (err: unknown) {
113+
console.info((err as Error).message)
114+
return route.path
115+
}
116+
}, [route.path, data])
117+
122118
return (
123119
<FormProvider form={form}>
124120
<PortalProvider>
@@ -131,13 +127,16 @@ function FormImpl({ route, routePrefix, name }: RsshubFormParams) {
131127
routePrefix={routePrefix}
132128
errors={nextErrors}
133129
/>
130+
<Text className="text-secondary-label mx-4 mt-2 text-center text-sm">
131+
{`rsshub://${routePrefix}${fullPath}`}
132+
</Text>
134133
{keys.length === 0 && (
135-
<View className="bg-secondary-system-grouped-background mx-2 mt-2 gap-4 rounded-lg p-3">
134+
<View className="bg-secondary-system-grouped-background mx-2 mt-4 gap-4 rounded-lg p-3">
136135
<Text className="text-center text-base">This feed has no parameters.</Text>
137136
</View>
138137
)}
139138
{keys.length > 0 && (
140-
<View className="bg-secondary-system-grouped-background mx-2 mt-2 gap-4 rounded-lg px-3 py-6">
139+
<View className="bg-secondary-system-grouped-background mx-4 mt-4 gap-5 rounded-[10px] px-4 py-5">
141140
{keys.map((keyItem) => {
142141
const parameters = normalizeRSSHubParameters(route.parameters[keyItem.name]!)
143142

@@ -198,10 +197,17 @@ function FormImpl({ route, routePrefix, name }: RsshubFormParams) {
198197
})}
199198
</View>
200199
)}
200+
{!!topFeeds?.length && (
201+
<View className="bg-secondary-system-grouped-background mx-4 mt-4 rounded-[10px] py-1">
202+
{topFeeds.map((feed) => (
203+
<FeedSummary key={feed.id} item={{ feed }} simple className="px-4 py-2" />
204+
))}
205+
</View>
206+
)}
201207
<Maintainers maintainers={route.maintainers} />
202208

203209
{!!route.description && (
204-
<View className="mt-4 flex-1 p-4">
210+
<View className="mt-6 flex-1 px-8">
205211
<MarkdownNative value={route.description.replaceAll(":::", "")} />
206212
</View>
207213
)}
@@ -218,7 +224,7 @@ const Maintainers = ({ maintainers }: { maintainers?: string[] }) => {
218224
}
219225

220226
return (
221-
<View className="text-tertiary-label mx-4 mt-2 flex flex-row flex-wrap gap-x-1 text-sm">
227+
<View className="text-tertiary-label mx-8 mt-4 flex flex-row flex-wrap gap-x-1 text-sm">
222228
<Text className="text-secondary-label text-xs">
223229
This feed is provided by RSSHub, with credit to{" "}
224230
</Text>

packages/internal/utils/src/path-parser.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,20 @@ export const parseRegexpPathParams = (
110110
regexpPath: string,
111111
options?: ParseRegexpPathParamsOptions,
112112
) => {
113-
const { excludeNames = [], forceExcludeNames = [] } = options || {}
113+
const {
114+
excludeNames = [
115+
"routeParams",
116+
"functionalFlag",
117+
"fulltext",
118+
"disableEmbed",
119+
"embed",
120+
"date",
121+
"language",
122+
"lang",
123+
"sort",
124+
],
125+
forceExcludeNames = ["routeParams"],
126+
} = options || {}
114127
const transformedPath = transformUriPath(regexpPath)
115128
const { tokens } = parse(transformedPath)
116129

0 commit comments

Comments
 (0)