From 39b80071049e693a0883def8cd9a73f2ea102146 Mon Sep 17 00:00:00 2001 From: Rem Helper Date: Mon, 6 Jul 2026 02:27:08 +0000 Subject: [PATCH] Redesign mobile settings and add profile header entry - Move profile access into the tab stack header - Replace the old More tab with a richer settings screen - Add session, account, playback, and admin management sections --- apps/mobile/app/(app)/(tabs)/_layout.tsx | 11 - apps/mobile/app/(app)/(tabs)/home/_layout.tsx | 2 + .../mobile/app/(app)/(tabs)/home/settings.tsx | 827 ++++++++++++++---- .../app/(app)/(tabs)/library/_layout.tsx | 2 + apps/mobile/app/(app)/(tabs)/more/_layout.tsx | 7 - apps/mobile/app/(app)/(tabs)/more/index.tsx | 137 --- .../app/(app)/(tabs)/search/_layout.tsx | 2 + .../components/profile-header-button.tsx | 65 ++ 8 files changed, 707 insertions(+), 346 deletions(-) delete mode 100644 apps/mobile/app/(app)/(tabs)/more/_layout.tsx delete mode 100644 apps/mobile/app/(app)/(tabs)/more/index.tsx create mode 100644 apps/mobile/components/profile-header-button.tsx diff --git a/apps/mobile/app/(app)/(tabs)/_layout.tsx b/apps/mobile/app/(app)/(tabs)/_layout.tsx index 6620e89..efee656 100644 --- a/apps/mobile/app/(app)/(tabs)/_layout.tsx +++ b/apps/mobile/app/(app)/(tabs)/_layout.tsx @@ -116,17 +116,6 @@ export default function TabsLayout() { Search - - - - More - ) diff --git a/apps/mobile/app/(app)/(tabs)/home/_layout.tsx b/apps/mobile/app/(app)/(tabs)/home/_layout.tsx index 438f058..19de5fc 100644 --- a/apps/mobile/app/(app)/(tabs)/home/_layout.tsx +++ b/apps/mobile/app/(app)/(tabs)/home/_layout.tsx @@ -1,5 +1,6 @@ import { Stack } from "expo-router" +import { ProfileHeaderButton } from "@/components/profile-header-button" import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation" export const unstable_settings = { @@ -15,6 +16,7 @@ export default function HomeLayout() { screenOptions={({ route }) => ({ ...baseOptions, title: tabStackScreenTitles[route.name] ?? "Home", + headerRight: route.name === "settings" ? undefined : () => , })} /> ) diff --git a/apps/mobile/app/(app)/(tabs)/home/settings.tsx b/apps/mobile/app/(app)/(tabs)/home/settings.tsx index 8063d66..6764a4f 100644 --- a/apps/mobile/app/(app)/(tabs)/home/settings.tsx +++ b/apps/mobile/app/(app)/(tabs)/home/settings.tsx @@ -1,5 +1,8 @@ +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 { useRouter } from "expo-router" import { useState } from "react" import { Pressable, @@ -9,17 +12,28 @@ import { Text, View, } from "react-native" +import type { StyleProp, ViewStyle } from "react-native" -import { Button, Input, LoadingView } from "@/components/ui/primitives" import { contentBottomInset } from "@/components/player" -import { api } from "@otunes/convex/_generated/api" -import type { Doc, Id } from "@otunes/convex/_generated/dataModel" +import { Button, Input, LoadingView } from "@/components/ui/primitives" +import { useInvalidateAuthSession } from "@/contexts/convex-auth-session" +import { useServerConfig } from "@/contexts/server-config" import { initialsFromName } from "@/lib/format" +import { signOutToSignIn } from "@/lib/session" +import { radius, spacing, useThemeColors } from "@/lib/theme" import { showError, showSuccess } from "@/lib/toast" import type { PlaybackQuality } from "@/lib/urls" -import { radius, spacing, useThemeColors } from "@/lib/theme" +import { api } from "@otunes/convex/_generated/api" +import type { Doc, Id } from "@otunes/convex/_generated/dataModel" -type Section = "profile" | "quality" | "users" | "library" +type Section = "profile" | "quality" | "library" | "users" + +type SectionConfig = { + id: Section + label: string + icon: React.ComponentProps["name"] + admin?: boolean +} const QUALITY_OPTIONS: { value: PlaybackQuality @@ -32,10 +46,20 @@ const QUALITY_OPTIONS: { { value: "lossless", label: "Lossless", description: "ALAC or FLAC" }, ] +const SECTIONS: SectionConfig[] = [ + { id: "profile", label: "Profile", icon: "person-circle-outline" }, + { id: "quality", label: "Playback", icon: "volume-high-outline" }, + { id: "library", label: "Library", icon: "library-outline", admin: true }, + { id: "users", label: "Users", icon: "people-outline", admin: true }, +] + export default function SettingsScreen() { const colors = useThemeColors() + const router = useRouter() const user = useQuery(api.auth.currentUser) const allUsers = useQuery(api.users.listUsers) + const { invalidateSession } = useInvalidateAuthSession() + const { clearServer } = useServerConfig() const [section, setSection] = useState
("profile") if (!user) { @@ -43,58 +67,99 @@ export default function SettingsScreen() { } const isAdmin = user.isAdmin === true - const sections: { id: Section; label: string; admin?: boolean }[] = [ - { id: "profile", label: "Profile" }, - { id: "quality", label: "Quality" }, - { id: "library", label: "Library", admin: true }, - { id: "users", label: "Users", admin: true }, - ] + const visibleSections = SECTIONS.filter((item) => !item.admin || isAdmin) + + async function handleSignOut() { + await signOutToSignIn(router, invalidateSession) + } + + async function handleChangeServer() { + await invalidateSession() + await clearServer() + router.replace("/server") + } return ( - - {sections - .filter((item) => !item.admin || isAdmin) - .map((item) => ( - setSection(item.id)} + + + + {visibleSections.map((item) => { + const selected = section === item.id + return ( + setSection(item.id)} + style={[ + styles.pill, + { backgroundColor: selected ? colors.primary : "transparent" }, + ]} + > + + - - {item.label} - - - ))} - + {item.label} + + + ) + })} + - - {section === "profile" ? : null} - {section === "quality" ? : null} - {section === "library" && isAdmin ? : null} - {section === "users" && isAdmin && allUsers ? ( - - ) : null} - + {section === "profile" ? : null} + {section === "quality" ? : null} + {section === "library" && isAdmin ? : null} + {section === "users" && isAdmin && allUsers ? ( + + ) : null} + + void handleChangeServer()} + onSignOut={() => void handleSignOut()} + /> ) } +function AccountHero({ user }: { user: Doc<"users"> }) { + const colors = useThemeColors() + + return ( + + + + + {user.name} + + + {user.email} + + {user.isAdmin ? ( + + Admin + + ) : null} + + + ) +} + function ProfileSection({ user }: { user: Doc<"users"> }) { const colors = useThemeColors() const updateName = useMutation(api.users.updateProfileName) @@ -114,6 +179,7 @@ function ProfileSection({ user }: { user: Doc<"users"> }) { base64: true, }) if (result.canceled || !result.assets[0]?.base64) return + const mime = result.assets[0].mimeType ?? "image/jpeg" try { await updateImage({ image: `data:${mime};base64,${result.assets[0].base64}` }) @@ -123,11 +189,21 @@ function ProfileSection({ user }: { user: Doc<"users"> }) { } } + async function removeImage() { + try { + await updateImage({ image: null }) + showSuccess("Profile photo removed") + } catch (error) { + showError(error instanceof Error ? error.message : "Failed to remove photo") + } + } + async function handlePasswordChange() { if (newPassword !== confirmPassword) { showError("Passwords do not match") return } + setChangingPassword(true) try { await updatePassword({ newPassword }) @@ -142,53 +218,95 @@ function ProfileSection({ user }: { user: Doc<"users"> }) { } return ( - - - - {initialsFromName(user.name)} - - -