- Replace mobile placeholder with Expo Router app (tabs, playback, auth, library) - Move Convex backend to @otunes/convex for web and mobile reuse - Update web app imports and API routes to use shared package
138 lines
5.1 KiB
TypeScript
138 lines
5.1 KiB
TypeScript
import { useAuthActions } from "@convex-dev/auth/react"
|
|
import { useQuery } from "convex/react"
|
|
import { useRouter } from "expo-router"
|
|
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
|
import { SafeAreaView } from "react-native-safe-area-context"
|
|
import { Ionicons } from "@expo/vector-icons"
|
|
|
|
import { ScreenHeader } from "@/components/screen-header"
|
|
import { contentBottomInset } from "@/components/player"
|
|
import { useServerConfig } from "@/contexts/server-config"
|
|
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 colors = useThemeColors()
|
|
const { signOut } = useAuthActions()
|
|
const { clearServer } = useServerConfig()
|
|
const user = useQuery(api.auth.currentUser)
|
|
const sidebarPlaylists = useQuery(api.playlists.listSidebarPlaylists)
|
|
|
|
async function handleSignOut() {
|
|
await signOut()
|
|
router.replace("/signin")
|
|
}
|
|
|
|
async function handleChangeServer() {
|
|
await signOut()
|
|
await clearServer()
|
|
router.replace("/server")
|
|
}
|
|
|
|
const subscribed = sidebarPlaylists?.subscribed ?? []
|
|
const owned = sidebarPlaylists?.owned ?? []
|
|
|
|
return (
|
|
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
|
<ScreenHeader title="More" />
|
|
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
|
<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={() => router.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={() => router.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={() => router.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={() => router.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>
|
|
</SafeAreaView>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
safe: { flex: 1 },
|
|
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",
|
|
},
|
|
})
|