Skip to content

Commit

Permalink
feat(rn): init follow feed modal
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Jan 3, 2025
1 parent 8583210 commit 1e8196a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
6 changes: 6 additions & 0 deletions apps/mobile/src/screens/(modal)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export default function ModalLayout() {
title: "RSSHub Form",
}}
/>
<Stack.Screen
name="follow"
options={{
title: "Follow",
}}
/>
</Stack>
)
}
11 changes: 11 additions & 0 deletions apps/mobile/src/screens/(modal)/follow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useLocalSearchParams } from "expo-router"
import { Text, View } from "react-native"

export default function Follow() {
const { url } = useLocalSearchParams()
return (
<View>
<Text className="text-text">{url}</Text>
</View>
)
}
67 changes: 60 additions & 7 deletions apps/mobile/src/screens/(modal)/rsshub-form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { RSSHubParameter, RSSHubParameterObject, RSSHubRoute } from "@follow/models/src/rsshub"
import { parseFullPathParams, parseRegexpPathParams, withOpacity } from "@follow/utils"
import {
MissingOptionalParamError,
parseFullPathParams,
parseRegexpPathParams,
regexpPathToPath,
withOpacity,
} from "@follow/utils"
import { PortalProvider } from "@gorhom/portal"
import { zodResolver } from "@hookform/resolvers/zod"
import { router, Stack, useLocalSearchParams } from "expo-router"
Expand Down Expand Up @@ -224,7 +230,7 @@ const ScreenOptions = memo(({ name, routeName, route, routePrefix }: ScreenOptio
headerLeft: ModalHeaderCloseButton,
headerRight: () => (
<FormProvider form={form}>
<ModalHeaderSubmitButton />
<ModalHeaderSubmitButton routePrefix={routePrefix} route={route} />
</FormProvider>
),

Expand All @@ -244,15 +250,62 @@ const Title = ({ name, routeName, route, routePrefix }: ScreenOptionsProps) => {
)
}

const ModalHeaderSubmitButton = () => {
return <ModalHeaderSubmitButtonImpl />
type ModalHeaderSubmitButtonProps = {
routePrefix: string
route: string
}
const ModalHeaderSubmitButton = ({ routePrefix, route }: ModalHeaderSubmitButtonProps) => {
return <ModalHeaderSubmitButtonImpl routePrefix={routePrefix} route={route} />
}
const ModalHeaderSubmitButtonImpl = () => {

const routeParamsKeyPrefix = "route-params-"

const ModalHeaderSubmitButtonImpl = ({ routePrefix, route }: ModalHeaderSubmitButtonProps) => {
const form = useFormContext()
const label = useColor("label")
const { isValid } = form.formState
const submit = form.handleSubmit((data) => {
void data
const submit = form.handleSubmit((_data) => {
const data = Object.fromEntries(
Object.entries(_data).filter(([key]) => !key.startsWith(routeParamsKeyPrefix)),
)

try {
const routeParamsPath = encodeURIComponent(
Object.entries(_data)
.filter(([key, value]) => key.startsWith(routeParamsKeyPrefix) && value)
.map(([key, value]) => [key.slice(routeParamsKeyPrefix.length), value])
.map(([key, value]) => `${key}=${value}`)
.join("&"),
)

const fillRegexpPath = regexpPathToPath(
routeParamsPath ? route.slice(0, route.indexOf("/:routeParams")) : route,
data,
)
const url = `rsshub://${routePrefix}${fillRegexpPath}`

const finalUrl = routeParamsPath ? `${url}/${routeParamsPath}` : url

if (router.canDismiss()) {
router.dismiss()
}
requestAnimationFrame(() => {
router.push({
pathname: "/follow",
params: {
url: finalUrl,
},
})
})
} catch (err: unknown) {
if (err instanceof MissingOptionalParamError) {
// toast.error(err.message)
// const idx = keys.findIndex((item) => item.name === err.param)
// form.setFocus(keys[idx === 0 ? 0 : idx - 1].name, {
// shouldSelect: true,
// })
}
}
})

return (
Expand Down

0 comments on commit 1e8196a

Please sign in to comment.