feat: initial mobile app UI pass
This commit is contained in:
1 parent
73c7283d4d
commit
0ff352e11a
51 files changed
+2534
-1258
No files matched your search
@@ -1,2 +1,7 @@
|
||||
ios/
|
||||
android/
|
||||
android/
|
||||
# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
|
||||
# The following patterns were generated by expo-cli
|
||||
|
||||
expo-env.d.ts
|
||||
# @end expo-cli
|
||||
@@ -21,9 +21,10 @@
|
||||
"expo-router",
|
||||
"expo-secure-store",
|
||||
[
|
||||
"expo-av",
|
||||
"expo-audio",
|
||||
{
|
||||
"microphonePermission": false
|
||||
"microphonePermission": false,
|
||||
"enableBackgroundPlayback": true
|
||||
}
|
||||
]
|
||||
],
|
||||
|
||||
@@ -1,68 +1,122 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Tabs } from "expo-router"
|
||||
import { DarkTheme, DefaultTheme, ThemeProvider } from "expo-router"
|
||||
import { NativeTabs } from "expo-router/unstable-native-tabs"
|
||||
import { DynamicColorIOS, Platform, useColorScheme } from "react-native"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
import { TabBottomAccessory } from "@/components/mini-player"
|
||||
import { appleMusic, colors } from "@/lib/theme"
|
||||
|
||||
function useRouterTheme() {
|
||||
const isDark = useColorScheme() === "dark"
|
||||
|
||||
return useMemo(() => {
|
||||
const palette = isDark ? colors.dark : colors.light
|
||||
const base = isDark ? DarkTheme : DefaultTheme
|
||||
|
||||
return {
|
||||
...base,
|
||||
colors: {
|
||||
...base.colors,
|
||||
background: palette.background,
|
||||
card: palette.card,
|
||||
text: palette.foreground,
|
||||
border: palette.border,
|
||||
primary: palette.primary,
|
||||
},
|
||||
}
|
||||
}, [isDark])
|
||||
}
|
||||
|
||||
function useNativeTabColors() {
|
||||
const isDark = useColorScheme() === "dark"
|
||||
const inactive = appleMusic.tabInactive
|
||||
|
||||
const iconColor =
|
||||
Platform.OS === "ios"
|
||||
? {
|
||||
default: DynamicColorIOS({ dark: inactive, light: "#636366" }),
|
||||
selected: appleMusic.pink,
|
||||
}
|
||||
: {
|
||||
default: isDark ? inactive : "#636366",
|
||||
selected: appleMusic.pink,
|
||||
}
|
||||
|
||||
const labelColor =
|
||||
Platform.OS === "ios"
|
||||
? DynamicColorIOS({ dark: inactive, light: "#636366" })
|
||||
: isDark
|
||||
? inactive
|
||||
: "#636366"
|
||||
|
||||
return {
|
||||
isDark,
|
||||
iconColor,
|
||||
labelStyle: {
|
||||
default: { color: labelColor, fontSize: 10 },
|
||||
selected: { color: appleMusic.pink, fontSize: 10, fontWeight: "600" as const },
|
||||
},
|
||||
blurEffect: isDark ? "systemChromeMaterialDark" : "systemChromeMaterialLight",
|
||||
backgroundColor:
|
||||
Platform.OS === "ios" ? undefined : isDark ? appleMusic.background : colors.light.background,
|
||||
}
|
||||
}
|
||||
|
||||
export default function TabsLayout() {
|
||||
const colors = useThemeColors()
|
||||
const routerTheme = useRouterTheme()
|
||||
const tabColors = useNativeTabColors()
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
screenOptions={{
|
||||
headerShown: false,
|
||||
tabBarActiveTintColor: colors.foreground,
|
||||
tabBarInactiveTintColor: colors.mutedForeground,
|
||||
tabBarStyle: {
|
||||
backgroundColor: colors.background,
|
||||
borderTopColor: colors.border,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Tabs.Screen
|
||||
name="index"
|
||||
options={{
|
||||
title: "Home",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="home" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="search"
|
||||
options={{
|
||||
title: "Search",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="search" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="library"
|
||||
options={{
|
||||
title: "Library",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="library" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="playlists"
|
||||
options={{
|
||||
title: "Playlists",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="list" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="more"
|
||||
options={{
|
||||
title: "More",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="person-circle" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Tabs>
|
||||
<ThemeProvider value={routerTheme}>
|
||||
<NativeTabs
|
||||
blurEffect={tabColors.blurEffect as "systemChromeMaterialDark" | "systemChromeMaterialLight"}
|
||||
backgroundColor={tabColors.backgroundColor}
|
||||
iconColor={tabColors.iconColor}
|
||||
labelStyle={tabColors.labelStyle}
|
||||
tintColor={appleMusic.pink}
|
||||
minimizeBehavior="onScrollDown"
|
||||
>
|
||||
<NativeTabs.BottomAccessory>
|
||||
<TabBottomAccessory />
|
||||
</NativeTabs.BottomAccessory>
|
||||
|
||||
<NativeTabs.Trigger name="home" disableTransparentOnScrollEdge>
|
||||
<NativeTabs.Trigger.Icon
|
||||
sf={{ default: "house", selected: "house.fill" }}
|
||||
md="home"
|
||||
/>
|
||||
<NativeTabs.Trigger.Label>Home</NativeTabs.Trigger.Label>
|
||||
</NativeTabs.Trigger>
|
||||
|
||||
<NativeTabs.Trigger name="library" disableTransparentOnScrollEdge>
|
||||
<NativeTabs.Trigger.Icon
|
||||
sf={{ default: "square.stack", selected: "square.stack.fill" }}
|
||||
md="library_music"
|
||||
/>
|
||||
<NativeTabs.Trigger.Label>Library</NativeTabs.Trigger.Label>
|
||||
</NativeTabs.Trigger>
|
||||
|
||||
<NativeTabs.Trigger name="playlists" disableTransparentOnScrollEdge>
|
||||
<NativeTabs.Trigger.Icon
|
||||
sf={{ default: "music.note.list", selected: "music.note.list" }}
|
||||
md="playlist_play"
|
||||
/>
|
||||
<NativeTabs.Trigger.Label>Playlists</NativeTabs.Trigger.Label>
|
||||
</NativeTabs.Trigger>
|
||||
|
||||
<NativeTabs.Trigger name="search" role="search" disableTransparentOnScrollEdge>
|
||||
<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>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { useStackScreenOptions } from "@/lib/navigation"
|
||||
|
||||
export default function HomeLayout() {
|
||||
return <Stack screenOptions={useStackScreenOptions({ title: "Home" })} />
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet } from "react-native"
|
||||
|
||||
import { ContentCarousel } from "@/components/media-cards"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function HomeScreen() {
|
||||
const colors = useThemeColors()
|
||||
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
|
||||
const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed)
|
||||
|
||||
if (recentlyAdded === undefined || recentlyPlayed === undefined) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={[styles.content, { paddingBottom: tabContentBottomInset }]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
{recentlyPlayed.length > 0 ? (
|
||||
<ContentCarousel
|
||||
title="Recently Played"
|
||||
href="/recently-played"
|
||||
content={recentlyPlayed}
|
||||
/>
|
||||
) : null}
|
||||
<ContentCarousel
|
||||
title="Recently Added"
|
||||
href="/recently-added"
|
||||
content={recentlyAdded}
|
||||
/>
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
content: {
|
||||
padding: spacing.lg,
|
||||
gap: spacing.xl,
|
||||
},
|
||||
})
|
||||
@@ -1,55 +0,0 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { ContentCarousel } from "@/components/media-cards"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function HomeScreen() {
|
||||
const colors = useThemeColors()
|
||||
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
|
||||
const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed)
|
||||
|
||||
if (recentlyAdded === undefined || recentlyPlayed === undefined) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]}>
|
||||
<ScreenHeader title="Home" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Home" />
|
||||
<ScrollView
|
||||
contentContainerStyle={[styles.content, { paddingBottom: contentBottomInset }]}
|
||||
>
|
||||
{recentlyPlayed.length > 0 ? (
|
||||
<ContentCarousel
|
||||
title="Recently Played"
|
||||
href="/recently-played"
|
||||
content={recentlyPlayed.slice(0, 9)}
|
||||
/>
|
||||
) : null}
|
||||
<ContentCarousel
|
||||
title="Recently Added"
|
||||
href="/recently-added"
|
||||
content={recentlyAdded.slice(0, 9)}
|
||||
/>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
content: {
|
||||
padding: spacing.lg,
|
||||
gap: spacing.xl,
|
||||
},
|
||||
})
|
||||
@@ -1,67 +0,0 @@
|
||||
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 { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
const links = [
|
||||
{ title: "Albums", href: "/library/albums", icon: "disc" as const },
|
||||
{ title: "Artists", href: "/library/artists", icon: "mic" as const },
|
||||
{ title: "Songs", href: "/library/songs", icon: "musical-notes" as const },
|
||||
{ title: "Recently Played", href: "/recently-played", icon: "time" as const },
|
||||
{ title: "Recently Added", href: "/recently-added", icon: "sparkles" as const },
|
||||
{ title: "Favorites", href: "/playlist/favorites", icon: "star" as const },
|
||||
]
|
||||
|
||||
export default function LibraryScreen() {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Library" />
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
{links.map((link) => (
|
||||
<Pressable
|
||||
key={link.href}
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={() => router.push(link.href as never)}
|
||||
>
|
||||
<View style={[styles.iconWrap, { backgroundColor: colors.muted }]}>
|
||||
<Ionicons name={link.icon} size={20} color={colors.foreground} />
|
||||
</View>
|
||||
<Text style={[styles.rowTitle, { color: colors.foreground }]}>{link.title}</Text>
|
||||
<Ionicons name="chevron-forward" size={18} color={colors.mutedForeground} />
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
iconWrap: {
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: radius.md,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
rowTitle: {
|
||||
flex: 1,
|
||||
fontSize: 16,
|
||||
fontWeight: "600",
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { useStackScreenOptions } from "@/lib/navigation"
|
||||
|
||||
export default function LibraryLayout() {
|
||||
return <Stack screenOptions={useStackScreenOptions({ title: "Library" })} />
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { useRouter } from "expo-router"
|
||||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
import { SymbolView } from "expo-symbols"
|
||||
import { Platform } from "react-native"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
|
||||
import { MediaGrid } from "@/components/media-cards"
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { appleMusic, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
const links = [
|
||||
{ title: "Playlists", href: "/(app)/(tabs)/playlists", icon: "music.note.list" as const },
|
||||
{ title: "Artists", href: "/library/artists", icon: "mic.fill" as const },
|
||||
{ title: "Albums", href: "/library/albums", icon: "square.stack" as const },
|
||||
{ title: "Songs", href: "/library/songs", icon: "music.note" as const },
|
||||
{ title: "Recently Played", href: "/recently-played", icon: "clock" as const },
|
||||
{ title: "Recently Added", href: "/recently-added", icon: "sparkles" as const },
|
||||
{ title: "Favorites", href: "/playlist/favorites", icon: "star" as const },
|
||||
]
|
||||
|
||||
function LibraryIcon({ name }: { name: (typeof links)[number]["icon"] }) {
|
||||
if (Platform.OS === "ios") {
|
||||
return (
|
||||
<SymbolView
|
||||
name={name}
|
||||
size={22}
|
||||
tintColor={appleMusic.pink}
|
||||
weight="semibold"
|
||||
/>
|
||||
)
|
||||
}
|
||||
const ionMap: Record<string, keyof typeof Ionicons.glyphMap> = {
|
||||
"music.note.list": "list",
|
||||
"mic.fill": "mic",
|
||||
"square.stack": "albums",
|
||||
"music.note": "musical-notes",
|
||||
clock: "time",
|
||||
sparkles: "sparkles",
|
||||
star: "star",
|
||||
}
|
||||
return <Ionicons name={ionMap[name] ?? "musical-notes"} size={22} color={appleMusic.pink} />
|
||||
}
|
||||
|
||||
export default function LibraryScreen() {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
{links.map((link) => (
|
||||
<Pressable
|
||||
key={link.href}
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={() => router.push(link.href as never)}
|
||||
>
|
||||
<LibraryIcon name={link.icon} />
|
||||
<Text style={[styles.rowTitle, { color: colors.foreground }]}>{link.title}</Text>
|
||||
<Ionicons name="chevron-forward" size={16} color={colors.mutedForeground} />
|
||||
</Pressable>
|
||||
))}
|
||||
|
||||
<View style={styles.section}>
|
||||
<Pressable onPress={() => router.push("/recently-added")}>
|
||||
<Text style={[styles.sectionTitle, { color: colors.foreground }]}>
|
||||
Recently Added
|
||||
</Text>
|
||||
</Pressable>
|
||||
{recentlyAdded === undefined ? (
|
||||
<LoadingView />
|
||||
) : (
|
||||
<MediaGrid content={recentlyAdded.slice(0, 4)} />
|
||||
)}
|
||||
</View>
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: 14,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
rowTitle: {
|
||||
flex: 1,
|
||||
fontSize: 20,
|
||||
fontWeight: "400",
|
||||
},
|
||||
section: {
|
||||
paddingTop: spacing.xl,
|
||||
paddingHorizontal: spacing.lg,
|
||||
gap: spacing.md,
|
||||
},
|
||||
sectionTitle: {
|
||||
fontSize: 22,
|
||||
fontWeight: "700",
|
||||
},
|
||||
})
|
||||
@@ -1,137 +0,0 @@
|
||||
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",
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { useStackScreenOptions } from "@/lib/navigation"
|
||||
|
||||
export default function MoreLayout() {
|
||||
return <Stack screenOptions={useStackScreenOptions({ title: "More" })} />
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
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 { Ionicons } from "@expo/vector-icons"
|
||||
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
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 colors = useThemeColors()
|
||||
const { signOut } = useAuthActions()
|
||||
const { clearServer } = useServerConfig()
|
||||
const user = useQuery(api.auth.currentUser)
|
||||
const sidebarPlaylists = useQuery(api.playlists.listSidebarPlaylists)
|
||||
|
||||
async function handleSignOut() {
|
||||
await signOutToSignIn(signOut, router)
|
||||
}
|
||||
|
||||
async function handleChangeServer() {
|
||||
await signOut()
|
||||
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={() => 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>
|
||||
)
|
||||
}
|
||||
|
||||
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,48 +0,0 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { PlaylistCard } from "@/components/media-cards"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { Button, LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { PlaylistSummary } from "@otunes/convex/types"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function PlaylistsTabScreen() {
|
||||
const colors = useThemeColors()
|
||||
const playlists = useQuery(api.playlists.listAllPlaylists)
|
||||
const { openCreatePlaylist } = useAddToPlaylist()
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader
|
||||
title="Playlists"
|
||||
right={<Button title="New" variant="secondary" onPress={openCreatePlaylist} />}
|
||||
/>
|
||||
{playlists === undefined ? (
|
||||
<LoadingView />
|
||||
) : (
|
||||
<ScrollView contentContainerStyle={[styles.content, { paddingBottom: contentBottomInset }]}>
|
||||
<View style={styles.grid}>
|
||||
{playlists.map((playlist: PlaylistSummary) => (
|
||||
<PlaylistCard key={playlist.id} playlist={playlist} />
|
||||
))}
|
||||
</View>
|
||||
</ScrollView>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
content: { padding: spacing.lg },
|
||||
grid: {
|
||||
flexDirection: "row",
|
||||
flexWrap: "wrap",
|
||||
gap: spacing.lg,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Stack } from "expo-router"
|
||||
import { Pressable, Text } from "react-native"
|
||||
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
import { useStackScreenOptions } from "@/lib/navigation"
|
||||
import { appleMusic } from "@/lib/theme"
|
||||
|
||||
function NewPlaylistButton() {
|
||||
const { openCreatePlaylist } = useAddToPlaylist()
|
||||
|
||||
return (
|
||||
<Pressable onPress={openCreatePlaylist} hitSlop={8}>
|
||||
<Text style={{ color: appleMusic.pink, fontSize: 17, fontWeight: "600" }}>
|
||||
New
|
||||
</Text>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
export default function PlaylistsLayout() {
|
||||
return (
|
||||
<Stack
|
||||
screenOptions={useStackScreenOptions({
|
||||
title: "Playlists",
|
||||
headerRight: () => <NewPlaylistButton />,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet } from "react-native"
|
||||
|
||||
import { MediaGrid } from "@/components/media-cards"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function PlaylistsTabScreen() {
|
||||
const colors = useThemeColors()
|
||||
const playlists = useQuery(api.playlists.listAllPlaylists)
|
||||
|
||||
if (playlists === undefined) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={[styles.content, { paddingBottom: tabContentBottomInset }]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<MediaGrid content={playlists} />
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
content: { padding: spacing.lg },
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { useStackScreenOptions } from "@/lib/navigation"
|
||||
|
||||
export default function SearchLayout() {
|
||||
return <Stack screenOptions={useStackScreenOptions({ title: "Search" })} />
|
||||
}
|
||||
+26
-23
@@ -1,12 +1,11 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { Stack } from "expo-router"
|
||||
import { useMemo, useState } from "react"
|
||||
import { ScrollView, StyleSheet, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
import { ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { ContentCarousel } from "@/components/media-cards"
|
||||
import { contentBottomInset, SongRow } from "@/components/player"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { Input, LoadingView } from "@/components/ui/primitives"
|
||||
import { tabContentBottomInset, SongRow } from "@/components/player"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { usePlayback } from "@/contexts/playback"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
@@ -53,29 +52,34 @@ export default function SearchScreen() {
|
||||
)
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Search" />
|
||||
<View style={styles.searchBox}>
|
||||
<Input
|
||||
value={query}
|
||||
onChangeText={handleQueryChange}
|
||||
placeholder="Search songs, albums, artists..."
|
||||
returnKeyType="search"
|
||||
onSubmitEditing={() => setSearchQuery(query.trim())}
|
||||
/>
|
||||
</View>
|
||||
<>
|
||||
<Stack.SearchBar
|
||||
placeholder="Artists, Songs, Lyrics, and More"
|
||||
onChangeText={(event) => handleQueryChange(event.nativeEvent.text)}
|
||||
onSearchButtonPress={() => setSearchQuery(query.trim())}
|
||||
autoCapitalize="none"
|
||||
/>
|
||||
|
||||
{isSearching ? (
|
||||
<LoadingView />
|
||||
) : !hasQuery ? (
|
||||
<View style={styles.empty}>
|
||||
<Input editable={false} value="Search your library" />
|
||||
<Text style={[styles.emptyText, { color: colors.mutedForeground }]}>
|
||||
Find your favorite music
|
||||
</Text>
|
||||
</View>
|
||||
) : (
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
keyboardShouldPersistTaps="handled"
|
||||
>
|
||||
{!hasLibraryResults ? (
|
||||
<View style={styles.empty}>
|
||||
<Input editable={false} value={`No results for "${searchQuery}"`} />
|
||||
<Text style={[styles.emptyText, { color: colors.mutedForeground }]}>
|
||||
No results for "{searchQuery}"
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
@@ -115,13 +119,12 @@ export default function SearchScreen() {
|
||||
) : null}
|
||||
</ScrollView>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
searchBox: { paddingHorizontal: spacing.lg, paddingBottom: spacing.md },
|
||||
empty: { padding: spacing.lg },
|
||||
empty: { padding: spacing.xl, alignItems: "center" },
|
||||
emptyText: { fontSize: 16 },
|
||||
section: { paddingHorizontal: spacing.lg, paddingBottom: spacing.lg, gap: spacing.md },
|
||||
})
|
||||
@@ -1,22 +1,30 @@
|
||||
import { useConvexAuth } from "@convex-dev/auth/react"
|
||||
import { Redirect, Stack } from "expo-router"
|
||||
import { View } from "react-native"
|
||||
import { Platform } from "react-native"
|
||||
|
||||
import { PlayerBar } from "@/components/player"
|
||||
import { FloatingMiniPlayer } from "@/components/mini-player"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { AddToPlaylistProvider } from "@/contexts/add-to-playlist"
|
||||
import { FavoritesProvider } from "@/contexts/favorites"
|
||||
import { PlaybackProvider } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { useStackScreenOptions } from "@/lib/navigation"
|
||||
|
||||
export default function AppLayout() {
|
||||
const { config } = useServerConfig()
|
||||
const { isLoading, isAuthenticated } = useConvexAuth()
|
||||
const auth = useConvexAuth()
|
||||
const stackOptions = useStackScreenOptions()
|
||||
|
||||
if (!config) {
|
||||
return <Redirect href="/server" />
|
||||
}
|
||||
|
||||
if (!auth) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
const { isLoading, isAuthenticated } = auth
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingView />
|
||||
}
|
||||
@@ -29,10 +37,32 @@ export default function AppLayout() {
|
||||
<PlaybackProvider>
|
||||
<AddToPlaylistProvider>
|
||||
<FavoritesProvider>
|
||||
<View style={{ flex: 1 }}>
|
||||
<Stack screenOptions={{ headerShown: false }} />
|
||||
<PlayerBar />
|
||||
</View>
|
||||
<Stack screenOptions={stackOptions}>
|
||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
||||
<Stack.Screen
|
||||
name="player"
|
||||
options={{
|
||||
headerShown: false,
|
||||
presentation: Platform.OS === "ios" ? "modal" : "fullScreenModal",
|
||||
animation: "slide_from_bottom",
|
||||
gestureEnabled: true,
|
||||
gestureDirection: "vertical",
|
||||
fullScreenGestureEnabled: true,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen name="album/[id]" options={{ title: "Album" }} />
|
||||
<Stack.Screen name="artist/[id]" options={{ title: "Artist" }} />
|
||||
<Stack.Screen name="playlist/[id]" options={{ title: "Playlist" }} />
|
||||
<Stack.Screen name="playlist/favorites" options={{ title: "Favorites" }} />
|
||||
<Stack.Screen name="library/albums" options={{ title: "Albums" }} />
|
||||
<Stack.Screen name="library/artists" options={{ title: "Artists" }} />
|
||||
<Stack.Screen name="library/songs" options={{ title: "Songs" }} />
|
||||
<Stack.Screen name="recently-played" options={{ title: "Recently Played" }} />
|
||||
<Stack.Screen name="recently-added" options={{ title: "Recently Added" }} />
|
||||
<Stack.Screen name="queue" options={{ title: "Queue" }} />
|
||||
<Stack.Screen name="settings" options={{ title: "Settings" }} />
|
||||
</Stack>
|
||||
<FloatingMiniPlayer />
|
||||
</FavoritesProvider>
|
||||
</AddToPlaylistProvider>
|
||||
</PlaybackProvider>
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import { useLocalSearchParams, useRouter } from "expo-router"
|
||||
import { Stack, useLocalSearchParams, useRouter } from "expo-router"
|
||||
import { useState } from "react"
|
||||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
|
||||
import { MediaActionsSheet, type MediaAction } from "@/components/media-actions-sheet"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { Button, LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
@@ -33,22 +31,14 @@ export default function AlbumScreen() {
|
||||
const [actionsOpen, setActionsOpen] = useState(false)
|
||||
|
||||
if (album === undefined || !config) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Album" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (album === null) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Album" />
|
||||
<View style={styles.empty}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Album not found.</Text>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
<View style={[styles.empty, { backgroundColor: colors.background }]}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Album not found.</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -70,16 +60,23 @@ export default function AlbumScreen() {
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader
|
||||
title={album.title}
|
||||
right={
|
||||
<Pressable onPress={() => setActionsOpen(true)} hitSlop={8}>
|
||||
<Ionicons name="ellipsis-horizontal" size={22} color={colors.foreground} />
|
||||
</Pressable>
|
||||
}
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: album.title,
|
||||
headerLargeTitle: false,
|
||||
headerRight: () => (
|
||||
<Pressable onPress={() => setActionsOpen(true)} hitSlop={8}>
|
||||
<Ionicons name="ellipsis-horizontal" size={22} color={colors.foreground} />
|
||||
</Pressable>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<View style={styles.hero}>
|
||||
<Image
|
||||
source={{ uri: albumCoverUrl(config.serverUrl, album.id) }}
|
||||
@@ -140,12 +137,11 @@ export default function AlbumScreen() {
|
||||
onClose={() => setActionsOpen(false)}
|
||||
onAction={handleAlbumAction}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||
hero: {
|
||||
alignItems: "center",
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import { useLocalSearchParams } from "expo-router"
|
||||
import { Stack, useLocalSearchParams } from "expo-router"
|
||||
import { useState } from "react"
|
||||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
|
||||
import { AlbumCard, ContentCarousel } from "@/components/media-cards"
|
||||
import { ContentCarousel, MediaGrid } from "@/components/media-cards"
|
||||
import { MediaActionsSheet, type MediaAction } from "@/components/media-actions-sheet"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { Button, LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
@@ -17,7 +15,6 @@ import { usePlayback } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseAlbum } from "@otunes/convex/types"
|
||||
import { artistCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
@@ -32,22 +29,14 @@ export default function ArtistScreen() {
|
||||
const [actionsOpen, setActionsOpen] = useState(false)
|
||||
|
||||
if (data === undefined || !config) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Artist" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (data === null) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Artist" />
|
||||
<View style={styles.empty}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Artist not found.</Text>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
<View style={[styles.empty, { backgroundColor: colors.background }]}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Artist not found.</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -66,16 +55,23 @@ export default function ArtistScreen() {
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader
|
||||
title={data.artist.name}
|
||||
right={
|
||||
<Pressable onPress={() => setActionsOpen(true)} hitSlop={8}>
|
||||
<Ionicons name="ellipsis-horizontal" size={22} color={colors.foreground} />
|
||||
</Pressable>
|
||||
}
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: data.artist.name,
|
||||
headerLargeTitle: false,
|
||||
headerRight: () => (
|
||||
<Pressable onPress={() => setActionsOpen(true)} hitSlop={8}>
|
||||
<Ionicons name="ellipsis-horizontal" size={22} color={colors.foreground} />
|
||||
</Pressable>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<View style={styles.hero}>
|
||||
<Image
|
||||
source={{ uri: artistCoverUrl(config.serverUrl, data.artist.id) }}
|
||||
@@ -110,11 +106,7 @@ export default function ArtistScreen() {
|
||||
|
||||
<View style={styles.section}>
|
||||
<Text style={[styles.sectionTitle, { color: colors.foreground }]}>Albums</Text>
|
||||
<View style={styles.grid}>
|
||||
{data.albums.map((album: BrowseAlbum) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
</View>
|
||||
<MediaGrid content={data.albums} />
|
||||
</View>
|
||||
</ScrollView>
|
||||
|
||||
@@ -125,12 +117,11 @@ export default function ArtistScreen() {
|
||||
onClose={() => setActionsOpen(false)}
|
||||
onAction={handleAction}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||
avatar: {
|
||||
@@ -143,5 +134,4 @@ const styles = StyleSheet.create({
|
||||
actions: { flexDirection: "row", alignItems: "center", gap: spacing.sm, marginTop: spacing.sm },
|
||||
section: { padding: spacing.lg, gap: spacing.md },
|
||||
sectionTitle: { fontSize: 20, fontWeight: "700" },
|
||||
grid: { flexDirection: "row", flexWrap: "wrap", gap: spacing.lg },
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Redirect } from "expo-router"
|
||||
|
||||
export default function AppIndex() {
|
||||
return <Redirect href="/(app)/(tabs)/home" />
|
||||
}
|
||||
@@ -1,39 +1,31 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
import { ScrollView, StyleSheet } from "react-native"
|
||||
|
||||
import { AlbumCard } from "@/components/media-cards"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { MediaGrid } from "@/components/media-cards"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { BrowseAlbum } from "@otunes/convex/types"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function AlbumsScreen() {
|
||||
const colors = useThemeColors()
|
||||
const albums = useQuery(api.library.browseAlbums)
|
||||
|
||||
if (albums === undefined) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Albums" />
|
||||
{albums === undefined ? (
|
||||
<LoadingView />
|
||||
) : (
|
||||
<ScrollView contentContainerStyle={[styles.content, { paddingBottom: contentBottomInset }]}>
|
||||
<View style={styles.grid}>
|
||||
{albums.map((album: BrowseAlbum) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
</View>
|
||||
</ScrollView>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={[styles.content, { paddingBottom: contentBottomInset }]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<MediaGrid content={albums} />
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
content: { padding: spacing.lg },
|
||||
grid: { flexDirection: "row", flexWrap: "wrap", gap: spacing.lg },
|
||||
})
|
||||
@@ -1,10 +1,8 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { useRouter } from "expo-router"
|
||||
import { Pressable, ScrollView, StyleSheet, Text } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
import { Image } from "expo-image"
|
||||
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
@@ -19,35 +17,35 @@ export default function ArtistsScreen() {
|
||||
const { config } = useServerConfig()
|
||||
const artists = useQuery(api.library.browseArtists)
|
||||
|
||||
if (artists === undefined || !config) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Artists" />
|
||||
{artists === undefined || !config ? (
|
||||
<LoadingView />
|
||||
) : (
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
{artists.map((artist: BrowseArtist) => (
|
||||
<Pressable
|
||||
key={artist.id}
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={() => router.push(`/artist/${artist.id}`)}
|
||||
>
|
||||
<Image
|
||||
source={{ uri: artistCoverUrl(config.serverUrl, artist.id) }}
|
||||
style={styles.avatar}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<Text style={[styles.name, { color: colors.foreground }]}>{artist.name}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
{artists.map((artist: BrowseArtist) => (
|
||||
<Pressable
|
||||
key={artist.id}
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={() => router.push(`/artist/${artist.id}`)}
|
||||
>
|
||||
<Image
|
||||
source={{ uri: artistCoverUrl(config.serverUrl, artist.id) }}
|
||||
style={styles.avatar}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<Text style={[styles.name, { color: colors.foreground }]}>{artist.name}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { usePaginatedQuery } from "convex/react"
|
||||
import { useState } from "react"
|
||||
import { FlatList, Pressable, StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { MediaActionsSheet, type MediaAction } from "@/components/media-actions-sheet"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { contentBottomInset, SongRow } from "@/components/player"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
@@ -67,17 +65,11 @@ export default function SongsScreen() {
|
||||
}
|
||||
|
||||
if (results === undefined) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Songs" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Songs" />
|
||||
<View style={{ flex: 1, backgroundColor: colors.background }}>
|
||||
<View style={[styles.sortRow, { borderBottomColor: colors.border }]}>
|
||||
{(["title", "artist", "album"] as const).map((key) => (
|
||||
<Pressable key={key} onPress={() => cycleSort(key)} style={styles.sortButton}>
|
||||
@@ -98,6 +90,7 @@ export default function SongsScreen() {
|
||||
data={results}
|
||||
keyExtractor={(item) => item.id}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
onEndReached={() => {
|
||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
||||
}}
|
||||
@@ -120,12 +113,11 @@ export default function SongsScreen() {
|
||||
onClose={() => setActionSong(null)}
|
||||
onAction={handleAction}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
sortRow: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-around",
|
||||
|
||||
@@ -0,0 +1,380 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import Slider from "@react-native-community/slider"
|
||||
import { BlurView } from "expo-blur"
|
||||
import { Image } from "expo-image"
|
||||
import { useRouter } from "expo-router"
|
||||
import * as Haptics from "expo-haptics"
|
||||
import { useState } from "react"
|
||||
import {
|
||||
Platform,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
} from "react-native"
|
||||
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
import { StatusBar } from "expo-status-bar"
|
||||
|
||||
import { MediaActionsSheet, type MediaAction } from "@/components/media-actions-sheet"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
import { usePlayback } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { formatDuration, formatRemainingDuration } from "@/lib/format"
|
||||
import { albumCoverUrl } from "@/lib/urls"
|
||||
import { appleMusic, radius, spacing, usePlayerTheme } from "@/lib/theme"
|
||||
|
||||
export default function PlayerScreen() {
|
||||
const router = useRouter()
|
||||
const insets = useSafeAreaInsets()
|
||||
const player = usePlayerTheme()
|
||||
const { config } = useServerConfig()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const [actionsOpen, setActionsOpen] = useState(false)
|
||||
const {
|
||||
currentSong,
|
||||
isPlaying,
|
||||
shuffleEnabled,
|
||||
repeatEnabled,
|
||||
currentTime,
|
||||
duration,
|
||||
volume,
|
||||
queueSongIds,
|
||||
setIsPlaying,
|
||||
setVolume,
|
||||
seekTo,
|
||||
toggleShuffle,
|
||||
cycleRepeat,
|
||||
skipNext,
|
||||
skipPrevious,
|
||||
addToQueueNext,
|
||||
addToQueueLast,
|
||||
playShuffled,
|
||||
} = usePlayback()
|
||||
|
||||
if (!currentSong || !config) {
|
||||
return null
|
||||
}
|
||||
|
||||
const coverUri = albumCoverUrl(config.serverUrl, currentSong.album.id)
|
||||
const favorited = isSongFavorite(currentSong.id)
|
||||
const bottomInset = Math.max(insets.bottom, spacing.md) + spacing.lg
|
||||
const { colors } = player
|
||||
|
||||
async function handleAction(action: MediaAction) {
|
||||
setActionsOpen(false)
|
||||
switch (action) {
|
||||
case "favorite":
|
||||
await toggleSongFavorite(currentSong!.id)
|
||||
break
|
||||
case "play-next":
|
||||
await addToQueueNext([currentSong!.id])
|
||||
break
|
||||
case "play-last":
|
||||
await addToQueueLast([currentSong!.id])
|
||||
break
|
||||
case "shuffle":
|
||||
await playShuffled([currentSong!.id])
|
||||
break
|
||||
case "go-artist":
|
||||
router.push(`/artist/${currentSong!.artist.id}`)
|
||||
break
|
||||
case "go-album":
|
||||
router.push(`/album/${currentSong!.album.id}`)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function togglePlayback() {
|
||||
void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)
|
||||
setIsPlaying(!isPlaying)
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={[styles.root, { backgroundColor: colors.background }]}>
|
||||
<StatusBar style={player.statusBar} />
|
||||
<Image
|
||||
source={{ uri: coverUri }}
|
||||
style={[styles.backgroundImage, { opacity: player.backgroundImageOpacity }]}
|
||||
contentFit="cover"
|
||||
blurRadius={60}
|
||||
/>
|
||||
{Platform.OS === "ios" ? (
|
||||
<>
|
||||
<BlurView intensity={90} tint={player.blurTint} style={StyleSheet.absoluteFill} />
|
||||
<View style={[styles.scrim, { backgroundColor: player.scrim }]} />
|
||||
</>
|
||||
) : (
|
||||
<View style={[StyleSheet.absoluteFill, { backgroundColor: player.androidScrim }]} />
|
||||
)}
|
||||
|
||||
<SafeAreaView style={styles.safe} edges={["top"]}>
|
||||
<Pressable
|
||||
onPress={() => router.back()}
|
||||
hitSlop={12}
|
||||
style={styles.handleRow}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Close player"
|
||||
>
|
||||
<View style={[styles.handle, { backgroundColor: player.handle }]} />
|
||||
</Pressable>
|
||||
|
||||
<View style={styles.upper}>
|
||||
<View style={styles.artworkWrap}>
|
||||
<Image source={{ uri: coverUri }} style={styles.artwork} contentFit="cover" />
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View style={[styles.controls, { paddingBottom: bottomInset }]}>
|
||||
<View style={styles.metaRow}>
|
||||
<View style={styles.metaText}>
|
||||
<Text style={[styles.songTitle, { color: colors.foreground }]} numberOfLines={2}>
|
||||
{currentSong.title}
|
||||
</Text>
|
||||
<Text style={[styles.artistName, { color: colors.mutedForeground }]} numberOfLines={1}>
|
||||
{currentSong.artist.name}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={styles.metaActions}>
|
||||
<Pressable
|
||||
onPress={() => void toggleSongFavorite(currentSong.id)}
|
||||
hitSlop={10}
|
||||
style={[styles.circleButton, { backgroundColor: player.buttonSurface }]}
|
||||
>
|
||||
<Ionicons
|
||||
name={favorited ? "star" : "star-outline"}
|
||||
size={20}
|
||||
color={favorited ? appleMusic.pink : colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
onPress={() => setActionsOpen(true)}
|
||||
hitSlop={10}
|
||||
style={[styles.circleButton, { backgroundColor: player.buttonSurface }]}
|
||||
>
|
||||
<Ionicons name="ellipsis-horizontal" size={20} color={colors.foreground} />
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View style={styles.progressSection}>
|
||||
<Slider
|
||||
style={styles.slider}
|
||||
minimumValue={0}
|
||||
maximumValue={duration > 0 ? duration : 1}
|
||||
value={Math.min(currentTime, duration || 0)}
|
||||
onSlidingComplete={(value) => void seekTo(value)}
|
||||
minimumTrackTintColor={colors.foreground}
|
||||
maximumTrackTintColor={player.trackInactive}
|
||||
thumbTintColor={colors.foreground}
|
||||
/>
|
||||
<View style={styles.timeRow}>
|
||||
<Text style={[styles.time, { color: colors.mutedForeground }]}>
|
||||
{formatDuration(currentTime)}
|
||||
</Text>
|
||||
<Text style={[styles.time, { color: colors.mutedForeground }]}>
|
||||
{formatRemainingDuration(currentTime, duration)}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View style={styles.transport}>
|
||||
<Pressable onPress={() => void skipPrevious()} hitSlop={12}>
|
||||
<Ionicons name="play-back" size={36} color={colors.foreground} />
|
||||
</Pressable>
|
||||
<Pressable onPress={togglePlayback} style={styles.playButton} hitSlop={12}>
|
||||
<Ionicons
|
||||
name={isPlaying ? "pause" : "play"}
|
||||
size={52}
|
||||
color={colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Pressable onPress={() => void skipNext()} hitSlop={12}>
|
||||
<Ionicons name="play-forward" size={36} color={colors.foreground} />
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
<View style={styles.volumeSection}>
|
||||
<Ionicons name="volume-low" size={18} color={colors.mutedForeground} />
|
||||
<Slider
|
||||
style={styles.volumeSlider}
|
||||
minimumValue={0}
|
||||
maximumValue={1}
|
||||
value={volume}
|
||||
onValueChange={setVolume}
|
||||
minimumTrackTintColor={colors.foreground}
|
||||
maximumTrackTintColor={player.trackInactive}
|
||||
thumbTintColor={colors.foreground}
|
||||
/>
|
||||
<Ionicons name="volume-high" size={18} color={colors.mutedForeground} />
|
||||
</View>
|
||||
|
||||
<View style={styles.footer}>
|
||||
<Pressable onPress={() => void toggleShuffle()} hitSlop={12} style={styles.footerButton}>
|
||||
<Ionicons
|
||||
name="shuffle"
|
||||
size={22}
|
||||
color={shuffleEnabled ? appleMusic.pink : colors.mutedForeground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Pressable onPress={() => void cycleRepeat()} hitSlop={12} style={styles.footerButton}>
|
||||
<Ionicons
|
||||
name={repeatEnabled === "once" ? "repeat-outline" : "repeat"}
|
||||
size={22}
|
||||
color={repeatEnabled !== "none" ? appleMusic.pink : colors.mutedForeground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
onPress={() => router.push("/queue")}
|
||||
hitSlop={12}
|
||||
style={styles.footerButton}
|
||||
disabled={queueSongIds.length === 0}
|
||||
>
|
||||
<Ionicons name="list" size={22} color={colors.mutedForeground} />
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
|
||||
<MediaActionsSheet
|
||||
visible={actionsOpen}
|
||||
title={currentSong.title}
|
||||
favorited={favorited}
|
||||
showNavigation
|
||||
onClose={() => setActionsOpen(false)}
|
||||
onAction={handleAction}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
root: {
|
||||
flex: 1,
|
||||
},
|
||||
backgroundImage: {
|
||||
...StyleSheet.absoluteFill,
|
||||
},
|
||||
scrim: {
|
||||
...StyleSheet.absoluteFill,
|
||||
},
|
||||
safe: {
|
||||
flex: 1,
|
||||
paddingHorizontal: spacing.xl,
|
||||
},
|
||||
handleRow: {
|
||||
alignItems: "center",
|
||||
paddingTop: spacing.sm,
|
||||
paddingBottom: spacing.md,
|
||||
},
|
||||
handle: {
|
||||
width: 36,
|
||||
height: 5,
|
||||
borderRadius: radius.full,
|
||||
},
|
||||
upper: {
|
||||
flex: 1,
|
||||
minHeight: 0,
|
||||
justifyContent: "center",
|
||||
},
|
||||
artworkWrap: {
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
paddingVertical: spacing.sm,
|
||||
},
|
||||
artwork: {
|
||||
width: "100%",
|
||||
maxWidth: 320,
|
||||
aspectRatio: 1,
|
||||
borderRadius: 12,
|
||||
shadowColor: "#000",
|
||||
shadowOpacity: 0.45,
|
||||
shadowRadius: 24,
|
||||
shadowOffset: { width: 0, height: 12 },
|
||||
},
|
||||
controls: {
|
||||
flexShrink: 0,
|
||||
},
|
||||
metaRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "flex-start",
|
||||
gap: spacing.md,
|
||||
marginBottom: spacing.md,
|
||||
},
|
||||
metaText: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
},
|
||||
songTitle: {
|
||||
fontSize: 22,
|
||||
fontWeight: "700",
|
||||
lineHeight: 28,
|
||||
},
|
||||
artistName: {
|
||||
fontSize: 18,
|
||||
marginTop: spacing.xs,
|
||||
},
|
||||
metaActions: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingTop: 4,
|
||||
},
|
||||
circleButton: {
|
||||
width: 34,
|
||||
height: 34,
|
||||
borderRadius: 17,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
progressSection: {
|
||||
marginBottom: spacing.lg,
|
||||
},
|
||||
slider: {
|
||||
width: "100%",
|
||||
height: 28,
|
||||
},
|
||||
timeRow: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
marginTop: -4,
|
||||
},
|
||||
time: {
|
||||
fontSize: 13,
|
||||
fontVariant: ["tabular-nums"],
|
||||
},
|
||||
transport: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: 48,
|
||||
marginBottom: spacing.lg,
|
||||
},
|
||||
playButton: {
|
||||
width: 72,
|
||||
alignItems: "center",
|
||||
},
|
||||
volumeSection: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.sm,
|
||||
marginBottom: spacing.md,
|
||||
},
|
||||
volumeSlider: {
|
||||
flex: 1,
|
||||
height: 28,
|
||||
},
|
||||
footer: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
paddingHorizontal: spacing.xxl,
|
||||
paddingTop: spacing.sm,
|
||||
},
|
||||
footerButton: {
|
||||
minWidth: 44,
|
||||
minHeight: 44,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
})
|
||||
@@ -1,13 +1,11 @@
|
||||
import { useMutation, useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import { useLocalSearchParams, useRouter } from "expo-router"
|
||||
import { Stack, useLocalSearchParams, useRouter } from "expo-router"
|
||||
import { useState } from "react"
|
||||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
|
||||
import { MediaActionsSheet, type MediaAction } from "@/components/media-actions-sheet"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { Button, LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset, SongRow } from "@/components/player"
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
@@ -40,22 +38,14 @@ export default function PlaylistScreen() {
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
|
||||
if (playlist === undefined || !config) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Playlist" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (playlist === null) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Playlist" />
|
||||
<View style={styles.empty}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Playlist not found.</Text>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
<View style={[styles.empty, { backgroundColor: colors.background }]}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Playlist not found.</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -103,16 +93,23 @@ export default function PlaylistScreen() {
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader
|
||||
title={playlist.title}
|
||||
right={
|
||||
<Pressable onPress={() => setMenuOpen(true)} hitSlop={8}>
|
||||
<Ionicons name="ellipsis-horizontal" size={22} color={colors.foreground} />
|
||||
</Pressable>
|
||||
}
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: playlist.title,
|
||||
headerLargeTitle: false,
|
||||
headerRight: () => (
|
||||
<Pressable onPress={() => setMenuOpen(true)} hitSlop={8}>
|
||||
<Ionicons name="ellipsis-horizontal" size={22} color={colors.foreground} />
|
||||
</Pressable>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<View style={styles.hero}>
|
||||
<Image
|
||||
source={{ uri: playlistCoverUrl(config.serverUrl, playlist.id ?? "favorites") }}
|
||||
@@ -183,12 +180,11 @@ export default function PlaylistScreen() {
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||
cover: {
|
||||
|
||||
@@ -2,10 +2,8 @@ import { useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import { useState } from "react"
|
||||
import { ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { MediaActionsSheet, type MediaAction } from "@/components/media-actions-sheet"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { Button, LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset, SongRow } from "@/components/player"
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
@@ -27,22 +25,14 @@ export default function FavoritesScreen() {
|
||||
const [actionSong, setActionSong] = useState<BrowseSong | null>(null)
|
||||
|
||||
if (favorites === undefined || !config) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Favorites" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (favorites === null) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Favorites" />
|
||||
<View style={styles.empty}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Sign in to view your favorites.</Text>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
<View style={[styles.empty, { backgroundColor: colors.background }]}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Sign in to view your favorites.</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -63,9 +53,12 @@ export default function FavoritesScreen() {
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Favorites" />
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<View style={styles.hero}>
|
||||
<Image
|
||||
source={{ uri: playlistCoverUrl(config.serverUrl, "favorites") }}
|
||||
@@ -96,12 +89,11 @@ export default function FavoritesScreen() {
|
||||
onClose={() => setActionSong(null)}
|
||||
onAction={handleSongAction}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||
cover: {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { usePaginatedQuery, useQuery } from "convex/react"
|
||||
import { Stack } from "expo-router"
|
||||
import { FlatList, Pressable, StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { Button, LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset, SongRow } from "@/components/player"
|
||||
import { usePlayback } from "@/contexts/playback"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
@@ -44,77 +42,77 @@ export default function QueueScreen() {
|
||||
void reorderQueue(next)
|
||||
}
|
||||
|
||||
if (queueSongs === undefined) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader
|
||||
title="Queue"
|
||||
right={
|
||||
queueSongIds.length > 0 ? (
|
||||
<Button title="Clear" variant="ghost" onPress={() => void clearQueue()} />
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
headerRight: () =>
|
||||
queueSongIds.length > 0 ? (
|
||||
<Button title="Clear" variant="ghost" onPress={() => void clearQueue()} />
|
||||
) : null,
|
||||
}}
|
||||
/>
|
||||
<FlatList
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
ListHeaderComponent={
|
||||
<View>
|
||||
<Text style={[styles.section, { color: colors.mutedForeground }]}>Up Next</Text>
|
||||
{queueSongIds.length === 0 ? (
|
||||
<Text style={[styles.empty, { color: colors.mutedForeground }]}>
|
||||
Queue is empty
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
}
|
||||
data={queueSongs}
|
||||
keyExtractor={(item) => `${item.id}-${item.queueIndex}`}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
onEndReached={() => {
|
||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
||||
}}
|
||||
renderItem={({ item, index }) => (
|
||||
<View>
|
||||
<SongRow
|
||||
song={item}
|
||||
onPress={() => void skipToQueueIndex(item.queueIndex)}
|
||||
/>
|
||||
<View style={styles.queueActions}>
|
||||
<Pressable disabled={index === 0} onPress={() => moveSong(index, -1)}>
|
||||
<Text style={{ color: colors.foreground }}>Move up</Text>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
disabled={index === queueSongIds.length - 1}
|
||||
onPress={() => moveSong(index, 1)}
|
||||
>
|
||||
<Text style={{ color: colors.foreground }}>Move down</Text>
|
||||
</Pressable>
|
||||
{currentSong?.id === item.id ? (
|
||||
<Text style={{ color: colors.primary, fontWeight: "700" }}>Now playing</Text>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
ListFooterComponent={
|
||||
historySongs && historySongs.length > 0 ? (
|
||||
<View style={styles.history}>
|
||||
<Text style={[styles.section, { color: colors.mutedForeground }]}>History</Text>
|
||||
{historySongs.map((song: BrowseSong) => (
|
||||
<SongRow key={song.id} song={song} />
|
||||
))}
|
||||
</View>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
|
||||
{queueSongs === undefined ? (
|
||||
<LoadingView />
|
||||
) : (
|
||||
<FlatList
|
||||
ListHeaderComponent={
|
||||
<View>
|
||||
<Text style={[styles.section, { color: colors.mutedForeground }]}>Up Next</Text>
|
||||
{queueSongIds.length === 0 ? (
|
||||
<Text style={[styles.empty, { color: colors.mutedForeground }]}>
|
||||
Queue is empty
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
}
|
||||
data={queueSongs}
|
||||
keyExtractor={(item) => `${item.id}-${item.queueIndex}`}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
onEndReached={() => {
|
||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
||||
}}
|
||||
renderItem={({ item, index }) => (
|
||||
<View>
|
||||
<SongRow
|
||||
song={item}
|
||||
onPress={() => void skipToQueueIndex(item.queueIndex)}
|
||||
/>
|
||||
<View style={styles.queueActions}>
|
||||
<Pressable disabled={index === 0} onPress={() => moveSong(index, -1)}>
|
||||
<Text style={{ color: colors.foreground }}>Move up</Text>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
disabled={index === queueSongIds.length - 1}
|
||||
onPress={() => moveSong(index, 1)}
|
||||
>
|
||||
<Text style={{ color: colors.foreground }}>Move down</Text>
|
||||
</Pressable>
|
||||
{currentSong?.id === item.id ? (
|
||||
<Text style={{ color: colors.primary, fontWeight: "700" }}>Now playing</Text>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
ListFooterComponent={
|
||||
historySongs && historySongs.length > 0 ? (
|
||||
<View style={styles.history}>
|
||||
<Text style={[styles.section, { color: colors.mutedForeground }]}>History</Text>
|
||||
{historySongs.map((song: BrowseSong) => (
|
||||
<SongRow key={song.id} song={song} />
|
||||
))}
|
||||
</View>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
section: {
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingTop: spacing.md,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { ContentCarousel } from "@/components/media-cards"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { MediaGrid } from "@/components/media-cards"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
@@ -13,21 +11,21 @@ export default function RecentlyAddedScreen() {
|
||||
const colors = useThemeColors()
|
||||
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
|
||||
|
||||
if (recentlyAdded === undefined) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Recently Added" />
|
||||
{recentlyAdded === undefined ? (
|
||||
<LoadingView />
|
||||
) : (
|
||||
<ScrollView contentContainerStyle={[styles.content, { paddingBottom: contentBottomInset }]}>
|
||||
<ContentCarousel title="Recently Added" content={recentlyAdded} />
|
||||
</ScrollView>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={[styles.content, { paddingBottom: contentBottomInset }]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<MediaGrid content={recentlyAdded} />
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
content: { padding: spacing.lg },
|
||||
})
|
||||
@@ -1,9 +1,7 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
import { ScrollView, StyleSheet } from "react-native"
|
||||
|
||||
import { ContentCarousel } from "@/components/media-cards"
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { MediaGrid } from "@/components/media-cards"
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
@@ -13,21 +11,21 @@ export default function RecentlyPlayedScreen() {
|
||||
const colors = useThemeColors()
|
||||
const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed)
|
||||
|
||||
if (recentlyPlayed === undefined) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Recently Played" />
|
||||
{recentlyPlayed === undefined ? (
|
||||
<LoadingView />
|
||||
) : (
|
||||
<ScrollView contentContainerStyle={[styles.content, { paddingBottom: contentBottomInset }]}>
|
||||
<ContentCarousel title="Recently Played" content={recentlyPlayed} />
|
||||
</ScrollView>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={[styles.content, { paddingBottom: contentBottomInset }]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<MediaGrid content={recentlyPlayed} />
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
content: { padding: spacing.lg },
|
||||
})
|
||||
@@ -9,9 +9,7 @@ import {
|
||||
Text,
|
||||
View,
|
||||
} from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { ScreenHeader } from "@/components/screen-header"
|
||||
import { Button, Input, LoadingView } from "@/components/ui/primitives"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
@@ -41,12 +39,7 @@ export default function SettingsScreen() {
|
||||
const [section, setSection] = useState<Section>("profile")
|
||||
|
||||
if (!user) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Settings" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
const isAdmin = user.isAdmin === true
|
||||
@@ -58,9 +51,11 @@ export default function SettingsScreen() {
|
||||
]
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Settings" />
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} style={styles.tabs}>
|
||||
{sections
|
||||
.filter((item) => !item.admin || isAdmin)
|
||||
@@ -96,8 +91,7 @@ export default function SettingsScreen() {
|
||||
<UsersSection users={allUsers} currentUserId={user._id} />
|
||||
) : null}
|
||||
</View>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -350,7 +344,6 @@ function UsersSection({
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
tabs: {
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
import { Stack } from "expo-router"
|
||||
import { useConvexAuth } from "@convex-dev/auth/react"
|
||||
import { Redirect, Stack } from "expo-router"
|
||||
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
|
||||
export default function AuthLayout() {
|
||||
const { config, isLoading: serverLoading } = useServerConfig()
|
||||
const auth = useConvexAuth()
|
||||
|
||||
if (serverLoading) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
return <Redirect href="/server" />
|
||||
}
|
||||
|
||||
if (!auth || auth.isLoading) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (auth.isAuthenticated) {
|
||||
return <Redirect href="/(app)/(tabs)/home" />
|
||||
}
|
||||
|
||||
return <Stack screenOptions={{ headerShown: false }} />
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Stack } from "expo-router"
|
||||
import { StatusBar } from "expo-status-bar"
|
||||
import { useColorScheme } from "react-native"
|
||||
import { GestureHandlerRootView } from "react-native-gesture-handler"
|
||||
import { SafeAreaProvider } from "react-native-safe-area-context"
|
||||
|
||||
@@ -7,13 +8,20 @@ import { ConvexAppProvider } from "@/contexts/convex-app"
|
||||
import { ServerConfigProvider } from "@/contexts/server-config"
|
||||
|
||||
export default function RootLayout() {
|
||||
const colorScheme = useColorScheme()
|
||||
|
||||
return (
|
||||
<GestureHandlerRootView style={{ flex: 1 }}>
|
||||
<SafeAreaProvider>
|
||||
<ServerConfigProvider>
|
||||
<ConvexAppProvider>
|
||||
<StatusBar style="auto" />
|
||||
<Stack screenOptions={{ headerShown: false }} />
|
||||
<StatusBar style={colorScheme === "dark" ? "light" : "dark"} />
|
||||
<Stack screenOptions={{ headerShown: false }}>
|
||||
<Stack.Screen name="index" />
|
||||
<Stack.Screen name="server" />
|
||||
<Stack.Screen name="(auth)" />
|
||||
<Stack.Screen name="(app)" />
|
||||
</Stack>
|
||||
</ConvexAppProvider>
|
||||
</ServerConfigProvider>
|
||||
</SafeAreaProvider>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Redirect } from "expo-router"
|
||||
import { useConvexAuth } from "@convex-dev/auth/react"
|
||||
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { AuthenticatedRedirect } from "@/components/authenticated-redirect"
|
||||
|
||||
export default function Index() {
|
||||
const { config, isLoading } = useServerConfig()
|
||||
const { isLoading: authLoading, isAuthenticated } = useConvexAuth()
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingView />
|
||||
@@ -16,13 +15,5 @@ export default function Index() {
|
||||
return <Redirect href="/server" />
|
||||
}
|
||||
|
||||
if (authLoading) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Redirect href="/signin" />
|
||||
}
|
||||
|
||||
return <Redirect href="/(app)/(tabs)" />
|
||||
return <AuthenticatedRedirect />
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useRouter } from "expo-router"
|
||||
import { useState } from "react"
|
||||
import { useEffect, useState } from "react"
|
||||
import { KeyboardAvoidingView, Platform, StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
@@ -10,11 +10,17 @@ import { spacing, useThemeColors } from "@/lib/theme"
|
||||
export default function ServerScreen() {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const { setServerHostname } = useServerConfig()
|
||||
const { config, isLoading, setServerHostname } = useServerConfig()
|
||||
const [hostname, setHostname] = useState("")
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (config?.hostname) {
|
||||
setHostname(config.hostname)
|
||||
}
|
||||
}, [config?.hostname])
|
||||
|
||||
async function handleContinue() {
|
||||
setError(null)
|
||||
setSubmitting(true)
|
||||
@@ -27,6 +33,10 @@ export default function ServerScreen() {
|
||||
router.replace("/signin")
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]}>
|
||||
<KeyboardAvoidingView
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { Button, Card, Input } from "@/components/ui/primitives"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
@@ -51,6 +52,7 @@ export function AuthForm({ flow }: { flow: AuthFlow }) {
|
||||
const { signIn } = useAuthActions()
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const appSettings = useQuery(api.users.getAppSettings)
|
||||
const [name, setName] = useState("")
|
||||
const [email, setEmail] = useState("")
|
||||
@@ -78,7 +80,7 @@ export function AuthForm({ flow }: { flow: AuthFlow }) {
|
||||
|
||||
try {
|
||||
await signIn("password", formData)
|
||||
router.replace("/(app)/(tabs)")
|
||||
router.replace("/(app)/(tabs)/home")
|
||||
} catch {
|
||||
setError(
|
||||
flow === "signIn"
|
||||
@@ -101,6 +103,11 @@ export function AuthForm({ flow }: { flow: AuthFlow }) {
|
||||
<Text style={[styles.description, { color: colors.mutedForeground }]}>
|
||||
{text.description}
|
||||
</Text>
|
||||
{config ? (
|
||||
<Text style={[styles.server, { color: colors.mutedForeground }]}>
|
||||
Server: {config.hostname}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
{signupsDisabled ? (
|
||||
@@ -172,6 +179,7 @@ const styles = StyleSheet.create({
|
||||
header: { gap: spacing.xs },
|
||||
title: { fontSize: 22, fontWeight: "700" },
|
||||
description: { fontSize: 14, lineHeight: 20 },
|
||||
server: { fontSize: 13, marginTop: spacing.xs },
|
||||
form: { gap: spacing.md },
|
||||
switchRow: {
|
||||
flexDirection: "row",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useConvexAuth } from "@convex-dev/auth/react"
|
||||
import { Redirect } from "expo-router"
|
||||
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
|
||||
export function AuthenticatedRedirect() {
|
||||
const auth = useConvexAuth()
|
||||
|
||||
if (!auth) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
const { isLoading, isAuthenticated } = auth
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Redirect href="/signin" />
|
||||
}
|
||||
|
||||
return <Redirect href="/(app)/(tabs)/home" />
|
||||
}
|
||||
@@ -1,20 +1,30 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Image } from "expo-image"
|
||||
import { useRouter } from "expo-router"
|
||||
import { Pressable, StyleSheet, Text, View } from "react-native"
|
||||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import type { BrowseAlbum, BrowseArtist, PlaylistSummary } from "@otunes/convex/types"
|
||||
import { albumCoverUrl, artistCoverUrl, playlistCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
import { carouselCardWidth, radius, spacing, useThemeColors, useTwoColumnCardWidth } from "@/lib/theme"
|
||||
|
||||
function CoverImage({ uri, size, rounded }: { uri: string; size: number; rounded?: boolean }) {
|
||||
type MediaItem = BrowseAlbum | BrowseArtist | PlaylistSummary
|
||||
|
||||
function CoverImage({
|
||||
uri,
|
||||
size,
|
||||
rounded,
|
||||
}: {
|
||||
uri: string
|
||||
size: number
|
||||
rounded?: boolean
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<Image
|
||||
source={{ uri }}
|
||||
style={[
|
||||
{ width: size, height: size, borderRadius: rounded ? size / 2 : radius.md },
|
||||
{ width: size, height: size, borderRadius: rounded ? size / 2 : radius.sm },
|
||||
{ backgroundColor: colors.muted },
|
||||
]}
|
||||
contentFit="cover"
|
||||
@@ -23,7 +33,13 @@ function CoverImage({ uri, size, rounded }: { uri: string; size: number; rounded
|
||||
)
|
||||
}
|
||||
|
||||
export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
||||
export function AlbumCard({
|
||||
album,
|
||||
width = carouselCardWidth,
|
||||
}: {
|
||||
album: BrowseAlbum
|
||||
width?: number
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const { config } = useServerConfig()
|
||||
const colors = useThemeColors()
|
||||
@@ -31,10 +47,10 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={styles.card}
|
||||
style={[styles.card, { width }]}
|
||||
onPress={() => router.push(`/album/${album.id}`)}
|
||||
>
|
||||
<CoverImage uri={albumCoverUrl(config.serverUrl, album.id)} size={140} />
|
||||
<CoverImage uri={albumCoverUrl(config.serverUrl, album.id)} size={width} />
|
||||
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
||||
{album.title}
|
||||
</Text>
|
||||
@@ -45,7 +61,13 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
||||
)
|
||||
}
|
||||
|
||||
export function ArtistCard({ artist }: { artist: BrowseArtist }) {
|
||||
export function ArtistCard({
|
||||
artist,
|
||||
width = carouselCardWidth,
|
||||
}: {
|
||||
artist: BrowseArtist
|
||||
width?: number
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const { config } = useServerConfig()
|
||||
const colors = useThemeColors()
|
||||
@@ -53,10 +75,10 @@ export function ArtistCard({ artist }: { artist: BrowseArtist }) {
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={styles.card}
|
||||
style={[styles.card, { width }]}
|
||||
onPress={() => router.push(`/artist/${artist.id}`)}
|
||||
>
|
||||
<CoverImage uri={artistCoverUrl(config.serverUrl, artist.id)} size={140} rounded />
|
||||
<CoverImage uri={artistCoverUrl(config.serverUrl, artist.id)} size={width} rounded />
|
||||
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
||||
{artist.name}
|
||||
</Text>
|
||||
@@ -64,7 +86,13 @@ export function ArtistCard({ artist }: { artist: BrowseArtist }) {
|
||||
)
|
||||
}
|
||||
|
||||
export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
|
||||
export function PlaylistCard({
|
||||
playlist,
|
||||
width = carouselCardWidth,
|
||||
}: {
|
||||
playlist: PlaylistSummary
|
||||
width?: number
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const { config } = useServerConfig()
|
||||
const colors = useThemeColors()
|
||||
@@ -72,10 +100,10 @@ export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={styles.card}
|
||||
style={[styles.card, { width }]}
|
||||
onPress={() => router.push(`/playlist/${playlist.id}`)}
|
||||
>
|
||||
<CoverImage uri={playlistCoverUrl(config.serverUrl, playlist.id)} size={140} />
|
||||
<CoverImage uri={playlistCoverUrl(config.serverUrl, playlist.id)} size={width} />
|
||||
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
||||
{playlist.title}
|
||||
</Text>
|
||||
@@ -86,6 +114,26 @@ export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
|
||||
)
|
||||
}
|
||||
|
||||
function renderMediaItem(item: MediaItem, width: number) {
|
||||
if ("owner" in item) return <PlaylistCard playlist={item} width={width} />
|
||||
if ("artist" in item) return <AlbumCard album={item} width={width} />
|
||||
return <ArtistCard artist={item} width={width} />
|
||||
}
|
||||
|
||||
export function MediaGrid({ content }: { content: MediaItem[] }) {
|
||||
const cardWidth = useTwoColumnCardWidth()
|
||||
|
||||
return (
|
||||
<View style={styles.grid}>
|
||||
{content.map((item) => (
|
||||
<View key={item.id} style={{ width: cardWidth }}>
|
||||
{renderMediaItem(item, cardWidth)}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export function ContentCarousel({
|
||||
title,
|
||||
href,
|
||||
@@ -93,7 +141,7 @@ export function ContentCarousel({
|
||||
}: {
|
||||
title: string
|
||||
href?: string
|
||||
content: (BrowseAlbum | BrowseArtist | PlaylistSummary)[]
|
||||
content: MediaItem[]
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
@@ -108,20 +156,21 @@ export function ContentCarousel({
|
||||
<Text style={[styles.sectionTitle, { color: colors.foreground }]}>{title}</Text>
|
||||
{href ? <Ionicons name="chevron-forward" size={18} color={colors.mutedForeground} /> : null}
|
||||
</Pressable>
|
||||
<View style={styles.grid}>
|
||||
{content.map((item) => {
|
||||
if ("owner" in item) return <PlaylistCard key={item.id} playlist={item} />
|
||||
if ("artist" in item) return <AlbumCard key={item.id} album={item} />
|
||||
return <ArtistCard key={item.id} artist={item} />
|
||||
})}
|
||||
</View>
|
||||
<ScrollView
|
||||
horizontal
|
||||
showsHorizontalScrollIndicator={false}
|
||||
contentContainerStyle={styles.carouselContent}
|
||||
>
|
||||
{content.map((item) => (
|
||||
<View key={item.id}>{renderMediaItem(item, carouselCardWidth)}</View>
|
||||
))}
|
||||
</ScrollView>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
card: {
|
||||
width: 140,
|
||||
gap: spacing.xs,
|
||||
},
|
||||
title: {
|
||||
@@ -140,12 +189,15 @@ const styles = StyleSheet.create({
|
||||
gap: spacing.xs,
|
||||
},
|
||||
sectionTitle: {
|
||||
fontSize: 20,
|
||||
fontSize: 22,
|
||||
fontWeight: "700",
|
||||
},
|
||||
carouselContent: {
|
||||
gap: spacing.md,
|
||||
},
|
||||
grid: {
|
||||
flexDirection: "row",
|
||||
flexWrap: "wrap",
|
||||
gap: spacing.lg,
|
||||
gap: spacing.md,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,342 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { BlurView } from "expo-blur"
|
||||
import { Image } from "expo-image"
|
||||
import { NativeTabs } from "expo-router/unstable-native-tabs"
|
||||
import { useRouter, useSegments } from "expo-router"
|
||||
import { Platform, Pressable, StyleSheet, Text, View } from "react-native"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
|
||||
import { usePlayback } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { albumCoverUrl } from "@/lib/urls"
|
||||
import { miniPlayerHeight, tabBarHeight, useBlurTint, useMiniPlayerBackground, useThemeColors } from "@/lib/theme"
|
||||
|
||||
function MiniPlayerContent({
|
||||
compact,
|
||||
variant = "bar",
|
||||
onOpenPlayer,
|
||||
}: {
|
||||
compact?: boolean
|
||||
variant?: "bar" | "accessory"
|
||||
onOpenPlayer: () => void
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const {
|
||||
currentSong,
|
||||
isPlaying,
|
||||
setIsPlaying,
|
||||
skipNext,
|
||||
} = usePlayback()
|
||||
|
||||
if (!currentSong || !config) {
|
||||
return null
|
||||
}
|
||||
|
||||
const isAccessory = variant === "accessory"
|
||||
const artworkStyle = isAccessory ? styles.accessoryArtwork : styles.artwork
|
||||
const rowStyle = compact ? styles.inlineContent : isAccessory ? styles.accessoryContent : styles.content
|
||||
|
||||
if (compact) {
|
||||
return (
|
||||
<Pressable style={rowStyle} onPress={onOpenPlayer}>
|
||||
<Image
|
||||
source={{ uri: albumCoverUrl(config.serverUrl, currentSong.album.id) }}
|
||||
style={isAccessory ? styles.accessoryInlineArtwork : styles.inlineArtwork}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<View style={isAccessory ? styles.accessoryInlineMeta : styles.inlineMeta}>
|
||||
<Text
|
||||
style={[
|
||||
isAccessory ? styles.accessoryTitle : styles.title,
|
||||
{ color: colors.foreground },
|
||||
]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{currentSong.title}
|
||||
</Text>
|
||||
</View>
|
||||
<Pressable
|
||||
style={styles.controlButton}
|
||||
onPress={(event) => {
|
||||
event.stopPropagation()
|
||||
setIsPlaying(!isPlaying)
|
||||
}}
|
||||
hitSlop={6}
|
||||
>
|
||||
<Ionicons
|
||||
name={isPlaying ? "pause" : "play"}
|
||||
size={20}
|
||||
color={colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Pressable style={rowStyle} onPress={onOpenPlayer}>
|
||||
<Image
|
||||
source={{ uri: albumCoverUrl(config.serverUrl, currentSong.album.id) }}
|
||||
style={artworkStyle}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<View style={isAccessory ? styles.accessoryMeta : styles.meta}>
|
||||
<Text
|
||||
style={[
|
||||
isAccessory ? styles.accessoryTitle : styles.title,
|
||||
{ color: colors.foreground },
|
||||
]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{currentSong.title}
|
||||
</Text>
|
||||
<Text
|
||||
style={[
|
||||
isAccessory ? styles.accessoryArtist : styles.artist,
|
||||
{ color: colors.mutedForeground },
|
||||
]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{currentSong.artist.name}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={styles.controls}>
|
||||
<Pressable
|
||||
style={styles.controlButton}
|
||||
onPress={(event) => {
|
||||
event.stopPropagation()
|
||||
setIsPlaying(!isPlaying)
|
||||
}}
|
||||
hitSlop={6}
|
||||
>
|
||||
<Ionicons
|
||||
name={isPlaying ? "pause" : "play"}
|
||||
size={24}
|
||||
color={colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
style={styles.controlButton}
|
||||
onPress={(event) => {
|
||||
event.stopPropagation()
|
||||
void skipNext()
|
||||
}}
|
||||
hitSlop={6}
|
||||
>
|
||||
<Ionicons name="play-forward" size={24} color={colors.foreground} />
|
||||
</Pressable>
|
||||
</View>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
|
||||
const colors = useThemeColors()
|
||||
const blurTint = useBlurTint()
|
||||
const backgroundColor = useMiniPlayerBackground()
|
||||
|
||||
if (Platform.OS === "ios") {
|
||||
return (
|
||||
<BlurView intensity={80} tint={blurTint} style={styles.blur}>
|
||||
<View style={[styles.topBorder, { backgroundColor: colors.border }]} />
|
||||
{children}
|
||||
</BlurView>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={[styles.androidBar, { backgroundColor }]}>
|
||||
<View style={[styles.topBorder, { backgroundColor: colors.border }]} />
|
||||
{children}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export function TabBottomAccessory() {
|
||||
const router = useRouter()
|
||||
const { currentSong, queueSongIds } = usePlayback()
|
||||
const placement = NativeTabs.BottomAccessory.usePlacement()
|
||||
|
||||
if (!currentSong || queueSongIds.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
const content = (
|
||||
<View style={styles.accessoryContainer}>
|
||||
<MiniPlayerContent
|
||||
compact={placement === "inline"}
|
||||
variant="accessory"
|
||||
onOpenPlayer={() => router.push("/player")}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
|
||||
if (Platform.OS === "android") {
|
||||
return <MiniPlayerChrome>{content}</MiniPlayerChrome>
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
function useFloatingMiniPlayerLayout() {
|
||||
const segments = useSegments() as string[]
|
||||
const insets = useSafeAreaInsets()
|
||||
|
||||
const onPlayerModal = segments.includes("player")
|
||||
const onAuthFlow =
|
||||
segments.includes("signin") ||
|
||||
segments.includes("signup") ||
|
||||
segments.includes("server")
|
||||
const onTabs = segments.includes("(tabs)")
|
||||
|
||||
const bottom = insets.bottom + (onTabs ? 0 : 0)
|
||||
|
||||
return {
|
||||
bottom,
|
||||
hidden: onPlayerModal || onAuthFlow || onTabs,
|
||||
}
|
||||
}
|
||||
|
||||
export function FloatingMiniPlayer() {
|
||||
const router = useRouter()
|
||||
const { bottom, hidden } = useFloatingMiniPlayerLayout()
|
||||
const { currentSong, queueSongIds } = usePlayback()
|
||||
|
||||
if (hidden || !currentSong || queueSongIds.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<View pointerEvents="box-none" style={[styles.floatingContainer, { bottom }]}>
|
||||
<MiniPlayerChrome>
|
||||
<MiniPlayerContent onOpenPlayer={() => router.push("/player")} />
|
||||
</MiniPlayerChrome>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
floatingContainer: {
|
||||
position: "absolute",
|
||||
left: 0,
|
||||
right: 0,
|
||||
zIndex: 100,
|
||||
},
|
||||
accessoryContainer: {
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
alignSelf: "stretch",
|
||||
},
|
||||
blur: {
|
||||
overflow: "hidden",
|
||||
},
|
||||
androidBar: {
|
||||
overflow: "hidden",
|
||||
},
|
||||
topBorder: {
|
||||
height: StyleSheet.hairlineWidth,
|
||||
},
|
||||
content: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 10,
|
||||
minHeight: miniPlayerHeight,
|
||||
gap: 12,
|
||||
},
|
||||
accessoryContent: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
alignSelf: "stretch",
|
||||
paddingHorizontal: 12,
|
||||
paddingVertical: 8,
|
||||
gap: 12,
|
||||
},
|
||||
inlineContent: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
alignSelf: "stretch",
|
||||
paddingHorizontal: 12,
|
||||
paddingVertical: 8,
|
||||
gap: 10,
|
||||
},
|
||||
artwork: {
|
||||
width: 36,
|
||||
height: 36,
|
||||
borderRadius: 5,
|
||||
},
|
||||
accessoryArtwork: {
|
||||
width: 32,
|
||||
height: 32,
|
||||
borderRadius: 4,
|
||||
},
|
||||
inlineArtwork: {
|
||||
width: 28,
|
||||
height: 28,
|
||||
borderRadius: 4,
|
||||
},
|
||||
accessoryInlineArtwork: {
|
||||
width: 24,
|
||||
height: 24,
|
||||
borderRadius: 4,
|
||||
},
|
||||
meta: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
justifyContent: "center",
|
||||
},
|
||||
accessoryMeta: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
justifyContent: "center",
|
||||
paddingTop: 3,
|
||||
},
|
||||
inlineMeta: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
justifyContent: "center",
|
||||
},
|
||||
accessoryInlineMeta: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
justifyContent: "center",
|
||||
paddingTop: 2,
|
||||
},
|
||||
title: {
|
||||
fontSize: 15,
|
||||
fontWeight: "500",
|
||||
lineHeight: 18,
|
||||
},
|
||||
accessoryTitle: {
|
||||
fontSize: 14,
|
||||
fontWeight: "500",
|
||||
lineHeight: 17,
|
||||
},
|
||||
artist: {
|
||||
fontSize: 13,
|
||||
lineHeight: 16,
|
||||
marginTop: 2,
|
||||
},
|
||||
accessoryArtist: {
|
||||
fontSize: 12,
|
||||
lineHeight: 15,
|
||||
marginTop: 1,
|
||||
},
|
||||
controls: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: 4,
|
||||
marginLeft: 4,
|
||||
},
|
||||
controlButton: {
|
||||
width: 36,
|
||||
height: 36,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
})
|
||||
|
||||
export { miniPlayerHeight, tabBarHeight }
|
||||
@@ -1,132 +1,16 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Image } from "expo-image"
|
||||
import { useRouter } from "expo-router"
|
||||
import { Pressable, StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { usePlayback } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { formatDuration } from "@/lib/format"
|
||||
import { albumCoverUrl } from "@/lib/urls"
|
||||
import { playerBarHeight, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export function PlayerBar() {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const {
|
||||
currentSong,
|
||||
isPlaying,
|
||||
shuffleEnabled,
|
||||
repeatEnabled,
|
||||
currentTime,
|
||||
duration,
|
||||
queueSongIds,
|
||||
setIsPlaying,
|
||||
seekTo,
|
||||
toggleShuffle,
|
||||
cycleRepeat,
|
||||
skipNext,
|
||||
skipPrevious,
|
||||
} = usePlayback()
|
||||
|
||||
const hasQueue = queueSongIds.length > 0
|
||||
|
||||
return (
|
||||
<View style={[styles.container, { backgroundColor: colors.card, borderColor: colors.border }]}>
|
||||
<Pressable
|
||||
style={styles.songArea}
|
||||
onPress={() => router.push("/queue")}
|
||||
disabled={!currentSong}
|
||||
>
|
||||
{currentSong && config ? (
|
||||
<>
|
||||
<Image
|
||||
source={{ uri: albumCoverUrl(config.serverUrl, currentSong.album.id) }}
|
||||
style={styles.artwork}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<View style={styles.meta}>
|
||||
<Text style={[styles.songTitle, { color: colors.foreground }]} numberOfLines={1}>
|
||||
{currentSong.title}
|
||||
</Text>
|
||||
<Text style={[styles.artistName, { color: colors.mutedForeground }]} numberOfLines={1}>
|
||||
{currentSong.artist.name}
|
||||
</Text>
|
||||
</View>
|
||||
</>
|
||||
) : (
|
||||
<Text style={[styles.placeholder, { color: colors.mutedForeground }]}>oTunes</Text>
|
||||
)}
|
||||
</Pressable>
|
||||
|
||||
<View style={styles.controls}>
|
||||
<Pressable onPress={() => void toggleShuffle()} hitSlop={8}>
|
||||
<Ionicons
|
||||
name="shuffle"
|
||||
size={18}
|
||||
color={shuffleEnabled ? colors.primary : colors.mutedForeground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Pressable disabled={!hasQueue} onPress={() => void skipPrevious()} hitSlop={8}>
|
||||
<Ionicons name="play-skip-back" size={22} color={colors.foreground} />
|
||||
</Pressable>
|
||||
<Pressable
|
||||
disabled={!hasQueue}
|
||||
onPress={() => setIsPlaying(!isPlaying)}
|
||||
style={[styles.playButton, { backgroundColor: colors.primary }]}
|
||||
>
|
||||
<Ionicons
|
||||
name={isPlaying ? "pause" : "play"}
|
||||
size={20}
|
||||
color={colors.primaryForeground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Pressable disabled={!hasQueue} onPress={() => void skipNext()} hitSlop={8}>
|
||||
<Ionicons name="play-skip-forward" size={22} color={colors.foreground} />
|
||||
</Pressable>
|
||||
<Pressable onPress={() => void cycleRepeat()} hitSlop={8}>
|
||||
<Ionicons
|
||||
name={repeatEnabled === "once" ? "repeat-outline" : "repeat"}
|
||||
size={18}
|
||||
color={repeatEnabled !== "none" ? colors.primary : colors.mutedForeground}
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{currentSong ? (
|
||||
<View style={styles.progressRow}>
|
||||
<Text style={[styles.time, { color: colors.mutedForeground }]}>
|
||||
{formatDuration(currentTime)}
|
||||
</Text>
|
||||
<Pressable
|
||||
style={[styles.progressTrack, { backgroundColor: colors.muted }]}
|
||||
onPress={(event) => {
|
||||
const { locationX } = event.nativeEvent
|
||||
const width = event.currentTarget as unknown as { offsetWidth?: number }
|
||||
const trackWidth = 200
|
||||
const ratio = Math.min(1, Math.max(0, locationX / trackWidth))
|
||||
void seekTo(ratio * duration)
|
||||
}}
|
||||
>
|
||||
<View
|
||||
style={[
|
||||
styles.progressFill,
|
||||
{
|
||||
backgroundColor: colors.primary,
|
||||
width: `${duration > 0 ? (currentTime / duration) * 100 : 0}%`,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Pressable>
|
||||
<Text style={[styles.time, { color: colors.mutedForeground }]}>
|
||||
{formatDuration(duration)}
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
import {
|
||||
miniPlayerHeight,
|
||||
spacing,
|
||||
tabBarHeight,
|
||||
useThemeColors,
|
||||
} from "@/lib/theme"
|
||||
|
||||
export function SongRow({
|
||||
song,
|
||||
@@ -170,74 +54,10 @@ export function SongRow({
|
||||
)
|
||||
}
|
||||
|
||||
export const contentBottomInset = playerBarHeight + spacing.lg
|
||||
export const tabContentBottomInset = spacing.lg
|
||||
export const contentBottomInset = miniPlayerHeight + spacing.lg
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
borderTopWidth: StyleSheet.hairlineWidth,
|
||||
paddingHorizontal: spacing.md,
|
||||
paddingTop: spacing.sm,
|
||||
paddingBottom: spacing.md,
|
||||
gap: spacing.sm,
|
||||
},
|
||||
songArea: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.sm,
|
||||
minHeight: 40,
|
||||
},
|
||||
artwork: {
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 6,
|
||||
},
|
||||
meta: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
},
|
||||
songTitle: {
|
||||
fontSize: 14,
|
||||
fontWeight: "600",
|
||||
},
|
||||
artistName: {
|
||||
fontSize: 12,
|
||||
},
|
||||
placeholder: {
|
||||
fontSize: 14,
|
||||
fontWeight: "600",
|
||||
},
|
||||
controls: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: spacing.lg,
|
||||
},
|
||||
playButton: {
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 20,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
progressRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.sm,
|
||||
},
|
||||
time: {
|
||||
fontSize: 11,
|
||||
width: 36,
|
||||
textAlign: "center",
|
||||
},
|
||||
progressTrack: {
|
||||
flex: 1,
|
||||
height: 4,
|
||||
borderRadius: 2,
|
||||
overflow: "hidden",
|
||||
},
|
||||
progressFill: {
|
||||
height: "100%",
|
||||
},
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import { StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export function ScreenHeader({
|
||||
title,
|
||||
right,
|
||||
}: {
|
||||
title: string
|
||||
right?: React.ReactNode
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<View style={[styles.header, { borderBottomColor: colors.border, backgroundColor: colors.background }]}>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>{title}</Text>
|
||||
{right}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
header: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
title: {
|
||||
fontSize: 20,
|
||||
fontWeight: "700",
|
||||
},
|
||||
})
|
||||
@@ -1,4 +1,9 @@
|
||||
import { Audio, AVPlaybackStatus } from "expo-av"
|
||||
import {
|
||||
createAudioPlayer,
|
||||
setAudioModeAsync,
|
||||
type AudioPlayer,
|
||||
type AudioStatus,
|
||||
} from "expo-audio"
|
||||
import { useConvex, useMutation, useQuery } from "convex/react"
|
||||
import {
|
||||
createContext,
|
||||
@@ -92,12 +97,14 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
const user = useQuery(api.auth.currentUser)
|
||||
const playback = useQuery(api.playback.getPlaybackState)
|
||||
|
||||
const soundRef = useRef<Audio.Sound | null>(null)
|
||||
const loadedSongIdRef = useRef<string | null>(null)
|
||||
const playerRef = useRef<AudioPlayer | null>(null)
|
||||
const statusSubscriptionRef = useRef<{ remove: () => void } | null>(null)
|
||||
const loadedSongKeyRef = useRef<string | null>(null)
|
||||
const autoPlayNextRef = useRef(false)
|
||||
const isPlayingRef = useRef(false)
|
||||
const progressRestoredForSongRef = useRef<Id<"songs"> | null>(null)
|
||||
const lastSavedProgressRef = useRef(-1)
|
||||
const pendingSeekRef = useRef<number | null>(null)
|
||||
|
||||
const [isPlaying, setIsPlayingState] = useState(false)
|
||||
const [currentTime, setCurrentTime] = useState(0)
|
||||
@@ -126,12 +133,110 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
const repeatEnabled = playback?.repeatEnabled ?? "none"
|
||||
const queueLength = playback?.queueSongIds.length ?? 0
|
||||
|
||||
const repeatEnabledRef = useRef(repeatEnabled)
|
||||
const queueLengthRef = useRef(queueLength)
|
||||
|
||||
useEffect(() => {
|
||||
void Audio.setAudioModeAsync({
|
||||
playsInSilentModeIOS: true,
|
||||
staysActiveInBackground: true,
|
||||
shouldDuckAndroid: true,
|
||||
repeatEnabledRef.current = repeatEnabled
|
||||
}, [repeatEnabled])
|
||||
|
||||
useEffect(() => {
|
||||
queueLengthRef.current = queueLength
|
||||
}, [queueLength])
|
||||
|
||||
const skipNextMutationRef = useRef(skipNextMutation)
|
||||
useEffect(() => {
|
||||
skipNextMutationRef.current = skipNextMutation
|
||||
}, [skipNextMutation])
|
||||
|
||||
const destroyPlayer = useCallback(() => {
|
||||
statusSubscriptionRef.current?.remove()
|
||||
statusSubscriptionRef.current = null
|
||||
playerRef.current?.remove()
|
||||
playerRef.current = null
|
||||
loadedSongKeyRef.current = null
|
||||
}, [])
|
||||
|
||||
const handlePlaybackStatusUpdate = useCallback((status: AudioStatus) => {
|
||||
if (!status.isLoaded) return
|
||||
|
||||
setCurrentTime(status.currentTime)
|
||||
if (status.duration > 0) {
|
||||
setDuration(status.duration)
|
||||
}
|
||||
|
||||
if (pendingSeekRef.current !== null && pendingSeekRef.current > 0) {
|
||||
const seekSeconds = pendingSeekRef.current
|
||||
pendingSeekRef.current = null
|
||||
void playerRef.current?.seekTo(seekSeconds)
|
||||
setCurrentTime(seekSeconds)
|
||||
}
|
||||
|
||||
if (
|
||||
(isPlayingRef.current || autoPlayNextRef.current) &&
|
||||
status.isLoaded &&
|
||||
!status.playing &&
|
||||
!status.didJustFinish
|
||||
) {
|
||||
playerRef.current?.play()
|
||||
}
|
||||
|
||||
if (status.didJustFinish) {
|
||||
if (repeatEnabledRef.current === "once") {
|
||||
void playerRef.current?.seekTo(0)
|
||||
playerRef.current?.play()
|
||||
return
|
||||
}
|
||||
|
||||
const shouldContinue =
|
||||
repeatEnabledRef.current !== "none" || queueLengthRef.current > 1
|
||||
if (shouldContinue) {
|
||||
autoPlayNextRef.current = true
|
||||
isPlayingRef.current = true
|
||||
setIsPlayingState(true)
|
||||
}
|
||||
|
||||
void skipNextMutationRef
|
||||
.current()
|
||||
.then(() => {
|
||||
if (shouldContinue) {
|
||||
autoPlayNextRef.current = true
|
||||
isPlayingRef.current = true
|
||||
setIsPlayingState(true)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
autoPlayNextRef.current = false
|
||||
isPlayingRef.current = false
|
||||
setIsPlayingState(false)
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
|
||||
const ensurePlayer = useCallback(() => {
|
||||
if (playerRef.current) {
|
||||
return playerRef.current
|
||||
}
|
||||
|
||||
const player = createAudioPlayer(null, { updateInterval: 500 })
|
||||
player.volume = volume
|
||||
statusSubscriptionRef.current = player.addListener(
|
||||
"playbackStatusUpdate",
|
||||
handlePlaybackStatusUpdate
|
||||
)
|
||||
playerRef.current = player
|
||||
return player
|
||||
}, [handlePlaybackStatusUpdate, volume])
|
||||
|
||||
useEffect(() => {
|
||||
void setAudioModeAsync({
|
||||
playsInSilentMode: true,
|
||||
shouldPlayInBackground: true,
|
||||
interruptionMode: "duckOthers",
|
||||
allowsRecording: false,
|
||||
shouldRouteThroughEarpiece: false,
|
||||
})
|
||||
|
||||
void AsyncStorage.getItem(VOLUME_STORAGE_KEY).then((stored) => {
|
||||
if (stored) {
|
||||
const parsed = Number(stored)
|
||||
@@ -140,20 +245,27 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
void soundRef.current?.unloadAsync()
|
||||
destroyPlayer()
|
||||
}
|
||||
}, [])
|
||||
}, [destroyPlayer])
|
||||
|
||||
useEffect(() => {
|
||||
if (playerRef.current) {
|
||||
playerRef.current.volume = volume
|
||||
}
|
||||
}, [volume])
|
||||
|
||||
const setIsPlaying = useCallback((playing: boolean) => {
|
||||
isPlayingRef.current = playing
|
||||
setIsPlayingState(playing)
|
||||
const sound = soundRef.current
|
||||
if (!sound) return
|
||||
const player = playerRef.current
|
||||
if (!player) return
|
||||
if (playing) {
|
||||
void sound.playAsync()
|
||||
player.play()
|
||||
} else {
|
||||
void sound.pauseAsync()
|
||||
player.pause()
|
||||
}
|
||||
}, [])
|
||||
|
||||
@@ -161,15 +273,17 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
const clamped = Math.min(1, Math.max(0, nextVolume))
|
||||
setVolumeState(clamped)
|
||||
void AsyncStorage.setItem(VOLUME_STORAGE_KEY, String(clamped))
|
||||
void soundRef.current?.setVolumeAsync(clamped)
|
||||
if (playerRef.current) {
|
||||
playerRef.current.volume = clamped
|
||||
}
|
||||
}, [])
|
||||
|
||||
const seekTo = useCallback(
|
||||
async (seconds: number) => {
|
||||
const sound = soundRef.current
|
||||
if (!sound) return
|
||||
const player = playerRef.current
|
||||
if (!player) return
|
||||
const clamped = Math.max(0, Math.min(seconds, duration || 0))
|
||||
await sound.setPositionAsync(clamped * 1000)
|
||||
await player.seekTo(clamped)
|
||||
setCurrentTime(clamped)
|
||||
},
|
||||
[duration]
|
||||
@@ -185,44 +299,6 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
[updateSongProgressMutation]
|
||||
)
|
||||
|
||||
const onPlaybackStatusUpdate = useCallback(
|
||||
(status: AVPlaybackStatus) => {
|
||||
if (!status.isLoaded) return
|
||||
setCurrentTime(status.positionMillis / 1000)
|
||||
if (status.durationMillis) {
|
||||
setDuration(status.durationMillis / 1000)
|
||||
}
|
||||
if (status.didJustFinish) {
|
||||
if (repeatEnabled === "once") {
|
||||
void soundRef.current?.setPositionAsync(0)
|
||||
void soundRef.current?.playAsync()
|
||||
return
|
||||
}
|
||||
const shouldContinue =
|
||||
repeatEnabled !== "none" || queueLength > 1
|
||||
if (shouldContinue) {
|
||||
autoPlayNextRef.current = true
|
||||
isPlayingRef.current = true
|
||||
setIsPlayingState(true)
|
||||
}
|
||||
void skipNextMutation()
|
||||
.then(() => {
|
||||
if (shouldContinue) {
|
||||
autoPlayNextRef.current = true
|
||||
isPlayingRef.current = true
|
||||
setIsPlayingState(true)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
autoPlayNextRef.current = false
|
||||
isPlayingRef.current = false
|
||||
setIsPlayingState(false)
|
||||
})
|
||||
}
|
||||
},
|
||||
[repeatEnabled, queueLength, skipNextMutation]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentSong || !playback) return
|
||||
if (progressRestoredForSongRef.current === currentSong.id) return
|
||||
@@ -235,16 +311,14 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
async function loadSong() {
|
||||
if (!config || !currentSong || user === undefined || !user) {
|
||||
if (!currentSong) {
|
||||
loadedSongIdRef.current = null
|
||||
await soundRef.current?.unloadAsync()
|
||||
soundRef.current = null
|
||||
destroyPlayer()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const settings = playbackLoadSettings(user)
|
||||
const loadKey = `${currentSong.id}:${settings.playbackQuality}:${settings.useHls ? "hls" : "file"}`
|
||||
if (loadedSongIdRef.current === loadKey) return
|
||||
if (loadedSongKeyRef.current === loadKey) return
|
||||
|
||||
const uri = settings.useHls
|
||||
? songHlsPlaylistUrl(
|
||||
@@ -260,22 +334,21 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
settings.preferAtmos
|
||||
)
|
||||
|
||||
await soundRef.current?.unloadAsync()
|
||||
const { sound } = await Audio.Sound.createAsync(
|
||||
{ uri },
|
||||
{
|
||||
shouldPlay: isPlayingRef.current || autoPlayNextRef.current,
|
||||
volume,
|
||||
progressUpdateIntervalMillis: 500,
|
||||
},
|
||||
onPlaybackStatusUpdate
|
||||
)
|
||||
soundRef.current = sound
|
||||
loadedSongIdRef.current = loadKey
|
||||
const player = ensurePlayer()
|
||||
loadedSongKeyRef.current = loadKey
|
||||
|
||||
if (progressToRestore && progressToRestore > 0) {
|
||||
await sound.setPositionAsync(progressToRestore * 1000)
|
||||
pendingSeekRef.current = progressToRestore
|
||||
setProgressToRestore(null)
|
||||
} else {
|
||||
pendingSeekRef.current = null
|
||||
}
|
||||
|
||||
player.replace(uri)
|
||||
player.volume = volume
|
||||
|
||||
if (isPlayingRef.current || autoPlayNextRef.current) {
|
||||
player.play()
|
||||
}
|
||||
|
||||
setDuration(currentSong.durationSeconds)
|
||||
@@ -293,7 +366,8 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
user?.preferAtmos,
|
||||
user === undefined,
|
||||
volume,
|
||||
onPlaybackStatusUpdate,
|
||||
destroyPlayer,
|
||||
ensurePlayer,
|
||||
clearQueueMutation,
|
||||
progressToRestore,
|
||||
currentSong,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
@@ -8,12 +7,15 @@ import {
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
|
||||
import { secureGetItem, secureRemoveItem, secureSetItem } from "@/lib/auth-storage"
|
||||
import {
|
||||
clearServerConfig,
|
||||
loadServerConfig,
|
||||
parseServerHostname,
|
||||
saveServerConfig,
|
||||
LEGACY_SERVER_CONFIG_KEY,
|
||||
type ServerConfig,
|
||||
} from "@/lib/server-config"
|
||||
|
||||
@@ -32,12 +34,28 @@ export function ServerConfigProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
void loadServerConfig((key) => AsyncStorage.getItem(key)).then((loaded) => {
|
||||
void (async () => {
|
||||
let loaded = await loadServerConfig(secureGetItem)
|
||||
if (!loaded) {
|
||||
const legacy = await AsyncStorage.getItem(LEGACY_SERVER_CONFIG_KEY)
|
||||
if (legacy) {
|
||||
try {
|
||||
const parsed = JSON.parse(legacy) as ServerConfig
|
||||
if (parsed.hostname && parsed.serverUrl && parsed.convexUrl) {
|
||||
await saveServerConfig(secureSetItem, parsed)
|
||||
await AsyncStorage.removeItem(LEGACY_SERVER_CONFIG_KEY)
|
||||
loaded = parsed
|
||||
}
|
||||
} catch {
|
||||
// Ignore invalid legacy data.
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cancelled) {
|
||||
setConfig(loaded)
|
||||
setIsLoading(false)
|
||||
}
|
||||
})
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
@@ -46,16 +64,13 @@ export function ServerConfigProvider({ children }: { children: ReactNode }) {
|
||||
const setServerHostname = useCallback(async (hostname: string) => {
|
||||
const parsed = parseServerHostname(hostname)
|
||||
if (!parsed) return false
|
||||
await saveServerConfig(
|
||||
(key, value) => AsyncStorage.setItem(key, value),
|
||||
parsed
|
||||
)
|
||||
await saveServerConfig(secureSetItem, parsed)
|
||||
setConfig(parsed)
|
||||
return true
|
||||
}, [])
|
||||
|
||||
const clearServer = useCallback(async () => {
|
||||
await clearServerConfig((key) => AsyncStorage.removeItem(key))
|
||||
await clearServerConfig(secureRemoveItem)
|
||||
setConfig(null)
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -1,14 +1,38 @@
|
||||
import * as SecureStore from "expo-secure-store"
|
||||
import type { TokenStorage } from "@convex-dev/auth/react"
|
||||
|
||||
const secureStoreOptions: SecureStore.SecureStoreOptions = {
|
||||
keychainAccessible: SecureStore.AFTER_FIRST_UNLOCK,
|
||||
}
|
||||
|
||||
export async function secureGetItem(key: string): Promise<string | null> {
|
||||
try {
|
||||
return await SecureStore.getItemAsync(key, secureStoreOptions)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function secureSetItem(key: string, value: string): Promise<void> {
|
||||
await SecureStore.setItemAsync(key, value, secureStoreOptions)
|
||||
}
|
||||
|
||||
export async function secureRemoveItem(key: string): Promise<void> {
|
||||
try {
|
||||
await SecureStore.deleteItemAsync(key, secureStoreOptions)
|
||||
} catch {
|
||||
// Item may already be gone.
|
||||
}
|
||||
}
|
||||
|
||||
export const secureStorage: TokenStorage = {
|
||||
getItem(key) {
|
||||
return SecureStore.getItemAsync(key)
|
||||
return secureGetItem(key)
|
||||
},
|
||||
setItem(key, value) {
|
||||
return SecureStore.setItemAsync(key, value)
|
||||
return secureSetItem(key, value)
|
||||
},
|
||||
removeItem(key) {
|
||||
return SecureStore.deleteItemAsync(key)
|
||||
return secureRemoveItem(key)
|
||||
},
|
||||
}
|
||||
@@ -5,6 +5,11 @@ export function formatDuration(seconds: number): string {
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`
|
||||
}
|
||||
|
||||
export function formatRemainingDuration(current: number, total: number): string {
|
||||
const remaining = Math.max(0, Math.floor(total) - Math.floor(current))
|
||||
return `-${formatDuration(remaining)}`
|
||||
}
|
||||
|
||||
export function sumDurationSeconds(durations: number[]): number {
|
||||
return durations.reduce((sum, value) => sum + value, 0)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { useColorScheme } from "react-native"
|
||||
|
||||
import { colors } from "@/lib/theme"
|
||||
|
||||
type StackScreenOptions = {
|
||||
title?: string
|
||||
headerLargeTitle?: boolean
|
||||
headerShadowVisible?: boolean
|
||||
headerStyle?: { backgroundColor?: string }
|
||||
headerTintColor?: string
|
||||
headerLargeTitleStyle?: { color?: string }
|
||||
headerBackButtonDisplayMode?: "minimal" | "default" | "generic"
|
||||
contentStyle?: { backgroundColor?: string }
|
||||
headerShown?: boolean
|
||||
headerRight?: () => React.ReactNode
|
||||
presentation?: "card" | "modal" | "transparentModal" | "containedModal" | "fullScreenModal"
|
||||
animation?: "default" | "fade" | "fade_from_bottom" | "flip" | "simple_push" | "slide_from_bottom" | "slide_from_right" | "slide_from_left" | "none"
|
||||
gestureEnabled?: boolean
|
||||
}
|
||||
|
||||
export function useStackScreenOptions(
|
||||
overrides?: StackScreenOptions
|
||||
): StackScreenOptions {
|
||||
const scheme = useColorScheme()
|
||||
const theme = scheme === "dark" ? colors.dark : colors.light
|
||||
|
||||
return {
|
||||
headerLargeTitle: true,
|
||||
headerShadowVisible: false,
|
||||
headerStyle: { backgroundColor: theme.background },
|
||||
headerTintColor: theme.foreground,
|
||||
headerLargeTitleStyle: { color: theme.foreground },
|
||||
headerBackButtonDisplayMode: "minimal",
|
||||
contentStyle: { backgroundColor: theme.background },
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ export type ServerConfig = {
|
||||
convexUrl: string
|
||||
}
|
||||
|
||||
const SERVER_CONFIG_KEY = "otunes:server-config"
|
||||
const SERVER_CONFIG_KEY = "otunes.server-config"
|
||||
const LEGACY_SERVER_CONFIG_KEY = "otunes:server-config"
|
||||
|
||||
function isLocalHost(hostname: string): boolean {
|
||||
const host = hostname.split(":")[0]?.toLowerCase() ?? ""
|
||||
@@ -81,4 +82,4 @@ export async function clearServerConfig(
|
||||
await removeItem(SERVER_CONFIG_KEY)
|
||||
}
|
||||
|
||||
export { SERVER_CONFIG_KEY }
|
||||
export { SERVER_CONFIG_KEY, LEGACY_SERVER_CONFIG_KEY }
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { useRouter } from "expo-router"
|
||||
|
||||
type AppRouter = ReturnType<typeof useRouter>
|
||||
|
||||
export async function signOutToSignIn(
|
||||
signOut: () => Promise<void>,
|
||||
router: Pick<AppRouter, "replace">
|
||||
) {
|
||||
await signOut()
|
||||
router.replace("/signin")
|
||||
}
|
||||
+78
-14
@@ -1,4 +1,18 @@
|
||||
import { useColorScheme } from "react-native"
|
||||
import { Platform, useColorScheme, useWindowDimensions } from "react-native"
|
||||
|
||||
export const appleMusic = {
|
||||
pink: "#FA2D48",
|
||||
background: "#000000",
|
||||
elevated: "#1C1C1E",
|
||||
secondary: "#2C2C2E",
|
||||
label: "#FFFFFF",
|
||||
secondaryLabel: "rgba(235, 235, 245, 0.6)",
|
||||
tertiaryLabel: "rgba(235, 235, 245, 0.3)",
|
||||
separator: "rgba(84, 84, 88, 0.65)",
|
||||
tabInactive: "#8E8E93",
|
||||
miniPlayer: "rgba(28, 28, 30, 0.92)",
|
||||
miniPlayerLight: "rgba(255, 255, 255, 0.92)",
|
||||
} as const
|
||||
|
||||
export const colors = {
|
||||
light: {
|
||||
@@ -8,22 +22,24 @@ export const colors = {
|
||||
muted: "#f4f4f5",
|
||||
mutedForeground: "#71717a",
|
||||
border: "#e4e4e7",
|
||||
primary: "#18181b",
|
||||
primaryForeground: "#fafafa",
|
||||
primary: appleMusic.pink,
|
||||
primaryForeground: "#ffffff",
|
||||
destructive: "#dc2626",
|
||||
accent: "#f4f4f5",
|
||||
accentForeground: appleMusic.pink,
|
||||
},
|
||||
dark: {
|
||||
background: "#0a0a0a",
|
||||
foreground: "#fafafa",
|
||||
card: "#171717",
|
||||
muted: "#262626",
|
||||
mutedForeground: "#a1a1aa",
|
||||
border: "#27272a",
|
||||
primary: "#fafafa",
|
||||
primaryForeground: "#18181b",
|
||||
destructive: "#ef4444",
|
||||
accent: "#262626",
|
||||
background: appleMusic.background,
|
||||
foreground: appleMusic.label,
|
||||
card: appleMusic.elevated,
|
||||
muted: appleMusic.secondary,
|
||||
mutedForeground: appleMusic.secondaryLabel,
|
||||
border: appleMusic.separator,
|
||||
primary: appleMusic.pink,
|
||||
primaryForeground: "#ffffff",
|
||||
destructive: "#FF453A",
|
||||
accent: appleMusic.secondary,
|
||||
accentForeground: appleMusic.pink,
|
||||
},
|
||||
} as const
|
||||
|
||||
@@ -34,6 +50,36 @@ export function useThemeColors(): ThemeColors {
|
||||
return scheme === "dark" ? colors.dark : colors.light
|
||||
}
|
||||
|
||||
export function useIsDark(): boolean {
|
||||
return useColorScheme() === "dark"
|
||||
}
|
||||
|
||||
export function useBlurTint(): "light" | "dark" {
|
||||
return useIsDark() ? "dark" : "light"
|
||||
}
|
||||
|
||||
export function useMiniPlayerBackground(): string {
|
||||
return useIsDark() ? appleMusic.miniPlayer : appleMusic.miniPlayerLight
|
||||
}
|
||||
|
||||
export function usePlayerTheme() {
|
||||
const theme = useThemeColors()
|
||||
const isDark = useIsDark()
|
||||
|
||||
return {
|
||||
colors: theme,
|
||||
isDark,
|
||||
blurTint: isDark ? ("dark" as const) : ("light" as const),
|
||||
statusBar: isDark ? ("light" as const) : ("dark" as const),
|
||||
scrim: isDark ? "rgba(0, 0, 0, 0.28)" : "rgba(255, 255, 255, 0.5)",
|
||||
androidScrim: isDark ? "rgba(0, 0, 0, 0.72)" : "rgba(255, 255, 255, 0.9)",
|
||||
backgroundImageOpacity: isDark ? 0.55 : 0.4,
|
||||
trackInactive: isDark ? "rgba(255, 255, 255, 0.25)" : "rgba(0, 0, 0, 0.12)",
|
||||
buttonSurface: isDark ? "rgba(255, 255, 255, 0.14)" : "rgba(0, 0, 0, 0.08)",
|
||||
handle: isDark ? "rgba(255, 255, 255, 0.35)" : "rgba(0, 0, 0, 0.2)",
|
||||
}
|
||||
}
|
||||
|
||||
export const spacing = {
|
||||
xs: 4,
|
||||
sm: 8,
|
||||
@@ -47,7 +93,25 @@ export const radius = {
|
||||
sm: 6,
|
||||
md: 10,
|
||||
lg: 14,
|
||||
xl: 20,
|
||||
full: 9999,
|
||||
} as const
|
||||
|
||||
export const playerBarHeight = 88
|
||||
export const miniPlayerHeight = 56
|
||||
export const tabBarHeight = Platform.OS === "ios" ? 49 : 56
|
||||
export const playerBarHeight = miniPlayerHeight
|
||||
export const carouselCardWidth = 160
|
||||
|
||||
export function useTwoColumnCardWidth(
|
||||
horizontalPadding = spacing.lg,
|
||||
gap = spacing.md,
|
||||
) {
|
||||
const { width } = useWindowDimensions()
|
||||
return Math.floor((width - horizontalPadding * 2 - gap) / 2)
|
||||
}
|
||||
|
||||
export function useBottomContentInset(hasMiniPlayer: boolean) {
|
||||
const base = spacing.lg
|
||||
if (!hasMiniPlayer) return base
|
||||
return miniPlayerHeight + tabBarHeight + spacing.lg
|
||||
}
|
||||
@@ -16,9 +16,11 @@
|
||||
"@expo/vector-icons": "^15.0.2",
|
||||
"@otunes/convex": "workspace:*",
|
||||
"@react-native-async-storage/async-storage": "2.2.0",
|
||||
"@react-native-community/slider": "5.2.0",
|
||||
"convex": "^1.40.0",
|
||||
"expo": "~56.0.11",
|
||||
"expo-av": "^16.0.8",
|
||||
"expo-audio": "^56.0.12",
|
||||
"expo-blur": "~56.0.3",
|
||||
"expo-constants": "~56.0.18",
|
||||
"expo-dev-client": "~56.0.20",
|
||||
"expo-haptics": "~56.0.3",
|
||||
@@ -28,7 +30,8 @@
|
||||
"expo-router": "~56.2.10",
|
||||
"expo-secure-store": "~56.0.4",
|
||||
"expo-status-bar": "~56.0.4",
|
||||
"react": "19.2.4",
|
||||
"expo-symbols": "~56.0.6",
|
||||
"react": "19.2.3",
|
||||
"react-native": "0.85.3",
|
||||
"react-native-gesture-handler": "~2.31.1",
|
||||
"react-native-reanimated": "4.3.1",
|
||||
|
||||
Generated
+525
-219
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user