From 1c22639527bc0ab808b467f075dc3725f530cf79 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Fri, 20 Nov 2026 01:28:17 -0500 Subject: [PATCH] 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 --- .../mobile/app/(app)/(tabs)/home/settings.tsx | 263 ++++++++++++------ apps/mobile/components/add-button.ios.tsx | 2 +- apps/mobile/components/add-button.tsx | 2 +- 3 files changed, 187 insertions(+), 80 deletions(-) diff --git a/apps/mobile/app/(app)/(tabs)/home/settings.tsx b/apps/mobile/app/(app)/(tabs)/home/settings.tsx index ea99c20..cf1791d 100644 --- a/apps/mobile/app/(app)/(tabs)/home/settings.tsx +++ b/apps/mobile/app/(app)/(tabs)/home/settings.tsx @@ -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({ /> } > - + {users.map((user) => ( - - - - - - {user.name} - - {user.isAdmin ? ( - - Admin - - ) : null} - - - {user.email} - - - {user._id !== currentUserId ? ( - <> - - void setAdmin({ - userId: user._id, - isAdmin: !user.isAdmin, - }).catch((error: Error) => showError(error.message)) - } - /> - - confirm( - `Delete ${user.name}?`, - "Delete", - () => - void deleteUserMutation({ userId: user._id }).catch( - (error: Error) => showError(error.message) - ) - ) - } - /> - - ) : null} - + + 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) + ) + ) + } + /> ))} @@ -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 = ( + + + + + + {user.name} + + {user.isAdmin ? ( + + Admin + + ) : null} + + + {user.email} + + + + ) + 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 ( + ( + + {actions.map((action) => ( + { + swipeable.close() + action.onPress() + }} + style={[styles.swipeAction, { backgroundColor: action.color }]} + > + + + {action.label} + + + ))} + + )} + > + {row} + + ) +} + function SessionSection({ onChangeServer, onSignOut, @@ -918,22 +999,36 @@ function GroupTitle({ {title} - {/* 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 ? {action} : null} ) } -/** 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 ( {Children.toArray(children).map((row, index) => ( - + {index > 0 ? ( ) : 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 ( diff --git a/apps/mobile/components/add-button.tsx b/apps/mobile/components/add-button.tsx index 7526704..f001042 100644 --- a/apps/mobile/components/add-button.tsx +++ b/apps/mobile/components/add-button.tsx @@ -20,7 +20,7 @@ export function AddButton({ onPress={onPress} style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })} > - + ) }