diff --git a/apps/desktop/src/renderer/src/modules/profile/email-management.tsx b/apps/desktop/src/renderer/src/modules/profile/email-management.tsx index bfd872a02..c7ff73cb3 100644 --- a/apps/desktop/src/renderer/src/modules/profile/email-management.tsx +++ b/apps/desktop/src/renderer/src/modules/profile/email-management.tsx @@ -111,7 +111,6 @@ function EmailManagementForm() { const updateEmailMutation = useMutation({ mutationFn: async (values: z.infer) => { - await new Promise((resolve) => setTimeout(resolve, 1000)) const res = await changeEmail({ newEmail: values.email }) if (res.error) { throw new Error(res.error.message) diff --git a/apps/mobile/app.config.ts b/apps/mobile/app.config.ts index 533ef8913..f7cfe30be 100644 --- a/apps/mobile/app.config.ts +++ b/apps/mobile/app.config.ts @@ -110,6 +110,12 @@ export default ({ config }: ConfigContext): ExpoConfig => ({ "expo-secure-store", "@react-native-firebase/app", "@react-native-firebase/crashlytics", + [ + "expo-image-picker", + { + photosPermission: "Allow $(PRODUCT_NAME) to access your photos.", + }, + ], ], experiments: { typedRoutes: true, diff --git a/apps/mobile/package.json b/apps/mobile/package.json index e58ae8c4e..e6145815b 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -54,6 +54,7 @@ "expo-file-system": "18.0.11", "expo-haptics": "14.0.1", "expo-image": "2.0.6", + "expo-image-picker": "~16.0.6", "expo-linear-gradient": "14.0.2", "expo-linking": "7.0.5", "expo-localization": "16.0.1", diff --git a/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx b/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx index 4b404aeec..511ae356a 100644 --- a/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx +++ b/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx @@ -3,8 +3,14 @@ import type { NativeStackNavigationOptions } from "@react-navigation/native-stac import { Stack } from "expo-router" import type { FC, PropsWithChildren } from "react" import { useContext, useEffect, useMemo, useRef, useState } from "react" -import type { ScrollView, ScrollViewProps } from "react-native" +import type { + NativeScrollEvent, + NativeSyntheticEvent, + ScrollView, + ScrollViewProps, +} from "react-native" import { Animated as RNAnimated, useAnimatedValue, View } from "react-native" +import type { SharedValue } from "react-native-reanimated" import type { ReanimatedScrollEvent } from "react-native-reanimated/lib/typescript/hook/commonTypes" import { useSafeAreaFrame, useSafeAreaInsets } from "react-native-safe-area-context" @@ -30,6 +36,9 @@ type SafeNavigationScrollViewProps = Omit & { // For scroll view content adjustment behavior withTopInset?: boolean withBottomInset?: boolean + + // to sharedValue + reanimatedScrollY?: SharedValue } & PropsWithChildren export const SafeNavigationScrollView: FC = ({ @@ -40,6 +49,7 @@ export const SafeNavigationScrollView: FC = ({ withBottomInset = false, withTopInset = false, + reanimatedScrollY, ...props }) => { @@ -70,6 +80,11 @@ export const SafeNavigationScrollView: FC = ({ ref={scrollViewRef} onScroll={RNAnimated.event([{ nativeEvent: { contentOffset: { y: scrollY } } }], { useNativeDriver: true, + listener(event: NativeSyntheticEvent) { + if (reanimatedScrollY) { + reanimatedScrollY.value = event.nativeEvent.contentOffset.y + } + }, })} automaticallyAdjustContentInsets={false} automaticallyAdjustsScrollIndicatorInsets={false} diff --git a/apps/mobile/src/components/ui/avatar/UserAvatar.tsx b/apps/mobile/src/components/ui/avatar/UserAvatar.tsx index 58b5a89a1..dd8f085c2 100644 --- a/apps/mobile/src/components/ui/avatar/UserAvatar.tsx +++ b/apps/mobile/src/components/ui/avatar/UserAvatar.tsx @@ -12,6 +12,7 @@ interface UserAvatarProps { className?: string color?: string } + export const UserAvatar = ({ image, size = 24, name, className, color }: UserAvatarProps) => { if (!image) { return ( @@ -24,7 +25,13 @@ export const UserAvatar = ({ image, size = 24, name, className, color }: UserAva style={{ width: size, height: size }} > {name ? ( - {name.slice(0, 2)} + + {name.slice(0, 2)} + ) : ( )} diff --git a/apps/mobile/src/components/ui/button/UIBarButton.tsx b/apps/mobile/src/components/ui/button/UIBarButton.tsx index 61fe08cc9..0e033f658 100644 --- a/apps/mobile/src/components/ui/button/UIBarButton.tsx +++ b/apps/mobile/src/components/ui/button/UIBarButton.tsx @@ -1,3 +1,4 @@ +import { cn } from "@follow/utils" import type { PressableProps } from "react-native" import { Pressable, TouchableOpacity } from "react-native" import Animated, { FadeIn, FadeOut } from "react-native-reanimated" @@ -28,7 +29,10 @@ export const UIBarButton = ({ const ButtonComponent = hasDifferentIcon ? Pressable : TouchableOpacity return ( )) +export const PlainTextField = forwardRef((props, ref) => { + const secondaryLabelColor = useColor("secondaryLabel") + + const [isFocused, setIsFocused] = useState(false) + const textInputRef = useRef(null) + useImperativeHandle(ref, () => textInputRef.current!) + + const pressableButtonXSharedValue = useSharedValue(20) + const pressableButtonOpacity = useSharedValue(0) + + const animatedStyle = useAnimatedStyle(() => { + return { + transform: [{ translateX: pressableButtonXSharedValue.value }], + opacity: pressableButtonOpacity.value, + position: "absolute", + right: 0, + } + }) + + const pressableWidthSharedValue = useSharedValue(isFocused ? 20 : 0) + + useEffect(() => { + if (isFocused) { + pressableButtonXSharedValue.value = withSpring(0, gentleSpringPreset) + pressableButtonOpacity.value = withSpring(1, gentleSpringPreset) + pressableWidthSharedValue.value = withSpring(20, gentleSpringPreset) + } else { + pressableButtonXSharedValue.value = withSpring(20, gentleSpringPreset) + pressableButtonOpacity.value = withSpring(0, gentleSpringPreset) + pressableWidthSharedValue.value = withSpring(0, gentleSpringPreset) + } + }, [isFocused, pressableButtonXSharedValue, pressableButtonOpacity, pressableWidthSharedValue]) + + return ( + + setIsFocused(true))} + onBlur={composeEventHandlers(props.onBlur, () => setIsFocused(false))} + selectionColor={accentColor} + className={cn("text-label placeholder:text-secondary-label w-full flex-1", props.className)} + /> + + + + { + textInputRef.current?.clear() + props.onChangeText?.("") + }} + > + + + + + ) +}) + const styles = StyleSheet.create({ textField: { fontSize: 16, diff --git a/apps/mobile/src/components/ui/grouped/GroupedList.tsx b/apps/mobile/src/components/ui/grouped/GroupedList.tsx index 46d892795..5c68113c1 100644 --- a/apps/mobile/src/components/ui/grouped/GroupedList.tsx +++ b/apps/mobile/src/components/ui/grouped/GroupedList.tsx @@ -2,8 +2,9 @@ import { cn } from "@follow/utils" import type { FC, PropsWithChildren } from "react" import * as React from "react" import { Fragment } from "react" -import type { ViewProps } from "react-native" +import type { PressableProps, ViewProps } from "react-native" import { Pressable, StyleSheet, Text, View } from "react-native" +import Animated, { FadeIn, FadeOut } from "react-native-reanimated" import { MingcuteRightLine } from "@/src/icons/mingcute_right_line" import { useColor } from "@/src/theme/colors" @@ -12,6 +13,17 @@ type GroupedInsetListCardProps = { showSeparator?: boolean } +interface BaseCellClassNames { + leftClassName?: string + rightClassName?: string +} + +export const GroupedOutlineDescription: FC<{ + description: string +}> = ({ description }) => { + return {description} +} + export const GroupedInsetListCard: FC< PropsWithChildren & ViewProps & GroupedInsetListCardProps > = ({ children, className, showSeparator = true, ...props }) => { @@ -76,12 +88,15 @@ export const GroupedInsetListBaseCell: FC = ({ ) } -export const GroupedInsetListNavigationLink: FC<{ - label: string - icon?: React.ReactNode - onPress: () => void - disabled?: boolean -}> = ({ label, icon, onPress, disabled }) => { +export const GroupedInsetListNavigationLink: FC< + { + label: string + icon?: React.ReactNode + onPress: () => void + disabled?: boolean + postfix?: React.ReactNode + } & BaseCellClassNames +> = ({ label, icon, onPress, disabled, leftClassName, rightClassName, postfix }) => { const rightIconColor = useColor("tertiaryLabel") return ( @@ -90,12 +105,13 @@ export const GroupedInsetListNavigationLink: FC<{ - + {icon} - {label} + {label} - + + {postfix} @@ -122,21 +138,23 @@ export const GroupedInsetListNavigationLinkIcon: FC< ) } -export const GroupedInsetListCell: FC<{ - label: string - description?: string - children?: React.ReactNode -}> = ({ label, description, children }) => { +export const GroupedInsetListCell: FC< + { + label: string + description?: string + children?: React.ReactNode + } & BaseCellClassNames +> = ({ label, description, children, leftClassName, rightClassName }) => { return ( - + {label} {!!description && ( {description} )} - {children} + {children} ) } @@ -218,3 +236,32 @@ export const GroupedInformationCell: FC<{ ) } + +export const GroupedPlainButtonCell: FC< + { + label: string + textClassName?: string + } & PressableProps +> = ({ label, textClassName, ...props }) => { + return ( + + + {({ pressed }) => { + return ( + + {/* Pressed Overlay Effect */} + {pressed && ( + + )} + {label} + + ) + }} + + + ) +} diff --git a/apps/mobile/src/lib/auth.ts b/apps/mobile/src/lib/auth.ts index 90b29a079..2b74b86f7 100644 --- a/apps/mobile/src/lib/auth.ts +++ b/apps/mobile/src/lib/auth.ts @@ -39,13 +39,16 @@ const authClient = createAuthClient({ // @keep-sorted export const { + changeEmail, forgetPassword, getCookie, getProviders, + sendVerificationEmail, signIn, signOut, signUp, twoFactor, + updateUser, useSession, } = authClient diff --git a/apps/mobile/src/lib/native/picker.ts b/apps/mobile/src/lib/native/picker.ts new file mode 100644 index 000000000..db24e0458 --- /dev/null +++ b/apps/mobile/src/lib/native/picker.ts @@ -0,0 +1,31 @@ +import * as ImagePicker from "expo-image-picker" + +export const pickImage = async ( + options?: ImagePicker.ImagePickerOptions & { + fileName?: string + }, +) => { + const result = await ImagePicker.launchImageLibraryAsync({ + mediaTypes: ["images"], + allowsEditing: true, + aspect: [1, 1], + quality: 1, + ...options, + }) + + if (result.assets?.[0]) { + const image = result.assets[0] + const imageResponse = await fetch(image.uri) + const imageBlob = await imageResponse.blob() + const formData = new FormData() + formData.append("file", imageBlob, options?.fileName ?? image.fileName ?? "untitled.jpg") + formData.append("type", image.mimeType ?? "image/png") + + return { + formData, + blob: imageBlob, + image, + } + } + return null +} diff --git a/apps/mobile/src/modules/settings/UserHeaderBanner.tsx b/apps/mobile/src/modules/settings/UserHeaderBanner.tsx index add5d3a87..ca10cf11a 100644 --- a/apps/mobile/src/modules/settings/UserHeaderBanner.tsx +++ b/apps/mobile/src/modules/settings/UserHeaderBanner.tsx @@ -130,7 +130,11 @@ export const UserHeaderBanner = ({ {user?.name ? ( {user.name} diff --git a/apps/mobile/src/modules/settings/routes/Account.tsx b/apps/mobile/src/modules/settings/routes/Account.tsx index 9f94d9a59..953f04d2a 100644 --- a/apps/mobile/src/modules/settings/routes/Account.tsx +++ b/apps/mobile/src/modules/settings/routes/Account.tsx @@ -1,14 +1,14 @@ import * as FileSystem from "expo-file-system" -import { Text, TouchableOpacity, View } from "react-native" +import { Alert, View } from "react-native" import { NavigationBlurEffectHeader, SafeNavigationScrollView, } from "@/src/components/layouts/views/SafeNavigationScrollView" import { - GroupedInsetListBaseCell, GroupedInsetListCard, GroupedInsetListSectionHeader, + GroupedPlainButtonCell, } from "@/src/components/ui/grouped/GroupedList" import { getDbPath } from "@/src/database" import { signOut } from "@/src/lib/auth" @@ -21,18 +21,25 @@ export const AccountScreen = () => { - - { - await signOut() - const dbPath = getDbPath() - await FileSystem.deleteAsync(dbPath) - await expo.reloadAppAsync("User sign out") - }} - > - Delete account - - + { + Alert.alert("Delete account", "Are you sure you want to delete your account?", [ + { text: "Cancel", style: "cancel" }, + { + text: "Delete", + style: "destructive", + onPress: async () => { + await signOut() + const dbPath = getDbPath() + await FileSystem.deleteAsync(dbPath) + await expo.reloadAppAsync("User sign out") + }, + }, + ]) + }} + /> diff --git a/apps/mobile/src/modules/settings/routes/EditProfile.tsx b/apps/mobile/src/modules/settings/routes/EditProfile.tsx new file mode 100644 index 000000000..66c338aa3 --- /dev/null +++ b/apps/mobile/src/modules/settings/routes/EditProfile.tsx @@ -0,0 +1,207 @@ +import { withOpacity } from "@follow/utils/src/color" +import { useMutation } from "@tanstack/react-query" +import { router } from "expo-router" +import type { FC } from "react" +import { useState } from "react" +import { + ActivityIndicator, + Text, + TouchableOpacity, + TouchableWithoutFeedback, + View, +} from "react-native" +import { KeyboardController } from "react-native-keyboard-controller" + +import { RotateableLoading } from "@/src/components/common/RotateableLoading" +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, + GroupedInsetListCell, + GroupedInsetListNavigationLink, + 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 { apiClient } from "@/src/lib/api-fetch" +import { pickImage } from "@/src/lib/native/picker" +import { toast } from "@/src/lib/toast" +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" + +export const EditProfileScreen = () => { + const whoami = useWhoami() + + if (!whoami) { + return ( + + + + ) + } + + return ( + + + + + ) +} + +const AvatarSection: FC<{ + whoami: MeModel +}> = ({ whoami }) => { + return ( + + + + { + const result = await pickImage({ + fileName: "avatar.jpg", + }) + + if (!result) return + const { formData } = result + const res = await apiClient.upload.avatar.$post({ + body: { + file: formData, + }, + }) + + void res + }} + > + Set Avatar + + + ) +} + +const ProfileForm: FC<{ + whoami: MeModel +}> = ({ whoami }) => { + const [dirtyFields, setDirtyFields] = useState>({}) + + const { mutateAsync: updateProfile, isPending } = useMutation({ + mutationFn: async () => { + await userSyncService.updateProfile(dirtyFields) + }, + onSuccess: () => { + toast.success("Profile updated") + }, + onError: (error) => { + toast.error(error.message) + }, + }) + + const label = useColor("label") + return ( + + ( + + ) : ( + + ) + } + onPress={() => { + updateProfile() + }} + /> + )} + title="Edit Profile" + /> + + { + KeyboardController.dismiss() + }} + > + + + + + { + setDirtyFields({ ...dirtyFields, name: text }) + }} + /> + + + + + + {/* User name */} + + + + { + setDirtyFields({ ...dirtyFields, handle: text }) + }} + /> + + + + + + {/* Email */} + + { + router.push("/edit-email") + }} + leftClassName="flex-none" + rightClassName="flex-1" + postfix={ + + {whoami.email} + {whoami.emailVerified ? ( + + ) : ( + + )} + + } + /> + + + + + ) +} diff --git a/apps/mobile/src/modules/settings/routes/index.tsx b/apps/mobile/src/modules/settings/routes/index.tsx index 812d8d60c..5adc9dc71 100644 --- a/apps/mobile/src/modules/settings/routes/index.tsx +++ b/apps/mobile/src/modules/settings/routes/index.tsx @@ -6,6 +6,7 @@ import { AchievementScreen } from "./Achievement" import { ActionsScreen } from "./Actions" import { AppearanceScreen } from "./Appearance" import { DataScreen } from "./Data" +import { EditProfileScreen } from "./EditProfile" import { FeedsScreen } from "./Feeds" import { GeneralScreen } from "./General" import { ListsScreen } from "./Lists" @@ -13,21 +14,26 @@ import { ManageListScreen } from "./ManageList" import { NotificationsScreen } from "./Notifications" import { PrivacyScreen } from "./Privacy" -export const SettingRoutes = (Stack: TypedNavigator) => { - return [ - // , - , - , - , - , - , - , - , - , - , - , - , - // @ts-expect-error - , - ] +const SettingFlatRoutes = (Stack: TypedNavigator) => { + return ( + + + + + + + + + + + + + + {/* @ts-expect-error */} + + + + ) } + +export const SettingRoutes = SettingFlatRoutes diff --git a/apps/mobile/src/modules/settings/types.ts b/apps/mobile/src/modules/settings/types.ts index 4ee48516f..b370c4c47 100644 --- a/apps/mobile/src/modules/settings/types.ts +++ b/apps/mobile/src/modules/settings/types.ts @@ -12,4 +12,5 @@ export type SettingsStackParamList = { Privacy: undefined About: undefined ManageList: { id: string } + EditProfile: undefined } diff --git a/apps/mobile/src/screens/(modal)/edit-email.tsx b/apps/mobile/src/screens/(modal)/edit-email.tsx new file mode 100644 index 000000000..da5487d98 --- /dev/null +++ b/apps/mobile/src/screens/(modal)/edit-email.tsx @@ -0,0 +1,90 @@ +import { useMutation } from "@tanstack/react-query" +import { useRouter } from "expo-router" +import { useMemo, useState } from "react" +import { View } from "react-native" + +import { ModalHeaderSubmitButton } from "@/src/components/common/ModalSharedComponents" +import { ModalHeader } from "@/src/components/layouts/header/ModalHeader" +import { SafeModalScrollView } from "@/src/components/layouts/views/SafeModalScrollView" +import { PlainTextField } from "@/src/components/ui/form/TextField" +import { + GroupedInsetListCard, + GroupedInsetListCell, + GroupedInsetListSectionHeader, + GroupedOutlineDescription, + GroupedPlainButtonCell, +} from "@/src/components/ui/grouped/GroupedList" +import { toast } from "@/src/lib/toast" +import { useWhoami } from "@/src/store/user/hooks" +import { userSyncService } from "@/src/store/user/store" + +const EditEmailScreen = () => { + const whoami = useWhoami() + + const [email, setEmail] = useState(whoami?.email ?? "") + + const [isDirty, setIsDirty] = useState(false) + const isValidate = whoami?.emailVerified + + const newEmailIsValid = useMemo(() => { + return email.match(/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/) + }, [email]) + + const navigation = useRouter() + const { mutate: updateEmail, isPending } = useMutation({ + mutationFn: async () => { + await userSyncService.updateEmail(email) + }, + onSuccess: () => { + toast.info("Please check your email inbox to verify your new email") + navigation.dismiss() + }, + }) + + return ( + + { + updateEmail() + }} + /> + } + /> + + + + + + { + setEmail(text) + setIsDirty(true) + }} + placeholder="Enter your email" + className="text-secondary-label w-full flex-1 text-left" + /> + + + + + {/* Buttons */} + + {!isValidate && ( + + + + )} + + + ) +} +export default EditEmailScreen diff --git a/apps/mobile/src/screens/(stack)/(tabs)/settings.tsx b/apps/mobile/src/screens/(stack)/(tabs)/settings.tsx index 50c28face..99e2ce5b5 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/settings.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/settings.tsx @@ -2,7 +2,7 @@ import { useIsFocused } from "@react-navigation/native" import { createNativeStackNavigator } from "@react-navigation/native-stack" import { createContext, useCallback, useContext, useEffect, useState } from "react" import type { NativeScrollEvent, NativeSyntheticEvent, ScrollView } from "react-native" -import { findNodeHandle, Text, UIManager } from "react-native" +import { findNodeHandle, Text, TouchableOpacity, UIManager, View } from "react-native" import type { SharedValue } from "react-native-reanimated" import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated" import { useSafeAreaFrame, useSafeAreaInsets } from "react-native-safe-area-context" @@ -17,6 +17,7 @@ import { useRegisterNavigationScrollView, } from "@/src/components/layouts/tabbar/hooks" import { getDefaultHeaderHeight } from "@/src/components/layouts/utils" +import { useSettingsNavigation } from "@/src/modules/settings/hooks" import { SettingRoutes } from "@/src/modules/settings/routes" import { SettingsList } from "@/src/modules/settings/SettingsList" import { UserHeaderBanner } from "@/src/modules/settings/UserHeaderBanner" @@ -131,15 +132,33 @@ const SettingHeader = ({ scrollY }: { scrollY: SharedValue }) => { } }) + const whoami = useWhoami() return ( - - - - Settings - + + + + Settings + + {!!whoami?.id && } + + ) +} + +const EditProfileButton = () => { + const navigation = useSettingsNavigation() + + return ( + navigation.navigate("EditProfile")} + > + + Edit + ) } diff --git a/apps/mobile/src/store/user/store.ts b/apps/mobile/src/store/user/store.ts index 9bb1407ae..8fcc312e6 100644 --- a/apps/mobile/src/store/user/store.ts +++ b/apps/mobile/src/store/user/store.ts @@ -2,14 +2,21 @@ import analytics from "@react-native-firebase/analytics" import type { UserSchema } from "@/src/database/schemas/types" import { apiClient } from "@/src/lib/api-fetch" +import { changeEmail, sendVerificationEmail, updateUser } from "@/src/lib/auth" +import { toast } from "@/src/lib/toast" import { UserService } from "@/src/services/user" import { createImmerSetter, createTransaction, createZustandStore } from "../internal/helper" +import type { UserProfileEditable } from "./types" export type UserModel = UserSchema + +export type MeModel = UserModel & { + emailVerified?: boolean +} type UserStore = { users: Record - whoami: UserModel | null + whoami: MeModel | null } export const useUserStore = createZustandStore("user")(() => ({ @@ -17,7 +24,7 @@ export const useUserStore = createZustandStore("user")(() => ({ whoami: null, })) -// const set = useUserStore.setState +const get = useUserStore.getState const immerSet = createImmerSetter(useUserStore) class UserSyncService { @@ -48,6 +55,77 @@ class UserSyncService { return null } } + + async updateProfile(data: Partial) { + const me = get().whoami + if (!me) return + const tx = createTransaction(me) + + tx.store(() => { + immerSet((state) => { + if (!state.whoami) return + state.whoami = { ...state.whoami, ...data } + }) + }) + + tx.request(async () => { + await updateUser({ + ...data, + }) + }) + tx.persist(async () => { + const { whoami } = get() + if (!whoami) return + const nextUser = { + ...whoami, + ...data, + } + userActions.upsertMany([nextUser]) + }) + tx.rollback(() => { + immerSet((state) => { + if (!state.whoami) return + state.whoami = me + }) + }) + await tx.run() + } + + async sendVerificationEmail() { + const me = get().whoami + if (!me?.email) return + await sendVerificationEmail({ email: me.email! }) + toast.success("Verification email sent") + } + + async updateEmail(email: string) { + const oldEmail = get().whoami?.email + if (!oldEmail) return + const tx = createTransaction(oldEmail) + tx.store(() => { + immerSet((state) => { + if (!state.whoami) return + state.whoami = { ...state.whoami, email } + }) + }) + tx.request(async () => { + const { whoami } = get() + if (!whoami) return + await changeEmail({ newEmail: email }) + }) + tx.rollback(() => { + immerSet((state) => { + if (!state.whoami) return + state.whoami.email = oldEmail + }) + }) + tx.persist(async () => { + const { whoami } = get() + if (!whoami) return + userActions.upsertMany([{ ...whoami, email }]) + }) + await tx.run() + } } class UserActions { diff --git a/apps/mobile/src/store/user/types.ts b/apps/mobile/src/store/user/types.ts new file mode 100644 index 000000000..53ff7b262 --- /dev/null +++ b/apps/mobile/src/store/user/types.ts @@ -0,0 +1,6 @@ +export interface UserProfileEditable { + email: string + name: string + handle: string + image: string +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 56e2573fe..d4d75bbaa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -859,6 +859,9 @@ importers: expo-image: specifier: 2.0.6 version: 2.0.6(expo@52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5))(react-native-web@0.19.13(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1) + expo-image-picker: + specifier: ~16.0.6 + version: 16.0.6(expo@52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5)) expo-linear-gradient: specifier: 14.0.2 version: 14.0.2(expo@52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1) @@ -8549,6 +8552,16 @@ packages: peerDependencies: expo: '*' + expo-image-loader@5.0.0: + resolution: {integrity: sha512-Eg+5FHtyzv3Jjw9dHwu2pWy4xjf8fu3V0Asyy42kO+t/FbvW/vjUixpTjPtgKQLQh+2/9Nk4JjFDV6FwCnF2ZA==} + peerDependencies: + expo: '*' + + expo-image-picker@16.0.6: + resolution: {integrity: sha512-HN4xZirFjsFDIsWFb12AZh19fRzuvZjj2ll17cGr19VNRP06S/VPQU3Tdccn5vwUzQhOBlLu704CnNm278boiQ==} + peerDependencies: + expo: '*' + expo-image@2.0.6: resolution: {integrity: sha512-NHpIZmGnrPbyDadil6eK+sUgyFMQfapEVb7YaGgxSFWBUQ1rSpjqdIQrCD24IZTO9uSH8V+hMh2ROxrAjAixzQ==} peerDependencies: @@ -24730,6 +24743,15 @@ snapshots: dependencies: expo: 52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5) + expo-image-loader@5.0.0(expo@52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5)): + dependencies: + expo: 52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5) + + expo-image-picker@16.0.6(expo@52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5)): + dependencies: + expo: 52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5) + expo-image-loader: 5.0.0(expo@52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5)) + expo-image@2.0.6(expo@52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5))(react-native-web@0.19.13(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1): dependencies: expo: 52.0.37(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@expo/metro-runtime@4.0.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.12.5(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(utf-8-validate@6.0.5)