feat(mobile): swipe actions for users in settings

Swipe a user left to make or remove admin, or delete them; both ask
for confirmation. The create account button is larger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
joshuafhigginsandClaude Opus 5.5 committed 2026-11-20 01:28:17 -05:00 Verified
1 parent 23e53cc8e9
commit 73813809f7
3 files changed
+187 -80

No files matched your search

+185 -78
View File
@@ -16,6 +16,7 @@ import {
Text,
View,
} from "react-native"
import ReanimatedSwipeable from "react-native-gesture-handler/ReanimatedSwipeable"
import { useSafeAreaInsets } from "react-native-safe-area-context"
import { AddButton } from "@/components/add-button"
@@ -44,7 +45,7 @@ import { useCachedQuery } from "@/hooks/use-cached-query"
import { clearCoverPaletteCache } from "@/hooks/use-cover-palette"
import { useProfileImageUrl } from "@/hooks/use-profile-image-url"
import { changeServer, signOut } from "@/lib/session"
import { radius, spacing, useThemeColors } from "@/lib/theme"
import { appleMusic, radius, spacing, useThemeColors } from "@/lib/theme"
import { showError } from "@/lib/toast"
import type { PlaybackQuality } from "@otunes/convex/playback-stream"
import { api } from "@otunes/convex/_generated/api"
@@ -425,11 +426,20 @@ function QualityName({
)
}
/** Asks before a destructive action, e.g. removing downloads or a user. */
function confirm(title: string, action: string, onConfirm: () => void) {
/** Asks before an action, e.g. removing downloads or changing a user. */
function confirm(
title: string,
action: string,
onConfirm: () => void,
destructive = true
) {
Alert.alert(title, undefined, [
{ text: "Cancel", style: "cancel" },
{ text: action, style: "destructive", onPress: onConfirm },
{
text: action,
style: destructive ? "destructive" : "default",
onPress: onConfirm,
},
])
}
@@ -780,67 +790,37 @@ function UsersSection({
/>
}
>
<List>
<List flush>
{users.map((user) => (
<View key={user._id} style={styles.listRow}>
<ProfileAvatar user={user} size={36} />
<View style={styles.rowCopy}>
<View style={styles.userNameRow}>
<Text
style={[
styles.rowTitle,
styles.userName,
{ color: colors.foreground },
]}
numberOfLines={1}
>
{user.name}
</Text>
{user.isAdmin ? (
<Text style={[styles.badgeText, { color: colors.primary }]}>
Admin
</Text>
) : null}
</View>
<Text
style={[styles.rowDetail, { color: colors.mutedForeground }]}
numberOfLines={1}
>
{user.email}
</Text>
</View>
{user._id !== currentUserId ? (
<>
<IconButton
icon={user.isAdmin ? "shield-checkmark" : "shield-outline"}
label={user.isAdmin ? "Remove admin" : "Make admin"}
plain
active={user.isAdmin}
onPress={() =>
void setAdmin({
userId: user._id,
isAdmin: !user.isAdmin,
}).catch((error: Error) => showError(error.message))
}
/>
<IconButton
icon="trash-outline"
label={`Delete ${user.name}`}
plain
onPress={() =>
confirm(
`Delete ${user.name}?`,
"Delete",
() =>
void deleteUserMutation({ userId: user._id }).catch(
(error: Error) => showError(error.message)
)
)
}
/>
</>
) : null}
</View>
<UserRow
key={user._id}
user={user}
swipeable={user._id !== currentUserId}
onToggleAdmin={() =>
confirm(
user.isAdmin
? `Remove admin from ${user.name}?`
: `Make ${user.name} an admin?`,
user.isAdmin ? "Remove Admin" : "Make Admin",
() =>
void setAdmin({
userId: user._id,
isAdmin: !user.isAdmin,
}).catch((error: Error) => showError(error.message)),
user.isAdmin
)
}
onDelete={() =>
confirm(
`Delete ${user.name}?`,
"Delete",
() =>
void deleteUserMutation({ userId: user._id }).catch(
(error: Error) => showError(error.message)
)
)
}
/>
))}
</List>
</Group>
@@ -848,6 +828,107 @@ function UsersSection({
)
}
/**
* A person in the admin list. Swiping left reveals admin and delete actions;
* both ask for confirmation through the handlers.
*/
function UserRow({
user,
swipeable,
onToggleAdmin,
onDelete,
}: {
user: AdminUser
swipeable: boolean
onToggleAdmin: () => void
onDelete: () => void
}) {
const colors = useThemeColors()
const row = (
<View style={[styles.listRow, styles.listItem]}>
<ProfileAvatar user={user} size={36} />
<View style={styles.rowCopy}>
<View style={styles.userNameRow}>
<Text
style={[
styles.rowTitle,
styles.userName,
{ color: colors.foreground },
]}
numberOfLines={1}
>
{user.name}
</Text>
{user.isAdmin ? (
<Text style={[styles.badgeText, { color: colors.primary }]}>
Admin
</Text>
) : null}
</View>
<Text
style={[styles.rowDetail, { color: colors.mutedForeground }]}
numberOfLines={1}
>
{user.email}
</Text>
</View>
</View>
)
if (!swipeable) return row
const actions: {
label: string
icon: IconName
color: string
onPress: () => void
}[] = [
{
label: user.isAdmin ? "Remove Admin" : "Make Admin",
icon: user.isAdmin ? "shield-outline" : "shield-checkmark",
color: appleMusic.tabInactive,
onPress: onToggleAdmin,
},
{
label: "Delete",
icon: "trash",
color: colors.destructive,
onPress: onDelete,
},
]
return (
<ReanimatedSwipeable
friction={2}
rightThreshold={40}
overshootRight={false}
childrenContainerStyle={{ backgroundColor: colors.card }}
renderRightActions={(_progress, _translation, swipeable) => (
<View style={{ flexDirection: "row" }}>
{actions.map((action) => (
<Pressable
key={action.label}
accessibilityRole="button"
accessibilityLabel={`${action.label}: ${user.name}`}
onPress={() => {
swipeable.close()
action.onPress()
}}
style={[styles.swipeAction, { backgroundColor: action.color }]}
>
<Ionicons name={action.icon} size={22} color="#fff" />
<Text style={[styles.swipeActionText, { color: "#fff" }]}>
{action.label}
</Text>
</Pressable>
))}
</View>
)}
>
{row}
</ReanimatedSwipeable>
)
}
function SessionSection({
onChangeServer,
onSignOut,
@@ -918,22 +999,36 @@ function GroupTitle({
<Text style={[styles.groupTitle, { color: colors.foreground }]}>
{title}
</Text>
{/* Overflows the row so every group title keeps the same height. */}
{/* Grows upward out of the row so every group title keeps the same height. */}
{action ? <View style={styles.groupAction}>{action}</View> : null}
</View>
)
}
/** An inset grouped card that stacks rows with inset hairline separators. */
function List({ children }: { children: React.ReactNode }) {
/**
* An inset grouped card that stacks rows with inset hairline separators.
* `flush` leaves horizontal padding to the rows, e.g. swipeable rows whose
* actions reach the card edge.
*/
function List({
flush,
children,
}: {
flush?: boolean
children: React.ReactNode
}) {
const colors = useThemeColors()
return (
<View style={[styles.list, { backgroundColor: colors.card }]}>
{Children.toArray(children).map((row, index) => (
<View key={index}>
<View key={index} style={flush ? undefined : styles.listItem}>
{index > 0 ? (
<View
style={[styles.separator, { backgroundColor: colors.border }]}
style={[
styles.separator,
{ backgroundColor: colors.border },
flush ? styles.flushSeparator : null,
]}
/>
) : null}
{row}
@@ -1069,7 +1164,6 @@ function IconButton({
loading,
destructive,
plain,
active,
}: {
icon: IconName
label: string
@@ -1078,17 +1172,14 @@ function IconButton({
loading?: boolean
destructive?: boolean
plain?: boolean
active?: boolean
}) {
const colors = useThemeColors()
const isDisabled = disabled || loading
const tint = destructive
? colors.destructive
: active
? colors.primary
: plain
? colors.mutedForeground
: colors.foreground
: plain
? colors.mutedForeground
: colors.foreground
return (
<Pressable
@@ -1212,8 +1303,9 @@ const styles = StyleSheet.create({
minHeight: 32,
},
groupAction: {
height: 0,
justifyContent: "center",
position: "absolute",
right: 0,
bottom: 0,
},
groupTitle: {
fontSize: 15,
@@ -1222,11 +1314,26 @@ const styles = StyleSheet.create({
list: {
borderRadius: radius.lg,
overflow: "hidden",
},
listItem: {
paddingHorizontal: spacing.lg,
},
separator: {
height: StyleSheet.hairlineWidth,
},
flushSeparator: {
marginHorizontal: spacing.lg,
},
swipeAction: {
width: 96,
alignItems: "center",
justifyContent: "center",
gap: 4,
},
swipeActionText: {
fontSize: 13,
fontWeight: "600",
},
groupFooter: {
fontSize: 13,
lineHeight: 18,
+1 -1
View File
@@ -24,7 +24,7 @@ export function AddButton({
labelStyle("iconOnly"),
buttonStyle("glass"),
buttonBorderShape("circle"),
controlSize("regular"),
controlSize("large"),
]}
/>
</Host>
+1 -1
View File
@@ -20,7 +20,7 @@ export function AddButton({
onPress={onPress}
style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
>
<Ionicons name="add" size={28} color={colors.foreground} />
<Ionicons name="add" size={32} color={colors.foreground} />
</Pressable>
)
}