feat(mobile): profile tab into modal (#14)
--------- Co-authored-by: Rem Helper <remhelper@abunchofknowitalls.com> Reviewed-on: https://git.abunchofknowitalls.com/joshuafhiggins/otunes/pulls/14
This commit is contained in:
1 parent
d99a888ab9
commit
ade451a63c
10 files changed
+688
-341
No files matched your search
@@ -116,17 +116,6 @@ export default function TabsLayout() {
|
||||
<NativeTabs.Trigger.Icon sf="magnifyingglass" md="search" />
|
||||
<NativeTabs.Trigger.Label>Search</NativeTabs.Trigger.Label>
|
||||
</NativeTabs.Trigger>
|
||||
|
||||
<NativeTabs.Trigger name="more" disableTransparentOnScrollEdge>
|
||||
<NativeTabs.Trigger.Icon
|
||||
sf={{
|
||||
default: "ellipsis.circle",
|
||||
selected: "ellipsis.circle.fill",
|
||||
}}
|
||||
md="more_horiz"
|
||||
/>
|
||||
<NativeTabs.Trigger.Label>More</NativeTabs.Trigger.Label>
|
||||
</NativeTabs.Trigger>
|
||||
</NativeTabs>
|
||||
</ThemeProvider>
|
||||
)
|
||||
|
||||
@@ -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 : () => <ProfileHeaderButton />,
|
||||
unstable_headerRightItems:
|
||||
route.name === "settings"
|
||||
? undefined
|
||||
: () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
],
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -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<typeof Ionicons>["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<Section>("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 (
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentContainerStyle={[
|
||||
styles.container,
|
||||
{ paddingBottom: contentBottomInset + spacing.xl },
|
||||
]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} style={styles.tabs}>
|
||||
{sections
|
||||
.filter((item) => !item.admin || isAdmin)
|
||||
.map((item) => (
|
||||
<Pressable
|
||||
key={item.id}
|
||||
onPress={() => setSection(item.id)}
|
||||
style={[
|
||||
styles.tab,
|
||||
{
|
||||
backgroundColor:
|
||||
section === item.id ? colors.foreground : colors.muted,
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
color: section === item.id ? colors.background : colors.foreground,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
>
|
||||
{item.label}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
<View style={[styles.pillGroup, { backgroundColor: colors.card }]}>
|
||||
{visibleSections.map((item) => {
|
||||
const selected = section === item.id
|
||||
return (
|
||||
<Pressable
|
||||
key={item.id}
|
||||
accessibilityLabel={item.label}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
onPress={() => setSection(item.id)}
|
||||
style={[
|
||||
styles.pill,
|
||||
{ backgroundColor: selected ? colors.primary : "transparent" },
|
||||
]}
|
||||
>
|
||||
<Ionicons
|
||||
name={item.icon}
|
||||
size={26}
|
||||
color={selected ? colors.primaryForeground : colors.mutedForeground}
|
||||
/>
|
||||
</Pressable>
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
|
||||
<View style={styles.content}>
|
||||
{section === "profile" ? <ProfileSection user={user} /> : null}
|
||||
{section === "quality" ? <QualitySection user={user} /> : null}
|
||||
{section === "library" && isAdmin ? <LibrarySection /> : null}
|
||||
{section === "users" && isAdmin && allUsers ? (
|
||||
<UsersSection users={allUsers} currentUserId={user._id} />
|
||||
) : null}
|
||||
</View>
|
||||
{section === "profile" ? <ProfileSection user={user} /> : null}
|
||||
{section === "quality" ? <QualitySection user={user} /> : null}
|
||||
{section === "library" && isAdmin ? <LibrarySection /> : null}
|
||||
{section === "users" && isAdmin && allUsers ? (
|
||||
<UsersSection users={allUsers} currentUserId={user._id} />
|
||||
) : null}
|
||||
|
||||
{section === "profile" ? (
|
||||
<SessionSection
|
||||
onChangeServer={() => void handleChangeServer()}
|
||||
onSignOut={() => void handleSignOut()}
|
||||
/>
|
||||
) : null}
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
@@ -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 (
|
||||
<View style={styles.sectionBlock}>
|
||||
<View style={[styles.avatar, { backgroundColor: colors.muted }]}>
|
||||
<Text style={{ color: colors.foreground, fontWeight: "700", fontSize: 20 }}>
|
||||
{initialsFromName(user.name)}
|
||||
</Text>
|
||||
</View>
|
||||
<Button title="Upload profile photo" variant="secondary" onPress={() => void pickImage()} />
|
||||
{user.image ? (
|
||||
<Button title="Remove photo" variant="ghost" onPress={() => void updateImage({ image: null })} />
|
||||
) : null}
|
||||
<Input value={name} onChangeText={setName} placeholder="Name" />
|
||||
<Button
|
||||
title="Save name"
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void updateName({ name }).catch((error: Error) => showError(error.message))
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
value={email}
|
||||
onChangeText={setEmail}
|
||||
placeholder="Email"
|
||||
autoCapitalize="none"
|
||||
keyboardType="email-address"
|
||||
/>
|
||||
<Button
|
||||
title="Save email"
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void updateEmail({ email }).catch((error: Error) => showError(error.message))
|
||||
}
|
||||
/>
|
||||
<Text style={[styles.sectionTitle, { color: colors.foreground }]}>Password</Text>
|
||||
<Input value={newPassword} onChangeText={setNewPassword} placeholder="New password" secureTextEntry />
|
||||
<Input
|
||||
value={confirmPassword}
|
||||
onChangeText={setConfirmPassword}
|
||||
placeholder="Confirm password"
|
||||
secureTextEntry
|
||||
/>
|
||||
<Button
|
||||
title="Update password"
|
||||
loading={changingPassword}
|
||||
disabled={!newPassword || newPassword !== confirmPassword}
|
||||
onPress={() => void handlePasswordChange()}
|
||||
/>
|
||||
</View>
|
||||
<>
|
||||
<SettingsCard
|
||||
title="Profile Photo"
|
||||
subtitle="This is the avatar shown in the app header and shared spaces."
|
||||
>
|
||||
<View style={styles.photoRow}>
|
||||
<ProfileAvatar user={user} size={76} />
|
||||
<View style={styles.photoActions}>
|
||||
<Button
|
||||
title="Choose Photo"
|
||||
variant="secondary"
|
||||
icon="image-outline"
|
||||
onPress={() => void pickImage()}
|
||||
/>
|
||||
{user.image ? (
|
||||
<Button
|
||||
title="Remove"
|
||||
variant="ghost"
|
||||
icon="trash-outline"
|
||||
onPress={() => void removeImage()}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
</SettingsCard>
|
||||
|
||||
<SettingsCard title="Account Details" subtitle="Keep your profile information up to date.">
|
||||
<Field label="Name">
|
||||
<Input value={name} onChangeText={setName} placeholder="Name" />
|
||||
</Field>
|
||||
<Button
|
||||
title="Save Name"
|
||||
variant="secondary"
|
||||
disabled={name.trim() === user.name}
|
||||
onPress={() =>
|
||||
void updateName({ name: name.trim() }).then(
|
||||
() => showSuccess("Name updated"),
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<View style={[styles.divider, { backgroundColor: colors.border }]} />
|
||||
<Field label="Email">
|
||||
<Input
|
||||
value={email}
|
||||
onChangeText={setEmail}
|
||||
placeholder="Email"
|
||||
autoCapitalize="none"
|
||||
keyboardType="email-address"
|
||||
/>
|
||||
</Field>
|
||||
<Button
|
||||
title="Save Email"
|
||||
variant="secondary"
|
||||
disabled={email.trim() === user.email}
|
||||
onPress={() =>
|
||||
void updateEmail({ email: email.trim() }).then(
|
||||
() => showSuccess("Email updated"),
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</SettingsCard>
|
||||
|
||||
<SettingsCard title="Password" subtitle="Choose a new password for this account.">
|
||||
<Field label="New Password">
|
||||
<Input
|
||||
value={newPassword}
|
||||
onChangeText={setNewPassword}
|
||||
placeholder="New password"
|
||||
secureTextEntry
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Confirm Password">
|
||||
<Input
|
||||
value={confirmPassword}
|
||||
onChangeText={setConfirmPassword}
|
||||
placeholder="Confirm password"
|
||||
secureTextEntry
|
||||
/>
|
||||
</Field>
|
||||
<Button
|
||||
title="Update Password"
|
||||
loading={changingPassword}
|
||||
disabled={!newPassword || newPassword !== confirmPassword}
|
||||
onPress={() => void handlePasswordChange()}
|
||||
/>
|
||||
</SettingsCard>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -199,32 +287,49 @@ function QualitySection({ user }: { user: Doc<"users"> }) {
|
||||
const quality = user.playbackQuality ?? "medium"
|
||||
|
||||
return (
|
||||
<View style={styles.sectionBlock}>
|
||||
{QUALITY_OPTIONS.map((option) => (
|
||||
<Pressable
|
||||
key={option.value}
|
||||
style={[
|
||||
styles.qualityRow,
|
||||
{
|
||||
borderColor: colors.border,
|
||||
backgroundColor: quality === option.value ? colors.muted : colors.card,
|
||||
},
|
||||
]}
|
||||
onPress={() =>
|
||||
void updateQuality({ playbackQuality: option.value }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
>
|
||||
<Text style={{ color: colors.foreground, fontWeight: "600" }}>{option.label}</Text>
|
||||
<Text style={{ color: colors.mutedForeground }}>{option.description}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
<View style={[styles.switchRow, { borderColor: colors.border }]}>
|
||||
<Text style={{ color: colors.foreground, flex: 1 }}>
|
||||
Prefer Dolby Atmos when available
|
||||
</Text>
|
||||
<Switch
|
||||
<>
|
||||
<SettingsCard
|
||||
title="Streaming Quality"
|
||||
subtitle="Pick the default audio quality for playback."
|
||||
>
|
||||
{QUALITY_OPTIONS.map((option) => {
|
||||
const selected = quality === option.value
|
||||
return (
|
||||
<Pressable
|
||||
key={option.value}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
onPress={() =>
|
||||
void updateQuality({ playbackQuality: option.value }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
style={[
|
||||
styles.optionRow,
|
||||
{
|
||||
borderColor: selected ? colors.primary : colors.border,
|
||||
backgroundColor: selected ? colors.muted : colors.card,
|
||||
},
|
||||
]}
|
||||
>
|
||||
<View style={styles.optionCopy}>
|
||||
<Text style={[styles.optionTitle, { color: colors.foreground }]}>
|
||||
{option.label}
|
||||
</Text>
|
||||
<Text style={{ color: colors.mutedForeground }}>{option.description}</Text>
|
||||
</View>
|
||||
{selected ? (
|
||||
<Ionicons name="checkmark-circle" size={22} color={colors.primary} />
|
||||
) : null}
|
||||
</Pressable>
|
||||
)
|
||||
})}
|
||||
</SettingsCard>
|
||||
|
||||
<SettingsCard title="Spatial Audio">
|
||||
<SwitchRow
|
||||
title="Prefer Dolby Atmos"
|
||||
subtitle="Use Atmos versions when they are available."
|
||||
value={user.preferAtmos ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void updateAtmos({ preferAtmos: checked }).catch((error: Error) =>
|
||||
@@ -232,8 +337,8 @@ function QualitySection({ user }: { user: Doc<"users"> }) {
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</SettingsCard>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -244,9 +349,13 @@ function LibrarySection() {
|
||||
const [cleaningHls, setCleaningHls] = useState(false)
|
||||
|
||||
return (
|
||||
<View style={styles.sectionBlock}>
|
||||
<SettingsCard
|
||||
title="Library Maintenance"
|
||||
subtitle="Run administrative jobs for the shared music library."
|
||||
>
|
||||
<Button
|
||||
title="Update library"
|
||||
title="Update Library"
|
||||
icon="refresh-outline"
|
||||
loading={updating}
|
||||
onPress={async () => {
|
||||
setUpdating(true)
|
||||
@@ -261,8 +370,9 @@ function LibrarySection() {
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
title="Clean HLS streams"
|
||||
title="Clean HLS Streams"
|
||||
variant="secondary"
|
||||
icon="sparkles-outline"
|
||||
loading={cleaningHls}
|
||||
onPress={async () => {
|
||||
setCleaningHls(true)
|
||||
@@ -276,7 +386,7 @@ function LibrarySection() {
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
</SettingsCard>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -294,10 +404,11 @@ function UsersSection({
|
||||
const deleteUserMutation = useMutation(api.users.deleteUser)
|
||||
|
||||
return (
|
||||
<View style={styles.sectionBlock}>
|
||||
<View style={[styles.switchRow, { borderColor: colors.border }]}>
|
||||
<Text style={{ color: colors.foreground, flex: 1 }}>Disable account creation</Text>
|
||||
<Switch
|
||||
<>
|
||||
<SettingsCard title="Sign Up">
|
||||
<SwitchRow
|
||||
title="Disable account creation"
|
||||
subtitle="Prevent new users from creating accounts."
|
||||
value={appSettings?.disableAccountCreation ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void setDisableCreation({ disabled: checked }).catch((error: Error) =>
|
||||
@@ -305,84 +416,363 @@ function UsersSection({
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
{users.map((user) => (
|
||||
<View key={user._id} style={[styles.userRow, { borderColor: colors.border }]}>
|
||||
<View style={{ flex: 1 }}>
|
||||
<Text style={{ color: colors.foreground, fontWeight: "600" }}>{user.name}</Text>
|
||||
<Text style={{ color: colors.mutedForeground }}>{user.email}</Text>
|
||||
{user.isAdmin ? (
|
||||
<Text style={{ color: colors.mutedForeground }}>Admin</Text>
|
||||
</SettingsCard>
|
||||
|
||||
<SettingsCard title="People" subtitle="Manage who can access this server.">
|
||||
{users.map((user, index) => (
|
||||
<View key={user._id}>
|
||||
{index > 0 ? (
|
||||
<View style={[styles.divider, { backgroundColor: colors.border }]} />
|
||||
) : null}
|
||||
<View style={styles.userRow}>
|
||||
<ProfileAvatar user={user} size={44} />
|
||||
<View style={styles.userCopy}>
|
||||
<View style={styles.userNameRow}>
|
||||
<Text style={[styles.userName, { color: colors.foreground }]} numberOfLines={1}>
|
||||
{user.name}
|
||||
</Text>
|
||||
{user.isAdmin ? (
|
||||
<View style={[styles.badge, { backgroundColor: colors.muted }]}>
|
||||
<Text style={[styles.badgeText, { color: colors.mutedForeground }]}>
|
||||
Admin
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
<Text style={{ color: colors.mutedForeground }} numberOfLines={1}>
|
||||
{user.email}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
{user._id !== currentUserId ? (
|
||||
<View style={styles.userActions}>
|
||||
<Button
|
||||
title={user.isAdmin ? "Remove Admin" : "Make Admin"}
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void setAdmin({ userId: user._id, isAdmin: !user.isAdmin }).then(
|
||||
() => showSuccess("Updated permissions"),
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
style={styles.userActionButton}
|
||||
/>
|
||||
<Button
|
||||
title="Delete"
|
||||
variant="destructive"
|
||||
onPress={() =>
|
||||
void deleteUserMutation({ userId: user._id }).then(
|
||||
() => showSuccess("User deleted"),
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
style={styles.userActionButton}
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
{user._id !== currentUserId ? (
|
||||
<View style={styles.userActions}>
|
||||
<Button
|
||||
title={user.isAdmin ? "Remove admin" : "Make admin"}
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void setAdmin({ userId: user._id, isAdmin: !user.isAdmin }).then(() =>
|
||||
showSuccess("Updated permissions")
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
title="Delete"
|
||||
variant="destructive"
|
||||
onPress={() =>
|
||||
void deleteUserMutation({ userId: user._id }).then(() =>
|
||||
showSuccess("User deleted")
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
))}
|
||||
))}
|
||||
</SettingsCard>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function SessionSection({
|
||||
onChangeServer,
|
||||
onSignOut,
|
||||
}: {
|
||||
onChangeServer: () => void
|
||||
onSignOut: () => void
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
|
||||
return (
|
||||
<SettingsCard title="Session">
|
||||
<ActionRow
|
||||
icon="server-outline"
|
||||
title="Change Server"
|
||||
subtitle="Disconnect from this server and choose another."
|
||||
onPress={onChangeServer}
|
||||
/>
|
||||
<View style={[styles.divider, { backgroundColor: colors.border }]} />
|
||||
<ActionRow
|
||||
icon="log-out-outline"
|
||||
title="Sign Out"
|
||||
subtitle="Return to the sign-in screen."
|
||||
destructive
|
||||
onPress={onSignOut}
|
||||
/>
|
||||
</SettingsCard>
|
||||
)
|
||||
}
|
||||
|
||||
function SettingsCard({
|
||||
title,
|
||||
subtitle,
|
||||
children,
|
||||
}: {
|
||||
title: string
|
||||
subtitle?: string
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
|
||||
return (
|
||||
<View style={[styles.card, { backgroundColor: colors.card }]}>
|
||||
<View style={styles.cardHeader}>
|
||||
<Text style={[styles.cardTitle, { color: colors.foreground }]}>{title}</Text>
|
||||
{subtitle ? (
|
||||
<Text style={[styles.cardSubtitle, { color: colors.mutedForeground }]}>{subtitle}</Text>
|
||||
) : null}
|
||||
</View>
|
||||
{children}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function Field({ label, children }: { label: string; children: React.ReactNode }) {
|
||||
const colors = useThemeColors()
|
||||
|
||||
return (
|
||||
<View style={styles.field}>
|
||||
<Text style={[styles.fieldLabel, { color: colors.mutedForeground }]}>{label}</Text>
|
||||
{children}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function SwitchRow({
|
||||
title,
|
||||
subtitle,
|
||||
value,
|
||||
onValueChange,
|
||||
}: {
|
||||
title: string
|
||||
subtitle?: string
|
||||
value: boolean
|
||||
onValueChange: (checked: boolean) => void
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
|
||||
return (
|
||||
<View style={styles.switchRow}>
|
||||
<View style={styles.optionCopy}>
|
||||
<Text style={[styles.optionTitle, { color: colors.foreground }]}>{title}</Text>
|
||||
{subtitle ? <Text style={{ color: colors.mutedForeground }}>{subtitle}</Text> : null}
|
||||
</View>
|
||||
<Switch value={value} onValueChange={onValueChange} />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function ActionRow({
|
||||
icon,
|
||||
title,
|
||||
subtitle,
|
||||
destructive,
|
||||
onPress,
|
||||
}: {
|
||||
icon: React.ComponentProps<typeof Ionicons>["name"]
|
||||
title: string
|
||||
subtitle: string
|
||||
destructive?: boolean
|
||||
onPress: () => void
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
const tint = destructive ? colors.destructive : colors.foreground
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => [styles.actionRow, { opacity: pressed ? 0.75 : 1 }]}
|
||||
>
|
||||
<View style={[styles.actionIcon, { backgroundColor: colors.muted }]}>
|
||||
<Ionicons name={icon} size={20} color={tint} />
|
||||
</View>
|
||||
<View style={styles.optionCopy}>
|
||||
<Text style={[styles.optionTitle, { color: tint }]}>{title}</Text>
|
||||
<Text style={{ color: colors.mutedForeground }}>{subtitle}</Text>
|
||||
</View>
|
||||
<Ionicons name="chevron-forward" size={18} color={colors.mutedForeground} />
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
function ProfileAvatar({
|
||||
user,
|
||||
size,
|
||||
style,
|
||||
}: {
|
||||
user: Pick<Doc<"users">, "name" | "image">
|
||||
size: number
|
||||
style?: StyleProp<ViewStyle>
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
const avatarStyle = [
|
||||
styles.avatar,
|
||||
{
|
||||
width: size,
|
||||
height: size,
|
||||
borderRadius: size / 2,
|
||||
backgroundColor: colors.muted,
|
||||
},
|
||||
style,
|
||||
]
|
||||
|
||||
if (user.image) {
|
||||
return (
|
||||
<View style={avatarStyle}>
|
||||
<Image source={{ uri: user.image }} style={styles.avatarImage} contentFit="cover" />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={avatarStyle}>
|
||||
<Text style={[styles.avatarInitials, { color: colors.foreground, fontSize: size * 0.34 }]}>
|
||||
{initialsFromName(user.name)}
|
||||
</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
tabs: {
|
||||
container: {
|
||||
gap: spacing.lg,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
paddingTop: spacing.md,
|
||||
},
|
||||
tab: {
|
||||
paddingHorizontal: spacing.md,
|
||||
paddingVertical: spacing.sm,
|
||||
badge: {
|
||||
alignSelf: "flex-start",
|
||||
borderRadius: radius.full,
|
||||
marginRight: spacing.sm,
|
||||
paddingHorizontal: spacing.sm,
|
||||
paddingVertical: 2,
|
||||
},
|
||||
content: { paddingHorizontal: spacing.lg },
|
||||
sectionBlock: { gap: spacing.md, paddingBottom: spacing.xl },
|
||||
sectionTitle: { fontSize: 16, fontWeight: "700", marginTop: spacing.md },
|
||||
avatar: {
|
||||
width: 72,
|
||||
height: 72,
|
||||
borderRadius: 36,
|
||||
badgeText: {
|
||||
fontSize: 12,
|
||||
fontWeight: "700",
|
||||
},
|
||||
pillGroup: {
|
||||
borderRadius: radius.xl,
|
||||
padding: spacing.xs,
|
||||
flexDirection: "row",
|
||||
gap: spacing.xs,
|
||||
},
|
||||
pill: {
|
||||
flex: 1,
|
||||
minHeight: 48,
|
||||
borderRadius: radius.full,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
qualityRow: {
|
||||
borderWidth: 1,
|
||||
borderRadius: radius.md,
|
||||
padding: spacing.md,
|
||||
gap: 4,
|
||||
card: {
|
||||
borderRadius: radius.xl,
|
||||
padding: spacing.lg,
|
||||
gap: spacing.md,
|
||||
},
|
||||
cardHeader: {
|
||||
gap: spacing.xs,
|
||||
},
|
||||
cardTitle: {
|
||||
fontSize: 18,
|
||||
fontWeight: "800",
|
||||
},
|
||||
cardSubtitle: {
|
||||
fontSize: 14,
|
||||
lineHeight: 20,
|
||||
},
|
||||
photoRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.lg,
|
||||
},
|
||||
photoActions: {
|
||||
flex: 1,
|
||||
gap: spacing.sm,
|
||||
},
|
||||
field: {
|
||||
gap: spacing.sm,
|
||||
},
|
||||
fieldLabel: {
|
||||
fontSize: 13,
|
||||
fontWeight: "700",
|
||||
textTransform: "uppercase",
|
||||
},
|
||||
divider: {
|
||||
height: StyleSheet.hairlineWidth,
|
||||
},
|
||||
optionRow: {
|
||||
borderWidth: 1,
|
||||
borderRadius: radius.lg,
|
||||
padding: spacing.md,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
},
|
||||
optionCopy: {
|
||||
flex: 1,
|
||||
gap: 3,
|
||||
},
|
||||
optionTitle: {
|
||||
fontSize: 16,
|
||||
fontWeight: "700",
|
||||
},
|
||||
switchRow: {
|
||||
minHeight: 56,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
borderWidth: 1,
|
||||
borderRadius: radius.md,
|
||||
padding: spacing.md,
|
||||
},
|
||||
userRow: {
|
||||
borderWidth: 1,
|
||||
borderRadius: radius.md,
|
||||
padding: spacing.md,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
},
|
||||
userCopy: {
|
||||
flex: 1,
|
||||
gap: 3,
|
||||
},
|
||||
userNameRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.sm,
|
||||
},
|
||||
userActions: { gap: spacing.sm },
|
||||
userName: {
|
||||
flexShrink: 1,
|
||||
fontSize: 16,
|
||||
fontWeight: "700",
|
||||
},
|
||||
userActions: {
|
||||
flexDirection: "row",
|
||||
gap: spacing.sm,
|
||||
marginTop: spacing.md,
|
||||
},
|
||||
userActionButton: {
|
||||
flex: 1,
|
||||
},
|
||||
actionRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
},
|
||||
actionIcon: {
|
||||
width: 36,
|
||||
height: 36,
|
||||
borderRadius: 18,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
avatar: {
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
overflow: "hidden",
|
||||
},
|
||||
avatarImage: {
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
},
|
||||
avatarInitials: {
|
||||
fontWeight: "800",
|
||||
},
|
||||
})
|
||||
@@ -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 LibraryLayout() {
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Library",
|
||||
headerRight: route.name === "settings" ? undefined : () => <ProfileHeaderButton />,
|
||||
unstable_headerRightItems:
|
||||
route.name === "settings"
|
||||
? undefined
|
||||
: () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
],
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { useStackScreenOptions } from "@/lib/navigation"
|
||||
|
||||
export default function MoreLayout() {
|
||||
return <Stack screenOptions={useStackScreenOptions({ title: "More" })} />
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { useRouter } from "expo-router"
|
||||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { useAppNavigation } from "@/lib/app-navigation"
|
||||
import { signOutToSignIn } from "@/lib/session"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { PlaylistSummary } from "@otunes/convex/types"
|
||||
import { initialsFromName } from "@/lib/format"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function MoreScreen() {
|
||||
const router = useRouter()
|
||||
const { push } = useAppNavigation()
|
||||
const colors = useThemeColors()
|
||||
const { invalidateSession } = useInvalidateAuthSession()
|
||||
const { clearServer } = useServerConfig()
|
||||
const user = useQuery(api.auth.currentUser)
|
||||
const sidebarPlaylists = useQuery(api.playlists.listSidebarPlaylists)
|
||||
|
||||
async function handleSignOut() {
|
||||
await signOutToSignIn(router, invalidateSession)
|
||||
}
|
||||
|
||||
async function handleChangeServer() {
|
||||
await invalidateSession()
|
||||
await clearServer()
|
||||
router.replace("/server")
|
||||
}
|
||||
|
||||
const subscribed = sidebarPlaylists?.subscribed ?? []
|
||||
const owned = sidebarPlaylists?.owned ?? []
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<View style={[styles.profileCard, { backgroundColor: colors.muted }]}>
|
||||
<View style={[styles.avatar, { backgroundColor: colors.card }]}>
|
||||
<Text style={{ color: colors.foreground, fontWeight: "700" }}>
|
||||
{initialsFromName(user?.name ?? "NA")}
|
||||
</Text>
|
||||
</View>
|
||||
<View>
|
||||
<Text style={[styles.name, { color: colors.foreground }]}>{user?.name ?? "..."}</Text>
|
||||
<Text style={{ color: colors.mutedForeground }}>{user?.email}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<Pressable style={styles.row} onPress={() => push("/settings")}>
|
||||
<Ionicons name="settings-outline" size={20} color={colors.foreground} />
|
||||
<Text style={[styles.rowText, { color: colors.foreground }]}>Settings</Text>
|
||||
</Pressable>
|
||||
<Pressable style={styles.row} onPress={() => push("/queue")}>
|
||||
<Ionicons name="list-outline" size={20} color={colors.foreground} />
|
||||
<Text style={[styles.rowText, { color: colors.foreground }]}>Queue</Text>
|
||||
</Pressable>
|
||||
|
||||
{owned.length > 0 ? (
|
||||
<Text style={[styles.sectionLabel, { color: colors.mutedForeground }]}>Your playlists</Text>
|
||||
) : null}
|
||||
{owned.map((playlist: PlaylistSummary) => (
|
||||
<Pressable
|
||||
key={playlist.id}
|
||||
style={styles.row}
|
||||
onPress={() => push(`/playlist/${playlist.id}`)}
|
||||
>
|
||||
<Ionicons name="musical-notes" size={20} color={colors.foreground} />
|
||||
<Text style={[styles.rowText, { color: colors.foreground }]}>{playlist.title}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
|
||||
{subscribed.length > 0 ? (
|
||||
<Text style={[styles.sectionLabel, { color: colors.mutedForeground }]}>Subscribed</Text>
|
||||
) : null}
|
||||
{subscribed.map((playlist: PlaylistSummary) => (
|
||||
<Pressable
|
||||
key={playlist.id}
|
||||
style={styles.row}
|
||||
onPress={() => push(`/playlist/${playlist.id}`)}
|
||||
>
|
||||
<Ionicons name="musical-notes-outline" size={20} color={colors.foreground} />
|
||||
<Text style={[styles.rowText, { color: colors.foreground }]}>{playlist.title}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
|
||||
<Pressable style={styles.row} onPress={() => void handleSignOut()}>
|
||||
<Ionicons name="log-out-outline" size={20} color={colors.destructive} />
|
||||
<Text style={[styles.rowText, { color: colors.destructive }]}>Sign out</Text>
|
||||
</Pressable>
|
||||
<Pressable style={styles.row} onPress={() => void handleChangeServer()}>
|
||||
<Ionicons name="server-outline" size={20} color={colors.mutedForeground} />
|
||||
<Text style={[styles.rowText, { color: colors.mutedForeground }]}>Change server</Text>
|
||||
</Pressable>
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
profileCard: {
|
||||
margin: spacing.lg,
|
||||
borderRadius: radius.lg,
|
||||
padding: spacing.lg,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
},
|
||||
avatar: {
|
||||
width: 48,
|
||||
height: 48,
|
||||
borderRadius: 24,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
name: { fontSize: 18, fontWeight: "700" },
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
},
|
||||
rowText: { fontSize: 16, fontWeight: "500" },
|
||||
sectionLabel: {
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingTop: spacing.lg,
|
||||
fontSize: 12,
|
||||
fontWeight: "700",
|
||||
textTransform: "uppercase",
|
||||
},
|
||||
})
|
||||
@@ -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 SearchLayout() {
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||
headerRight: route.name === "settings" ? undefined : () => <ProfileHeaderButton />,
|
||||
unstable_headerRightItems:
|
||||
route.name === "settings"
|
||||
? undefined
|
||||
: () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
],
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -67,6 +67,16 @@ export default function AppLayout() {
|
||||
<FavoritesProvider>
|
||||
<Stack screenOptions={stackOptions}>
|
||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
||||
<Stack.Screen
|
||||
name="settings"
|
||||
options={{
|
||||
headerShown: false,
|
||||
presentation: Platform.OS === "ios" ? "modal" : "fullScreenModal",
|
||||
animation: "slide_from_bottom",
|
||||
gestureEnabled: true,
|
||||
gestureDirection: "vertical",
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="player"
|
||||
options={{
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from "./(tabs)/home/settings"
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import { useRouter } from "expo-router"
|
||||
import { Pressable, StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { initialsFromName } from "@/lib/format"
|
||||
import { radius, useThemeColors } from "@/lib/theme"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export function ProfileHeaderButton() {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const user = useQuery(api.auth.currentUser)
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityLabel="Open profile"
|
||||
accessibilityRole="button"
|
||||
hitSlop={8}
|
||||
onPress={() => router.push("/(app)/settings")}
|
||||
style={({ pressed }) => [styles.button, { opacity: pressed ? 0.75 : 1 }]}
|
||||
>
|
||||
<View
|
||||
style={[
|
||||
styles.avatar,
|
||||
{
|
||||
backgroundColor: colors.muted,
|
||||
borderColor: colors.border,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{user?.image ? (
|
||||
<Image source={{ uri: user.image }} style={styles.image} contentFit="cover" />
|
||||
) : (
|
||||
<Text style={[styles.initials, { color: colors.foreground }]}>
|
||||
{initialsFromName(user?.name ?? "Me")}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
button: {
|
||||
marginRight: 4,
|
||||
},
|
||||
avatar: {
|
||||
width: 42,
|
||||
height: 42,
|
||||
borderRadius: radius.full,
|
||||
borderWidth: 1,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
overflow: "hidden",
|
||||
},
|
||||
image: {
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
},
|
||||
initials: {
|
||||
fontSize: 14,
|
||||
fontWeight: "700",
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user