diff --git a/apps/mobile/app/(app)/(tabs)/home/settings.tsx b/apps/mobile/app/(app)/(tabs)/home/settings.tsx index 4118351..399ff80 100644 --- a/apps/mobile/app/(app)/(tabs)/home/settings.tsx +++ b/apps/mobile/app/(app)/(tabs)/home/settings.tsx @@ -3,9 +3,10 @@ import { Ionicons } from "@expo/vector-icons" import { useAction, useMutation, useQuery } from "convex/react" import { Image } from "expo-image" import * as ImagePicker from "expo-image-picker" -import { useEffect, useMemo, useState } from "react" +import { Children, useEffect, useMemo, useState } from "react" import { router } from "expo-router" import { + ActivityIndicator, Alert, Platform, Pressable, @@ -15,10 +16,13 @@ import { Text, View, } from "react-native" -import type { StyleProp, ViewStyle } from "react-native" +import ReanimatedSwipeable, { + type SwipeableMethods, +} from "react-native-gesture-handler/ReanimatedSwipeable" +import { useSafeAreaInsets } from "react-native-safe-area-context" +import { AddButton } from "@/components/add-button" import { AudioFormatBadge } from "@/components/audio-format-badge" -import { contentBottomInset } from "@/components/player" import { useDownloads, useDownloadsVersion } from "@/contexts/downloads" import { readRememberedDownloadQuality, @@ -31,7 +35,7 @@ import { formatBytes, type DownloadQuality, } from "@otunes/convex/download-quality" -import { Button, 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 { @@ -49,7 +53,12 @@ import type { PlaybackQuality } from "@otunes/convex/playback-stream" import { api } from "@otunes/convex/_generated/api" import type { Id } from "@otunes/convex/_generated/dataModel" -type Section = "profile" | "quality" | "downloads" | "library" | "users" +type IconName = React.ComponentProps["name"] + +/** iOS system blue, used for the swipe-to-admin action. */ +const SWIPE_ADMIN_BLUE = "#0A84FF" + +type Section = "profile" | "quality" | "downloads" | "admin" type CurrentUser = { _id: Id<"users"> @@ -71,7 +80,7 @@ type AdminUser = { type SectionConfig = { id: Section label: string - icon: React.ComponentProps["name"] + icon: IconName admin?: boolean } @@ -87,22 +96,44 @@ const QUALITY_OPTIONS: { ] const SECTIONS: SectionConfig[] = [ - { id: "profile", label: "Profile", icon: "person-circle-outline" }, - { id: "quality", label: "Playback", icon: "volume-high-outline" }, - { id: "downloads", label: "Downloads", icon: "arrow-down-circle-outline" }, - { id: "library", label: "Library", icon: "library-outline", admin: true }, - { id: "users", label: "Users", icon: "people-outline", admin: true }, + { + id: "profile", + label: "Profile", + icon: "person-circle-outline", + }, + { + id: "quality", + label: "Playback", + icon: "volume-high-outline", + }, + { + id: "downloads", + label: "Downloads", + icon: "arrow-down-circle-outline", + }, + { + id: "admin", + label: "Admin", + icon: "shield-outline", + admin: true, + }, ] +/** + * Settings, presented as a full-height modal: a title bar with a close + * button (native header on iOS), the active section's content, and a pill + * section switcher at the bottom. + */ export default function SettingsScreen() { const colors = useThemeColors() + const insets = useSafeAreaInsets() const user = useCachedQuery(api.auth.currentUser) const { invalidateSession } = useInvalidateAuthSession() const { clearServer } = useServerConfig() const [section, setSection] = useState
("profile") const allUsers = useQuery( api.users.listUsers, - user?.isAdmin === true && section === "users" ? {} : "skip" + user?.isAdmin === true && section === "admin" ? {} : "skip" ) if (!user) { @@ -129,61 +160,96 @@ export default function SettingsScreen() { } return ( - - - {visibleSections.map((item) => { - const selected = section === item.id - return ( - setSection(item.id)} - style={[ - styles.pill, - { backgroundColor: selected ? colors.primary : "transparent" }, - ]} - > - - - ) - })} + {/* iOS shows the native header from the stack layout instead. */} + {Platform.OS === "ios" ? null : ( + + + Settings + + router.back()} + /> + + )} + + + {section === "profile" ? ( + <> + + + void handleChangeServer()} + onSignOut={() => void handleSignOut()} + /> + + ) : null} + {section === "quality" ? : null} + {section === "downloads" ? : null} + {section === "admin" && isAdmin ? ( + <> + + {allUsers ? ( + + ) : null} + + ) : null} + + + + + {visibleSections.map((item) => { + const selected = section === item.id + return ( + setSection(item.id)} + style={[ + styles.pill, + { + backgroundColor: selected ? colors.primary : "transparent", + }, + ]} + > + + + ) + })} + - - {section === "profile" ? ( - <> - - - - ) : null} - {section === "quality" ? : null} - {section === "downloads" ? : null} - {section === "library" && isAdmin ? : null} - {section === "users" && isAdmin && allUsers ? ( - - ) : null} - - {section === "profile" ? ( - void handleChangeServer()} - onSignOut={() => void handleSignOut()} - /> - ) : null} - + ) } @@ -192,39 +258,32 @@ function AppearanceSection() { const [saving, setSaving] = useState(false) return ( - - { - setSaving(true) - try { - await setArtworkColorsEnabled(checked) - clearCoverPaletteCache() - } catch { - showError("Could not save artwork colors preference.") - } finally { - setSaving(false) - } - }} - /> - + + + { + setSaving(true) + try { + await setArtworkColorsEnabled(checked) + clearCoverPaletteCache() + } catch { + showError("Could not save artwork colors preference.") + } finally { + setSaving(false) + } + }} + /> + + ) } 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({ @@ -256,194 +315,81 @@ 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 ( - <> - - - - -