feat(mobile): grouped settings lists and a combined admin tab
Merge Library and Users into one Admin tab, render settings lists as inset grouped cards with stacked option details and footers, even out the Session icon sizes, and enlarge the iOS header title. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3031606389
commit
9b41f89dbb
2 files changed
+205
-151
No files matched your search
@@ -51,7 +51,7 @@ import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
|
||||
type IconName = React.ComponentProps<typeof Ionicons>["name"]
|
||||
|
||||
type Section = "profile" | "quality" | "downloads" | "library" | "users"
|
||||
type Section = "profile" | "quality" | "downloads" | "admin"
|
||||
|
||||
type CurrentUser = {
|
||||
_id: Id<"users">
|
||||
@@ -105,15 +105,9 @@ const SECTIONS: SectionConfig[] = [
|
||||
icon: "arrow-down-circle-outline",
|
||||
},
|
||||
{
|
||||
id: "library",
|
||||
label: "Library",
|
||||
icon: "library-outline",
|
||||
admin: true,
|
||||
},
|
||||
{
|
||||
id: "users",
|
||||
label: "Users",
|
||||
icon: "people-outline",
|
||||
id: "admin",
|
||||
label: "Admin",
|
||||
icon: "shield-outline",
|
||||
admin: true,
|
||||
},
|
||||
]
|
||||
@@ -132,7 +126,7 @@ export default function SettingsScreen() {
|
||||
const [section, setSection] = useState<Section>("profile")
|
||||
const allUsers = useQuery(
|
||||
api.users.listUsers,
|
||||
user?.isAdmin === true && section === "users" ? {} : "skip"
|
||||
user?.isAdmin === true && section === "admin" ? {} : "skip"
|
||||
)
|
||||
|
||||
if (!user) {
|
||||
@@ -203,9 +197,13 @@ export default function SettingsScreen() {
|
||||
) : null}
|
||||
{section === "quality" ? <QualitySection user={user} /> : null}
|
||||
{section === "downloads" ? <DownloadsSection /> : null}
|
||||
{section === "library" && isAdmin ? <LibrarySection /> : null}
|
||||
{section === "users" && isAdmin && allUsers ? (
|
||||
<UsersSection users={allUsers} currentUserId={user._id} />
|
||||
{section === "admin" && isAdmin ? (
|
||||
<>
|
||||
<LibrarySection />
|
||||
{allUsers ? (
|
||||
<UsersSection users={allUsers} currentUserId={user._id} />
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
</ScrollView>
|
||||
|
||||
@@ -254,22 +252,24 @@ function AppearanceSection() {
|
||||
|
||||
return (
|
||||
<Group title="Appearance">
|
||||
<SwitchRow
|
||||
title="New artwork colors"
|
||||
value={enabled ?? false}
|
||||
disabled={enabled === undefined || saving}
|
||||
onValueChange={async (checked) => {
|
||||
setSaving(true)
|
||||
try {
|
||||
await setArtworkColorsEnabled(checked)
|
||||
clearCoverPaletteCache()
|
||||
} catch {
|
||||
showError("Could not save artwork colors preference.")
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<List>
|
||||
<SwitchRow
|
||||
title="New artwork colors"
|
||||
value={enabled ?? false}
|
||||
disabled={enabled === undefined || saving}
|
||||
onValueChange={async (checked) => {
|
||||
setSaving(true)
|
||||
try {
|
||||
await setArtworkColorsEnabled(checked)
|
||||
clearCoverPaletteCache()
|
||||
} catch {
|
||||
showError("Could not save artwork colors preference.")
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</List>
|
||||
</Group>
|
||||
)
|
||||
}
|
||||
@@ -449,37 +449,42 @@ function QualitySection({ user }: { user: CurrentUser }) {
|
||||
const quality = user.playbackQuality ?? "medium"
|
||||
|
||||
return (
|
||||
<Group title="Streaming Quality">
|
||||
<List>
|
||||
{QUALITY_OPTIONS.map((option) => (
|
||||
<OptionRow
|
||||
key={option.value}
|
||||
label={option.label}
|
||||
detail={option.description}
|
||||
selected={quality === option.value}
|
||||
onPress={() =>
|
||||
void updateQuality({ playbackQuality: option.value }).catch(
|
||||
(error: Error) => showError(error.message)
|
||||
<>
|
||||
<Group title="Streaming Quality" footer="Higher quality uses more data.">
|
||||
<List>
|
||||
{QUALITY_OPTIONS.map((option) => (
|
||||
<OptionRow
|
||||
key={option.value}
|
||||
label={option.label}
|
||||
detail={option.description}
|
||||
selected={quality === option.value}
|
||||
onPress={() =>
|
||||
void updateQuality({ playbackQuality: option.value }).catch(
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
</Group>
|
||||
<Group title="Spatial Audio">
|
||||
<List>
|
||||
<SwitchRow
|
||||
title="Prefer Dolby Atmos"
|
||||
subtitle={
|
||||
dolbyAtmosSupported ? undefined : "Not supported on this device"
|
||||
}
|
||||
disabled={!dolbyAtmosSupported}
|
||||
value={atmosEnabled(user)}
|
||||
onValueChange={(checked) =>
|
||||
void updateAtmos({ preferAtmos: checked }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
<GroupTitle title="Spatial Audio" />
|
||||
<SwitchRow
|
||||
title="Prefer Dolby Atmos"
|
||||
subtitle={
|
||||
dolbyAtmosSupported ? undefined : "Not supported on this device"
|
||||
}
|
||||
disabled={!dolbyAtmosSupported}
|
||||
value={atmosEnabled(user)}
|
||||
onValueChange={(checked) =>
|
||||
void updateAtmos({ preferAtmos: checked }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</Group>
|
||||
</List>
|
||||
</Group>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -541,7 +546,11 @@ function RememberedQualityGroup() {
|
||||
label: string
|
||||
detail: string
|
||||
}[] = [
|
||||
{ value: null, label: "Ask every time", detail: "" },
|
||||
{
|
||||
value: null,
|
||||
label: "Ask Every Time",
|
||||
detail: "Choose when downloading",
|
||||
},
|
||||
...DOWNLOAD_QUALITIES.map((quality) => ({
|
||||
value: quality,
|
||||
label: DOWNLOAD_QUALITY_LABELS[quality],
|
||||
@@ -550,7 +559,10 @@ function RememberedQualityGroup() {
|
||||
]
|
||||
|
||||
return (
|
||||
<Group title="Download Quality">
|
||||
<Group
|
||||
title="Download Quality"
|
||||
footer="Lossless files use significantly more space on your device."
|
||||
>
|
||||
<List>
|
||||
{options.map((option) => (
|
||||
<OptionRow
|
||||
@@ -587,56 +599,62 @@ function DownloadsSection() {
|
||||
return (
|
||||
<>
|
||||
<Group title="Storage">
|
||||
<Text style={{ color: colors.foreground, fontSize: 15 }}>
|
||||
{formatBytes(breakdown.bytes)} · {songCount(breakdown.songs)}
|
||||
{breakdown.queued > 0 ? ` · ${breakdown.queued} downloading` : ""}
|
||||
</Text>
|
||||
{breakdown.songs > 0 ? (
|
||||
<>
|
||||
<View
|
||||
style={[styles.storageBar, { backgroundColor: colors.muted }]}
|
||||
>
|
||||
{qualities.map((entry) => (
|
||||
<List>
|
||||
<View style={styles.storageCard}>
|
||||
<Text style={[styles.rowTitle, { color: colors.foreground }]}>
|
||||
{formatBytes(breakdown.bytes)} · {songCount(breakdown.songs)}
|
||||
{breakdown.queued > 0 ? ` · ${breakdown.queued} downloading` : ""}
|
||||
</Text>
|
||||
{breakdown.songs > 0 ? (
|
||||
<>
|
||||
<View
|
||||
key={entry.quality}
|
||||
style={{
|
||||
flex: entry.bytes,
|
||||
backgroundColor: colors.foreground,
|
||||
opacity: QUALITY_OPACITY[entry.quality],
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
{qualities.map((entry) => (
|
||||
<View key={entry.quality} style={styles.storageRow}>
|
||||
<View
|
||||
style={[
|
||||
styles.storageDot,
|
||||
{
|
||||
backgroundColor: colors.foreground,
|
||||
opacity: QUALITY_OPACITY[entry.quality],
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<View style={{ flex: 1 }}>
|
||||
<QualityName
|
||||
quality={entry.quality}
|
||||
color={colors.foreground}
|
||||
backgroundColor={colors.background}
|
||||
/>
|
||||
</View>
|
||||
<Text style={{ color: colors.mutedForeground, fontSize: 13 }}>
|
||||
{songCount(entry.songs)}
|
||||
</Text>
|
||||
<Text
|
||||
style={[styles.storageSize, { color: colors.foreground }]}
|
||||
style={[styles.storageBar, { backgroundColor: colors.muted }]}
|
||||
>
|
||||
{formatBytes(entry.bytes)}
|
||||
</Text>
|
||||
</View>
|
||||
))}
|
||||
</>
|
||||
) : null}
|
||||
{qualities.map((entry) => (
|
||||
<View
|
||||
key={entry.quality}
|
||||
style={{
|
||||
flex: entry.bytes,
|
||||
backgroundColor: colors.foreground,
|
||||
opacity: QUALITY_OPACITY[entry.quality],
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
{qualities.map((entry) => (
|
||||
<View key={entry.quality} style={styles.storageRow}>
|
||||
<View
|
||||
style={[
|
||||
styles.storageDot,
|
||||
{
|
||||
backgroundColor: colors.foreground,
|
||||
opacity: QUALITY_OPACITY[entry.quality],
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<View style={{ flex: 1 }}>
|
||||
<QualityName
|
||||
quality={entry.quality}
|
||||
color={colors.foreground}
|
||||
backgroundColor={colors.card}
|
||||
/>
|
||||
</View>
|
||||
<Text
|
||||
style={{ color: colors.mutedForeground, fontSize: 13 }}
|
||||
>
|
||||
{songCount(entry.songs)}
|
||||
</Text>
|
||||
<Text
|
||||
style={[styles.storageSize, { color: colors.foreground }]}
|
||||
>
|
||||
{formatBytes(entry.bytes)}
|
||||
</Text>
|
||||
</View>
|
||||
))}
|
||||
</>
|
||||
) : null}
|
||||
</View>
|
||||
</List>
|
||||
</Group>
|
||||
|
||||
<RememberedQualityGroup />
|
||||
@@ -685,7 +703,7 @@ function DownloadsSection() {
|
||||
<QualityName
|
||||
quality={collection.quality}
|
||||
color={colors.mutedForeground}
|
||||
backgroundColor={colors.background}
|
||||
backgroundColor={colors.card}
|
||||
/>
|
||||
{fallbackCount > 0 ? (
|
||||
<Text
|
||||
@@ -839,15 +857,17 @@ function UsersSection({
|
||||
return (
|
||||
<>
|
||||
<Group title="Sign Up">
|
||||
<SwitchRow
|
||||
title="Disable account creation"
|
||||
value={appSettings?.disableAccountCreation ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void setDisableCreation({ disabled: checked }).catch(
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<List>
|
||||
<SwitchRow
|
||||
title="Disable account creation"
|
||||
value={appSettings?.disableAccountCreation ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void setDisableCreation({ disabled: checked }).catch(
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</List>
|
||||
</Group>
|
||||
|
||||
<Group
|
||||
@@ -940,11 +960,13 @@ function SessionSection({
|
||||
<List>
|
||||
<ActionRow
|
||||
icon="server-outline"
|
||||
iconSize={19}
|
||||
title="Change Server"
|
||||
onPress={onChangeServer}
|
||||
/>
|
||||
<ActionRow
|
||||
icon="log-out-outline"
|
||||
iconSize={22}
|
||||
title="Sign Out"
|
||||
destructive
|
||||
onPress={onSignOut}
|
||||
@@ -954,20 +976,31 @@ function SessionSection({
|
||||
)
|
||||
}
|
||||
|
||||
/** A titled block of settings. `action` renders an icon button by the title. */
|
||||
/**
|
||||
* A titled block of settings. `action` renders an icon button by the title;
|
||||
* `footer` is a short note under the block.
|
||||
*/
|
||||
function Group({
|
||||
title,
|
||||
action,
|
||||
footer,
|
||||
children,
|
||||
}: {
|
||||
title: string
|
||||
action?: React.ReactNode
|
||||
footer?: string
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<View style={styles.group}>
|
||||
<GroupTitle title={title} action={action} />
|
||||
{children}
|
||||
{footer ? (
|
||||
<Text style={[styles.groupFooter, { color: colors.mutedForeground }]}>
|
||||
{footer}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -990,23 +1023,18 @@ function GroupTitle({
|
||||
)
|
||||
}
|
||||
|
||||
/** Stacks rows with hairline separators between them. */
|
||||
/** An inset grouped card that stacks rows with inset hairline separators. */
|
||||
function List({ children }: { children: React.ReactNode }) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<View>
|
||||
<View style={[styles.list, { backgroundColor: colors.card }]}>
|
||||
{Children.toArray(children).map((row, index) => (
|
||||
<View
|
||||
key={index}
|
||||
style={
|
||||
index > 0
|
||||
? {
|
||||
borderTopWidth: StyleSheet.hairlineWidth,
|
||||
borderTopColor: colors.border,
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<View key={index}>
|
||||
{index > 0 ? (
|
||||
<View
|
||||
style={[styles.separator, { backgroundColor: colors.border }]}
|
||||
/>
|
||||
) : null}
|
||||
{row}
|
||||
</View>
|
||||
))}
|
||||
@@ -1014,7 +1042,7 @@ function List({ children }: { children: React.ReactNode }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** A single-choice row with an inline detail and a checkmark when selected. */
|
||||
/** A single-choice row with a detail line and a checkmark when selected. */
|
||||
function OptionRow({
|
||||
label,
|
||||
detail,
|
||||
@@ -1034,19 +1062,17 @@ function OptionRow({
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => [styles.listRow, { opacity: pressed ? 0.6 : 1 }]}
|
||||
>
|
||||
<Text
|
||||
style={[styles.rowTitle, styles.rowCopy, { color: colors.foreground }]}
|
||||
>
|
||||
{label}
|
||||
</Text>
|
||||
<Text style={[styles.rowDetail, { color: colors.mutedForeground }]}>
|
||||
{detail}
|
||||
</Text>
|
||||
<Ionicons
|
||||
name="checkmark"
|
||||
size={20}
|
||||
color={selected ? colors.primary : "transparent"}
|
||||
/>
|
||||
<View style={styles.rowCopy}>
|
||||
<Text style={[styles.rowTitle, { color: colors.foreground }]}>
|
||||
{label}
|
||||
</Text>
|
||||
<Text style={[styles.rowDetail, { color: colors.mutedForeground }]}>
|
||||
{detail}
|
||||
</Text>
|
||||
</View>
|
||||
{selected ? (
|
||||
<Ionicons name="checkmark" size={24} color={colors.primary} />
|
||||
) : null}
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
@@ -1095,12 +1121,15 @@ function SwitchRow({
|
||||
|
||||
function ActionRow({
|
||||
icon,
|
||||
iconSize = 20,
|
||||
title,
|
||||
destructive,
|
||||
loading,
|
||||
onPress,
|
||||
}: {
|
||||
icon: IconName
|
||||
/** Ionicons glyphs vary in optical size; tune per icon so rows match. */
|
||||
iconSize?: number
|
||||
title: string
|
||||
destructive?: boolean
|
||||
loading?: boolean
|
||||
@@ -1116,7 +1145,9 @@ function ActionRow({
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => [styles.listRow, { opacity: pressed ? 0.6 : 1 }]}
|
||||
>
|
||||
<Ionicons name={icon} size={20} color={tint} />
|
||||
<View style={styles.rowIcon}>
|
||||
<Ionicons name={icon} size={iconSize} color={tint} />
|
||||
</View>
|
||||
<Text style={[styles.rowTitle, styles.rowCopy, { color: tint }]}>
|
||||
{title}
|
||||
</Text>
|
||||
@@ -1283,22 +1314,43 @@ const styles = StyleSheet.create({
|
||||
fontSize: 15,
|
||||
fontWeight: "700",
|
||||
},
|
||||
list: {
|
||||
borderRadius: radius.lg,
|
||||
overflow: "hidden",
|
||||
paddingHorizontal: spacing.lg,
|
||||
},
|
||||
separator: {
|
||||
height: StyleSheet.hairlineWidth,
|
||||
},
|
||||
groupFooter: {
|
||||
fontSize: 13,
|
||||
lineHeight: 18,
|
||||
paddingHorizontal: spacing.lg,
|
||||
},
|
||||
storageCard: {
|
||||
gap: spacing.sm,
|
||||
paddingVertical: spacing.md,
|
||||
},
|
||||
rowIcon: {
|
||||
width: 24,
|
||||
alignItems: "center",
|
||||
},
|
||||
listRow: {
|
||||
minHeight: 44,
|
||||
minHeight: 48,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingVertical: spacing.xs,
|
||||
paddingVertical: spacing.sm,
|
||||
},
|
||||
rowCopy: {
|
||||
flex: 1,
|
||||
gap: 2,
|
||||
},
|
||||
rowTitle: {
|
||||
fontSize: 16,
|
||||
fontSize: 17,
|
||||
},
|
||||
rowDetail: {
|
||||
fontSize: 13,
|
||||
fontSize: 15,
|
||||
},
|
||||
photoRow: {
|
||||
flexDirection: "row",
|
||||
|
||||
@@ -95,6 +95,8 @@ export default function AppLayout() {
|
||||
headerTransparent: false,
|
||||
headerShadowVisible: false,
|
||||
headerStyle: { backgroundColor: "#000" },
|
||||
// Matches the inline title size of Apple Music's settings.
|
||||
headerTitleStyle: { fontSize: 20, fontWeight: "700" },
|
||||
presentation:
|
||||
Platform.OS === "ios" ? "modal" : "fullScreenModal",
|
||||
animation: "slide_from_bottom",
|
||||
|
||||
Reference in new issue
Block a user