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..893a6c7 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,17 @@ export default function HomeLayout() { screenOptions={({ route }) => ({ ...baseOptions, title: tabStackScreenTitles[route.name] ?? "Home", + headerRight: route.name === "settings" ? undefined : () => , + unstable_headerRightItems: + route.name === "settings" + ? undefined + : () => [ + { + type: "custom", + element: , + hidesSharedBackground: true, + }, + ], })} /> ) diff --git a/apps/mobile/app/(app)/(tabs)/home/settings.tsx b/apps/mobile/app/(app)/(tabs)/home/settings.tsx index 8063d66..7324595 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,54 +67,65 @@ 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)} - style={[ - styles.tab, - { - backgroundColor: - section === item.id ? colors.foreground : colors.muted, - }, - ]} - > - - {item.label} - - - ))} - + + {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 === "library" && isAdmin ? : null} - {section === "users" && isAdmin && allUsers ? ( - - ) : null} - + {section === "profile" ? : null} + {section === "quality" ? : null} + {section === "library" && isAdmin ? : null} + {section === "users" && isAdmin && allUsers ? ( + + ) : null} + + {section === "profile" ? ( + void handleChangeServer()} + onSignOut={() => void handleSignOut()} + /> + ) : null} ) } @@ -114,6 +149,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 +159,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 +188,95 @@ function ProfileSection({ user }: { user: Doc<"users"> }) { } return ( - - - - {initialsFromName(user.name)} - - -