feat(mobile): split user swipe actions by direction

Swipe right to toggle admin (blue) and left to delete. Actions are
icon only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
joshuafhigginsandClaude Opus 5.5 committed 2026-11-20 10:25:34 -05:00
1 parent 1c22639527
commit 6ed2c16efa
1 file changed
+47 -48
+47 -48
View File
@@ -16,7 +16,9 @@ import {
Text,
View,
} from "react-native"
import ReanimatedSwipeable from "react-native-gesture-handler/ReanimatedSwipeable"
import ReanimatedSwipeable, {
type SwipeableMethods,
} from "react-native-gesture-handler/ReanimatedSwipeable"
import { useSafeAreaInsets } from "react-native-safe-area-context"
import { AddButton } from "@/components/add-button"
@@ -45,7 +47,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 { appleMusic, radius, spacing, useThemeColors } from "@/lib/theme"
import { 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"
@@ -53,6 +55,9 @@ import type { Id } from "@otunes/convex/_generated/dataModel"
type IconName = React.ComponentProps<typeof Ionicons>["name"]
/** iOS system blue, used for the swipe-to-admin action. */
const SWIPE_ADMIN_BLUE = "#0A84FF"
type Section = "profile" | "quality" | "downloads" | "admin"
type CurrentUser = {
@@ -829,8 +834,8 @@ function UsersSection({
}
/**
* A person in the admin list. Swiping left reveals admin and delete actions;
* both ask for confirmation through the handlers.
* A person in the admin list. Swiping right reveals the admin toggle and
* swiping left reveals delete; both ask for confirmation through the handlers.
*/
function UserRow({
user,
@@ -876,52 +881,51 @@ function UserRow({
)
if (!swipeable) return row
const actions: {
label: string
icon: IconName
color: string
// Icon-only actions: swipe right to toggle admin, left to delete.
function renderAction(
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 (
_progress: unknown,
_translation: unknown,
swipeable: SwipeableMethods
) => (
<Pressable
accessibilityRole="button"
accessibilityLabel={`${label}: ${user.name}`}
onPress={() => {
swipeable.close()
onPress()
}}
style={[styles.swipeAction, { backgroundColor: color }]}
>
<Ionicons name={icon} size={24} color="#fff" />
</Pressable>
)
}
return (
<ReanimatedSwipeable
friction={2}
leftThreshold={40}
rightThreshold={40}
overshootLeft={false}
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>
renderLeftActions={renderAction(
user.isAdmin ? "Remove Admin" : "Make Admin",
user.isAdmin ? "shield-outline" : "shield-checkmark",
SWIPE_ADMIN_BLUE,
onToggleAdmin
)}
renderRightActions={renderAction(
"Delete",
"trash",
colors.destructive,
onDelete
)}
>
{row}
@@ -1325,14 +1329,9 @@ const styles = StyleSheet.create({
marginHorizontal: spacing.lg,
},
swipeAction: {
width: 96,
width: 72,
alignItems: "center",
justifyContent: "center",
gap: 4,
},
swipeActionText: {
fontSize: 13,
fontWeight: "600",
},
groupFooter: {
fontSize: 13,