feat(modal): enhance Follow modal with improved navigation and loading state

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-01-07 17:02:11 +08:00
parent 265023126e
commit cf31c0f5fa
3 changed files with 57 additions and 13 deletions
@@ -1,9 +1,10 @@
import { withOpacity } from "@follow/utils"
import { router } from "expo-router"
import { router, useNavigation } from "expo-router"
import { TouchableOpacity } from "react-native"
import { CheckLineIcon } from "@/src/icons/check_line"
import { CloseCuteReIcon } from "@/src/icons/close_cute_re"
import { MingcuteLeftLineIcon } from "@/src/icons/mingcute_left_line"
import { useColor } from "@/src/theme/colors"
import { RotateableLoading } from "./RotateableLoading"
@@ -14,9 +15,20 @@ export const ModalHeaderCloseButton = () => {
const ModalHeaderCloseButtonImpl = () => {
const label = useColor("label")
const navigation = useNavigation()
const state = navigation.getState()
const routeOnlyOne = state.routes.length === 1
return (
<TouchableOpacity onPress={() => router.dismiss()}>
<CloseCuteReIcon height={20} width={20} color={label} />
{routeOnlyOne ? (
<CloseCuteReIcon height={20} width={20} color={label} />
) : (
<MingcuteLeftLineIcon height={20} width={20} color={label} />
)}
</TouchableOpacity>
)
}
@@ -0,0 +1,26 @@
import * as React from "react"
import Svg, { G, Path } from "react-native-svg"
interface MingcuteLeftLineIconProps {
width?: number
height?: number
color?: string
}
export const MingcuteLeftLineIcon = ({
width = 24,
height = 24,
color = "#10161F",
}: MingcuteLeftLineIconProps) => {
return (
<Svg width={width} height={height} viewBox="0 0 24 24">
<G fill="none" fillRule="evenodd">
<Path d="M24 0v24H0V0h24ZM12.593 23.258l-.011.002-.071.035-.02.004-.014-.004-.071-.035c-.01-.004-.019-.001-.024.005l-.004.01-.017.428.005.02.01.013.104.074.015.004.012-.004.104-.074.012-.016.004-.017-.017-.427c-.002-.01-.009-.017-.017-.018Zm.265-.113-.013.002-.185.093-.01.01-.003.011.018.43.005.012.008.007.201.093c.012.004.023 0 .029-.008l.004-.014-.034-.614c-.003-.012-.01-.02-.02-.022Zm-.715.002a.023.023 0 0 0-.027.006l-.006.014-.034.614c0 .012.007.02.017.024l.015-.002.201-.093.01-.008.004-.011.017-.43-.003-.012-.01-.01-.184-.092Z" />
<Path
fill={color}
d="M8.293 12.707a1 1 0 0 1 0-1.414l5.657-5.657a1 1 0 1 1 1.414 1.414L10.414 12l4.95 4.95a1 1 0 0 1-1.414 1.414l-5.657-5.657Z"
/>
</G>
</Svg>
)
}
+17 -11
View File
@@ -1,23 +1,24 @@
import { FeedViewType } from "@follow/constants"
import { withOpacity } from "@follow/utils"
import { zodResolver } from "@hookform/resolvers/zod"
import { router, Stack, useLocalSearchParams } from "expo-router"
import { useState } from "react"
import { Controller, useForm } from "react-hook-form"
import { ScrollView, Text, TouchableOpacity, View } from "react-native"
import { ScrollView, Text, View } from "react-native"
import { z } from "zod"
import { ModalHeaderCloseButton } from "@/src/components/common/ModalSharedComponents"
import {
ModalHeaderCloseButton,
ModalHeaderShubmitButton,
} from "@/src/components/common/ModalSharedComponents"
import { FormProvider } from "@/src/components/ui/form/FormProvider"
import { FormLabel } from "@/src/components/ui/form/Label"
import { FormSwitch } from "@/src/components/ui/form/Switch"
import { TextField } from "@/src/components/ui/form/TextField"
import { FeedIcon } from "@/src/components/ui/icon/feed-icon"
import { CheckLineIcon } from "@/src/icons/check_line"
import { FeedViewSelector } from "@/src/modules/feed/view-selector"
import { useFeed } from "@/src/store/feed/hooks"
import { subscriptionSyncService } from "@/src/store/subscription/store"
import type { SubscriptionForm } from "@/src/store/subscription/types"
import { useColor } from "@/src/theme/colors"
const formSchema = z.object({
view: z.string(),
@@ -39,7 +40,9 @@ export default function Follow() {
defaultValues,
})
const [isLoading, setIsLoading] = useState(false)
const submit = async () => {
setIsLoading(true)
const values = form.getValues()
const body: SubscriptionForm = {
url: feed.url,
@@ -50,15 +53,16 @@ export default function Follow() {
feedId: feed.id,
}
await subscriptionSyncService.subscribe(body)
await subscriptionSyncService.subscribe(body).finally(() => {
setIsLoading(false)
})
if (router.canDismiss()) {
router.dismiss()
router.dismissAll()
}
}
const { isValid, isDirty } = form.formState
const label = useColor("label")
return (
<ScrollView contentContainerClassName="px-2 pt-4 gap-y-4">
@@ -68,9 +72,11 @@ export default function Follow() {
headerLeft: ModalHeaderCloseButton,
gestureEnabled: !isDirty,
headerRight: () => (
<TouchableOpacity onPress={form.handleSubmit(submit)} disabled={!isValid}>
<CheckLineIcon color={isValid ? label : withOpacity(label, 0.5)} />
</TouchableOpacity>
<ModalHeaderShubmitButton
isValid={isValid}
onPress={form.handleSubmit(submit)}
isLoading={isLoading}
/>
),
}}
/>