feat(mobile): native add button and read-only profile in settings
Use a native SwiftUI glass plus button to create accounts, keep group title rows the same height so section spacing is even, and drop the name, email and password editors from the profile tab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9b41f89dbb
commit
5428691045
3 files changed
+97
-142
No files matched your search
@@ -18,6 +18,7 @@ import {
|
||||
} from "react-native"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
|
||||
import { AddButton } from "@/components/add-button"
|
||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||
import { useDownloads, useDownloadsVersion } from "@/contexts/downloads"
|
||||
import {
|
||||
@@ -31,7 +32,7 @@ import {
|
||||
formatBytes,
|
||||
type DownloadQuality,
|
||||
} from "@otunes/convex/download-quality"
|
||||
import { Input, LoadingView } from "@/components/ui/primitives"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import {
|
||||
@@ -276,15 +277,7 @@ function AppearanceSection() {
|
||||
|
||||
function ProfileSection({ user }: { user: CurrentUser }) {
|
||||
const colors = useThemeColors()
|
||||
const updateName = useMutation(api.users.updateProfileName)
|
||||
const updateEmail = useMutation(api.users.updateProfileEmail)
|
||||
const updateImage = useMutation(api.users.updateProfileImage)
|
||||
const updatePassword = useAction(api.users.updateOwnPassword)
|
||||
const [name, setName] = useState(user.name)
|
||||
const [email, setEmail] = useState(user.email)
|
||||
const [newPassword, setNewPassword] = useState("")
|
||||
const [confirmPassword, setConfirmPassword] = useState("")
|
||||
const [changingPassword, setChangingPassword] = useState(false)
|
||||
|
||||
async function pickImage() {
|
||||
const result = await ImagePicker.launchImageLibraryAsync({
|
||||
@@ -316,130 +309,37 @@ function ProfileSection({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePasswordChange() {
|
||||
if (newPassword !== confirmPassword) {
|
||||
showError("Passwords do not match")
|
||||
return
|
||||
}
|
||||
|
||||
setChangingPassword(true)
|
||||
try {
|
||||
await updatePassword({ newPassword })
|
||||
setNewPassword("")
|
||||
setConfirmPassword("")
|
||||
} catch (error) {
|
||||
showError(
|
||||
error instanceof Error ? error.message : "Failed to update password"
|
||||
)
|
||||
} finally {
|
||||
setChangingPassword(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<View style={styles.photoRow}>
|
||||
<ProfileAvatar user={user} size={64} />
|
||||
<View style={styles.rowCopy}>
|
||||
<Text
|
||||
style={[styles.rowTitle, { color: colors.foreground }]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{user.name}
|
||||
</Text>
|
||||
<Text
|
||||
style={[styles.rowDetail, { color: colors.mutedForeground }]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{user.email}
|
||||
</Text>
|
||||
</View>
|
||||
<IconButton
|
||||
icon="image-outline"
|
||||
label="Choose photo"
|
||||
onPress={() => void pickImage()}
|
||||
/>
|
||||
{user.image ? (
|
||||
<IconButton
|
||||
icon="trash-outline"
|
||||
label="Remove photo"
|
||||
destructive
|
||||
onPress={() => void removeImage()}
|
||||
/>
|
||||
) : null}
|
||||
<View style={styles.photoRow}>
|
||||
<ProfileAvatar user={user} size={64} />
|
||||
<View style={styles.rowCopy}>
|
||||
<Text
|
||||
style={[styles.rowTitle, { color: colors.foreground }]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{user.name}
|
||||
</Text>
|
||||
<Text
|
||||
style={[styles.rowDetail, { color: colors.mutedForeground }]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{user.email}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<Group title="Account">
|
||||
<View style={styles.inputRow}>
|
||||
<Input
|
||||
value={name}
|
||||
onChangeText={setName}
|
||||
placeholder="Name"
|
||||
style={styles.input}
|
||||
/>
|
||||
<IconButton
|
||||
icon="checkmark"
|
||||
label="Save name"
|
||||
disabled={!name.trim() || name.trim() === user.name}
|
||||
onPress={() =>
|
||||
void updateName({ name: name.trim() }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.inputRow}>
|
||||
<Input
|
||||
value={email}
|
||||
onChangeText={setEmail}
|
||||
placeholder="Email"
|
||||
autoCapitalize="none"
|
||||
keyboardType="email-address"
|
||||
style={styles.input}
|
||||
/>
|
||||
<IconButton
|
||||
icon="checkmark"
|
||||
label="Save email"
|
||||
disabled={!email.trim() || email.trim() === user.email}
|
||||
onPress={() =>
|
||||
void updateEmail({ email: email.trim() }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
</Group>
|
||||
|
||||
<Group title="Password">
|
||||
<View style={styles.inputRow}>
|
||||
<Input
|
||||
value={newPassword}
|
||||
onChangeText={setNewPassword}
|
||||
placeholder="New password"
|
||||
secureTextEntry
|
||||
style={styles.input}
|
||||
/>
|
||||
{/* Spacer keeps both password fields the same width. */}
|
||||
<View style={styles.iconButton} />
|
||||
</View>
|
||||
<View style={styles.inputRow}>
|
||||
<Input
|
||||
value={confirmPassword}
|
||||
onChangeText={setConfirmPassword}
|
||||
placeholder="Confirm password"
|
||||
secureTextEntry
|
||||
style={styles.input}
|
||||
/>
|
||||
<IconButton
|
||||
icon="checkmark"
|
||||
label="Update password"
|
||||
loading={changingPassword}
|
||||
disabled={!newPassword || newPassword !== confirmPassword}
|
||||
onPress={() => void handlePasswordChange()}
|
||||
/>
|
||||
</View>
|
||||
</Group>
|
||||
</>
|
||||
<IconButton
|
||||
icon="image-outline"
|
||||
label="Choose photo"
|
||||
onPress={() => void pickImage()}
|
||||
/>
|
||||
{user.image ? (
|
||||
<IconButton
|
||||
icon="trash-outline"
|
||||
label="Remove photo"
|
||||
destructive
|
||||
onPress={() => void removeImage()}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -667,6 +567,7 @@ function DownloadsSection() {
|
||||
icon="trash-outline"
|
||||
label="Remove all downloads"
|
||||
destructive
|
||||
plain
|
||||
onPress={() =>
|
||||
confirm(
|
||||
"Remove all downloads?",
|
||||
@@ -873,8 +774,7 @@ function UsersSection({
|
||||
<Group
|
||||
title="People"
|
||||
action={
|
||||
<IconButton
|
||||
icon="person-add-outline"
|
||||
<AddButton
|
||||
label="Create account"
|
||||
onPress={() => router.push("/(app)/create-account")}
|
||||
/>
|
||||
@@ -1018,7 +918,8 @@ function GroupTitle({
|
||||
<Text style={[styles.groupTitle, { color: colors.foreground }]}>
|
||||
{title}
|
||||
</Text>
|
||||
{action}
|
||||
{/* Overflows the row so every group title keeps the same height. */}
|
||||
{action ? <View style={styles.groupAction}>{action}</View> : null}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -1310,6 +1211,10 @@ const styles = StyleSheet.create({
|
||||
justifyContent: "space-between",
|
||||
minHeight: 32,
|
||||
},
|
||||
groupAction: {
|
||||
height: 0,
|
||||
justifyContent: "center",
|
||||
},
|
||||
groupTitle: {
|
||||
fontSize: 15,
|
||||
fontWeight: "700",
|
||||
@@ -1357,14 +1262,6 @@ const styles = StyleSheet.create({
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
},
|
||||
inputRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.sm,
|
||||
},
|
||||
input: {
|
||||
flex: 1,
|
||||
},
|
||||
iconButton: {
|
||||
width: 44,
|
||||
height: 44,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Button, Host } from "@expo/ui/swift-ui"
|
||||
import {
|
||||
buttonBorderShape,
|
||||
buttonStyle,
|
||||
controlSize,
|
||||
labelStyle,
|
||||
} from "@expo/ui/swift-ui/modifiers"
|
||||
|
||||
/** A native SwiftUI glass "+" button, matching the iOS header close button. */
|
||||
export function AddButton({
|
||||
label,
|
||||
onPress,
|
||||
}: {
|
||||
label: string
|
||||
onPress: () => void
|
||||
}) {
|
||||
return (
|
||||
<Host matchContents>
|
||||
<Button
|
||||
label={label}
|
||||
systemImage="plus"
|
||||
onPress={onPress}
|
||||
modifiers={[
|
||||
labelStyle("iconOnly"),
|
||||
buttonStyle("glass"),
|
||||
buttonBorderShape("circle"),
|
||||
controlSize("regular"),
|
||||
]}
|
||||
/>
|
||||
</Host>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Pressable } from "react-native"
|
||||
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
|
||||
/** A plain "+" icon button. iOS uses a native SwiftUI button instead. */
|
||||
export function AddButton({
|
||||
label,
|
||||
onPress,
|
||||
}: {
|
||||
label: string
|
||||
onPress: () => void
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={label}
|
||||
hitSlop={8}
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
|
||||
>
|
||||
<Ionicons name="add" size={28} color={colors.foreground} />
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user