diff --git a/apps/mobile/src/components/layouts/header/FakeNativeHeaderTitle.tsx b/apps/mobile/src/components/layouts/header/FakeNativeHeaderTitle.tsx index 2fd94b5da..16768ff58 100644 --- a/apps/mobile/src/components/layouts/header/FakeNativeHeaderTitle.tsx +++ b/apps/mobile/src/components/layouts/header/FakeNativeHeaderTitle.tsx @@ -13,7 +13,7 @@ export function FakeNativeHeaderTitle({ style, ...rest }: Props) { accessibilityRole="header" aria-level="1" numberOfLines={1} - className={"text-label font-bold"} + className={"text-label font-semibold"} {...rest} style={[styles.title, style]} /> diff --git a/apps/mobile/src/components/layouts/header/HeaderElements.tsx b/apps/mobile/src/components/layouts/header/HeaderElements.tsx index 23ae3e5b3..b37d2c3a8 100644 --- a/apps/mobile/src/components/layouts/header/HeaderElements.tsx +++ b/apps/mobile/src/components/layouts/header/HeaderElements.tsx @@ -1,6 +1,6 @@ -import { withOpacity } from "@follow/utils" +import { cn, withOpacity } from "@follow/utils" import { useCallback } from "react" -import { TouchableOpacity } from "react-native" +import { Text, TouchableOpacity, View } from "react-native" import { CheckLineIcon } from "@/src/icons/check_line" import { CloseCuteReIcon } from "@/src/icons/close_cute_re" @@ -24,6 +24,7 @@ const HeaderCloseButton = () => { const canDismiss = useCanDismiss() const isInModal = useScreenIsInSheetModal() const isSingleRouteInGroup = useIsSingleRouteInGroup() + const handlePress = useCallback(() => { if (canDismiss) { navigation.dismiss() @@ -67,6 +68,35 @@ export const HeaderSubmitButton = ({ ) } +export const HeaderSubmitTextButton = ({ + isValid, + onPress, + isLoading, + label = "Submit", +}: ModalHeaderSubmitButtonProps & { + label?: string +}) => { + const labelColor = useColor("label") + return ( + + {isLoading && ( + + + + )} + + {label} + + + ) +} + export const HeaderCloseOnly = () => { return ( diff --git a/apps/mobile/src/components/layouts/header/NavigationHeader.tsx b/apps/mobile/src/components/layouts/header/NavigationHeader.tsx index 94a0dc79f..d85b1ba96 100644 --- a/apps/mobile/src/components/layouts/header/NavigationHeader.tsx +++ b/apps/mobile/src/components/layouts/header/NavigationHeader.tsx @@ -30,6 +30,7 @@ import { MingcuteLeftLineIcon } from "@/src/icons/mingcute_left_line" import { useCanBack, useCanDismiss, + useIsTopRouteInGroup, useNavigation, useScreenIsInSheetModal, } from "@/src/lib/navigation/hooks" @@ -304,7 +305,6 @@ export const InternalNavigationHeader = ({ )} {/* Center */} - { const label = useColor("label") const navigation = useNavigation() + + const isTopRouteInGroup = useIsTopRouteInGroup() + + const showCloseIcon = canDismiss && isTopRouteInGroup + if (!canGoBack && !canDismiss) return null return ( - {canGoBack ? ( + {!showCloseIcon ? ( ) : ( diff --git a/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx b/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx index 1e201b113..60b31162e 100644 --- a/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx +++ b/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx @@ -1,7 +1,7 @@ import { useTypeScriptHappyCallback } from "@follow/hooks" import { useSetAtom, useStore } from "jotai" import type { PropsWithChildren } from "react" -import { forwardRef, useContext, useEffect, useState } from "react" +import { forwardRef, useContext, useLayoutEffect, useState } from "react" import type { ScrollView, ScrollViewProps, StyleProp, ViewStyle } from "react-native" import { View } from "react-native" import type { SharedValue } from "react-native-reanimated" @@ -126,7 +126,7 @@ export const NavigationBlurEffectHeader = ({ const setSlot = useSetAtom(screenCtxValue.Slot) const store = useStore() - useEffect(() => { + useLayoutEffect(() => { setSlot({ ...store.get(screenCtxValue.Slot), header: ( diff --git a/apps/mobile/src/lib/navigation/hooks.ts b/apps/mobile/src/lib/navigation/hooks.ts index 96bb533c6..363eebe1e 100644 --- a/apps/mobile/src/lib/navigation/hooks.ts +++ b/apps/mobile/src/lib/navigation/hooks.ts @@ -72,3 +72,15 @@ export const useIsSingleRouteInGroup = () => { if (!routeGroup || routeGroup.length === 0) return false return routeGroup.length === 1 } + +export const useIsTopRouteInGroup = () => { + const { screenId } = useContext(ScreenItemContext) + + const routeGroups = useContext(GroupedNavigationRouteContext) + if (!routeGroups) return false + const routeGroup = routeGroups.find((group) => group.some((r) => r.id === screenId)) + + if (!routeGroup || routeGroup.length === 0) return false + + return routeGroup.at(0)?.screenOptions?.id === screenId +} diff --git a/apps/mobile/src/modules/feed/FollowFeed.tsx b/apps/mobile/src/modules/feed/FollowFeed.tsx index b9093ac12..067ff0ea8 100644 --- a/apps/mobile/src/modules/feed/FollowFeed.tsx +++ b/apps/mobile/src/modules/feed/FollowFeed.tsx @@ -6,7 +6,7 @@ import { ActivityIndicator, Text, View } from "react-native" import { useSafeAreaInsets } from "react-native-safe-area-context" import { z } from "zod" -import { HeaderSubmitButton } from "@/src/components/layouts/header/HeaderElements" +import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements" import { NavigationBlurEffectHeader, SafeNavigationScrollView, @@ -131,10 +131,11 @@ function FollowImpl(props: { feedId: string }) { } /> diff --git a/apps/mobile/src/modules/list/FollowList.tsx b/apps/mobile/src/modules/list/FollowList.tsx index 9a17f8d1c..bee71aa78 100644 --- a/apps/mobile/src/modules/list/FollowList.tsx +++ b/apps/mobile/src/modules/list/FollowList.tsx @@ -6,7 +6,7 @@ import { Controller, useForm } from "react-hook-form" import { ActivityIndicator, Alert, StyleSheet, Text, View } from "react-native" import { z } from "zod" -import { HeaderSubmitButton } from "@/src/components/layouts/header/HeaderElements" +import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements" import { NavigationBlurEffectHeader, SafeNavigationScrollView, @@ -132,10 +132,11 @@ const Impl = (props: { id: string }) => { } /> diff --git a/apps/mobile/src/modules/settings/hooks/useTOTPModalWrapper.tsx b/apps/mobile/src/modules/settings/hooks/useTOTPModalWrapper.tsx new file mode 100644 index 000000000..e21704ec6 --- /dev/null +++ b/apps/mobile/src/modules/settings/hooks/useTOTPModalWrapper.tsx @@ -0,0 +1,58 @@ +import { useCallback } from "react" + +import { getFetchErrorInfo } from "@/src/lib/error-parser" +import { useNavigation } from "@/src/lib/navigation/hooks" +import { toast } from "@/src/lib/toast" +import { TwoFactorAuthScreen } from "@/src/screens/(modal)/2fa" +import { useWhoami } from "@/src/store/user/hooks" + +export const useTOTPModalWrapper = ( + callback: (input: T) => Promise, + options?: { force?: boolean }, +) => { + const user = useWhoami() + const navigation = useNavigation() + return useCallback( + async (input: T) => { + const presentTOTPModal = () => { + if (!user?.twoFactorEnabled) { + toast.error("You need to enable two-factor authentication to perform this action.") + + navigation.pushControllerView(TwoFactorAuthScreen) + + return + } + + // present({ + // title: t("profile.totp_code.title"), + // content: ({ dismiss }) => { + // return createElement(TOTPForm, { + // async onSubmitMutationFn(values) { + // await callback({ + // ...input, + // TOTPCode: values.code, + // }) + // dismiss() + // }, + // }) + // }, + // }) + } + + if (options?.force) { + presentTOTPModal() + return + } + + try { + await callback(input) + } catch (error) { + const { code } = getFetchErrorInfo(error as Error) + if (code === 4008) { + presentTOTPModal() + } + } + }, + [callback, navigation, options?.force, user?.twoFactorEnabled], + ) +} diff --git a/apps/mobile/src/modules/settings/routes/EditProfile.tsx b/apps/mobile/src/modules/settings/routes/EditProfile.tsx index 8b5b7f42f..fe9b00e70 100644 --- a/apps/mobile/src/modules/settings/routes/EditProfile.tsx +++ b/apps/mobile/src/modules/settings/routes/EditProfile.tsx @@ -1,7 +1,6 @@ -import { withOpacity } from "@follow/utils/src/color" import { useMutation } from "@tanstack/react-query" import type { FC } from "react" -import { useCallback, useState } from "react" +import { useState } from "react" import { ActivityIndicator, Text, @@ -11,13 +10,12 @@ import { } from "react-native" import { KeyboardController } from "react-native-keyboard-controller" -import { RotateableLoading } from "@/src/components/common/RotateableLoading" +import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements" import { NavigationBlurEffectHeader, SafeNavigationScrollView, } from "@/src/components/layouts/views/SafeNavigationScrollView" import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar" -import { UIBarButton } from "@/src/components/ui/button/UIBarButton" import { PlainTextField } from "@/src/components/ui/form/TextField" import { GroupedInsetListCard, @@ -26,7 +24,6 @@ import { GroupedOutlineDescription, } from "@/src/components/ui/grouped/GroupedList" import { CheckCircleCuteReIcon } from "@/src/icons/check_circle_cute_re" -import { CheckLineIcon } from "@/src/icons/check_line" import { CloseCircleFillIcon } from "@/src/icons/close_circle_fill" import { useNavigation } from "@/src/lib/navigation/hooks" import { toast } from "@/src/lib/toast" @@ -35,7 +32,7 @@ import { useWhoami } from "@/src/store/user/hooks" import type { MeModel } from "@/src/store/user/store" import { userSyncService } from "@/src/store/user/store" import type { UserProfileEditable } from "@/src/store/user/types" -import { accentColor, useColor } from "@/src/theme/colors" +import { accentColor } from "@/src/theme/colors" import { setAvatar } from "../utils" @@ -95,31 +92,21 @@ const ProfileForm: FC<{ }, }) - const label = useColor("label") - const headerRight = useCallback( - () => ( - - ) : ( - - ) - } - onPress={() => { - updateProfile() - }} - /> - ), - [dirtyFields, isPending, label, updateProfile], - ) - const navigation = useNavigation() return ( - + { + updateProfile() + }} + /> + } + title="Edit Profile" + /> { diff --git a/apps/mobile/src/modules/settings/routes/Invitations.tsx b/apps/mobile/src/modules/settings/routes/Invitations.tsx index 257e11a35..74beefa3a 100644 --- a/apps/mobile/src/modules/settings/routes/Invitations.tsx +++ b/apps/mobile/src/modules/settings/routes/Invitations.tsx @@ -2,7 +2,7 @@ import { cn } from "@follow/utils" import { useMutation, useQuery } from "@tanstack/react-query" import dayjs from "dayjs" import { setStringAsync } from "expo-clipboard" -import { Clipboard, Pressable, Text, View } from "react-native" +import { Pressable, Text, View } from "react-native" import { useServerConfigs } from "@/src/atoms/server-configs" import { UINavigationHeaderActionButton } from "@/src/components/layouts/header/NavigationHeader" @@ -53,7 +53,7 @@ export const InvitationsScreen: NavigationControllerView = () => { const { data: invitations, isLoading } = useInvitationsQuery() const limitation = useInvitationsLimitationQuery() const handleCopyCode = (code: string) => { - Clipboard.setString(code) + setStringAsync(code) toast.success("Copied to clipboard") } return ( diff --git a/apps/mobile/src/screens/(modal)/edit-email.tsx b/apps/mobile/src/screens/(modal)/edit-email.tsx index 5fa2c6779..4c34d42b5 100644 --- a/apps/mobile/src/screens/(modal)/edit-email.tsx +++ b/apps/mobile/src/screens/(modal)/edit-email.tsx @@ -2,7 +2,7 @@ import { useMutation } from "@tanstack/react-query" import { useMemo, useState } from "react" import { View } from "react-native" -import { HeaderSubmitButton } from "@/src/components/layouts/header/HeaderElements" +import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements" import { NavigationBlurEffectHeader, SafeNavigationScrollView, @@ -50,7 +50,7 @@ export const EditEmailScreen: NavigationControllerView = () => { { diff --git a/apps/mobile/src/screens/(modal)/rsshub-form.tsx b/apps/mobile/src/screens/(modal)/rsshub-form.tsx index 1e7bf3dd9..52323e94c 100644 --- a/apps/mobile/src/screens/(modal)/rsshub-form.tsx +++ b/apps/mobile/src/screens/(modal)/rsshub-form.tsx @@ -13,7 +13,7 @@ import { Controller, useForm } from "react-hook-form" import { KeyboardAvoidingView, Linking, Text, TouchableOpacity, View } from "react-native" import { z } from "zod" -import { HeaderSubmitButton } from "@/src/components/layouts/header/HeaderElements" +import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements" import { NavigationBlurEffectHeader, SafeNavigationScrollView, @@ -339,5 +339,7 @@ const ModalHeaderSubmitButtonImpl = ({ } }) - return + return ( + + ) }