Add Expo mobile app and extract shared Convex package
- Replace mobile placeholder with Expo Router app (tabs, playback, auth, library) - Move Convex backend to @otunes/convex for web and mobile reuse - Update web app imports and API routes to use shared package
This commit is contained in:
1 parent
ee845971ec
commit
73c7283d4d
114 files changed
+5659
-294
No files matched your search
@@ -10,6 +10,7 @@ This project uses [pnpm workspaces](https://pnpm.io/workspaces):
|
||||
| --- | --- | --- |
|
||||
| `@otunes/web` | `apps/web` | Next.js web app |
|
||||
| `@otunes/mobile` | `apps/mobile` | Expo React Native mobile app |
|
||||
| `@otunes/convex` | `packages/convex` | Shared Convex backend and client types |
|
||||
|
||||
### Development
|
||||
|
||||
@@ -33,6 +34,12 @@ Run the mobile app:
|
||||
pnpm dev:mobile
|
||||
```
|
||||
|
||||
Run the Convex backend (from the shared package):
|
||||
|
||||
```bash
|
||||
pnpm dev:convex
|
||||
```
|
||||
|
||||
Other commands:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import { StatusBar } from "expo-status-bar"
|
||||
import { StyleSheet, Text, View } from "react-native"
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.title}>oTunes</Text>
|
||||
<Text style={styles.subtitle}>Mobile app coming soon</Text>
|
||||
<StatusBar style="auto" />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: "#fff",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: 8,
|
||||
},
|
||||
title: {
|
||||
fontSize: 28,
|
||||
fontWeight: "700",
|
||||
},
|
||||
subtitle: {
|
||||
fontSize: 16,
|
||||
color: "#666",
|
||||
},
|
||||
})
|
||||
+17
-10
@@ -4,24 +4,31 @@
|
||||
"slug": "otunes",
|
||||
"version": "0.0.1",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/icon.png",
|
||||
"scheme": "otunes",
|
||||
"userInterfaceStyle": "automatic",
|
||||
"ios": {
|
||||
"supportsTablet": true,
|
||||
"bundleIdentifier": "com.abunchofknowitalls.otunes"
|
||||
"bundleIdentifier": "com.abunchofknowitalls.otunes",
|
||||
"infoPlist": {
|
||||
"UIBackgroundModes": ["audio"]
|
||||
}
|
||||
},
|
||||
"android": {
|
||||
"adaptiveIcon": {
|
||||
"backgroundColor": "#E6F4FE",
|
||||
"foregroundImage": "./assets/android-icon-foreground.png",
|
||||
"backgroundImage": "./assets/android-icon-background.png",
|
||||
"monochromeImage": "./assets/android-icon-monochrome.png"
|
||||
},
|
||||
"package": "com.abunchofknowitalls.otunes",
|
||||
"predictiveBackGestureEnabled": false
|
||||
},
|
||||
"web": {
|
||||
"favicon": "./assets/favicon.png"
|
||||
"plugins": [
|
||||
"expo-router",
|
||||
"expo-secure-store",
|
||||
[
|
||||
"expo-av",
|
||||
{
|
||||
"microphonePermission": false
|
||||
}
|
||||
]
|
||||
],
|
||||
"experiments": {
|
||||
"typedRoutes": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Tabs } from "expo-router"
|
||||
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function TabsLayout() {
|
||||
const colors = useThemeColors()
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,67 @@
|
||||
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,137 @@
|
||||
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,48 @@
|
||||
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,127 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { useMemo, useState } from "react"
|
||||
import { ScrollView, StyleSheet, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
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 { usePlayback } from "@/contexts/playback"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
const SEARCH_DEBOUNCE_MS = 300
|
||||
|
||||
export default function SearchScreen() {
|
||||
const colors = useThemeColors()
|
||||
const { playFromSong } = usePlayback()
|
||||
const [query, setQuery] = useState("")
|
||||
const [searchQuery, setSearchQuery] = useState("")
|
||||
const [debounceId, setDebounceId] = useState<ReturnType<typeof setTimeout> | null>(null)
|
||||
|
||||
const hasQuery = searchQuery.length > 0
|
||||
const results = useQuery(
|
||||
api.library.searchLibrary,
|
||||
hasQuery ? { query: searchQuery } : "skip"
|
||||
)
|
||||
const playlistResults = useQuery(
|
||||
api.playlists.searchPlaylists,
|
||||
hasQuery ? { query: searchQuery } : "skip"
|
||||
)
|
||||
|
||||
const isSearching = hasQuery && results === undefined
|
||||
|
||||
function handleQueryChange(value: string) {
|
||||
setQuery(value)
|
||||
if (debounceId) clearTimeout(debounceId)
|
||||
const id = setTimeout(() => setSearchQuery(value.trim()), SEARCH_DEBOUNCE_MS)
|
||||
setDebounceId(id)
|
||||
}
|
||||
|
||||
const hasLibraryResults = useMemo(
|
||||
() =>
|
||||
Boolean(
|
||||
results &&
|
||||
(results.topResults.length > 0 ||
|
||||
results.artists.length > 0 ||
|
||||
results.albums.length > 0 ||
|
||||
results.songs.length > 0)
|
||||
),
|
||||
[results]
|
||||
)
|
||||
|
||||
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>
|
||||
|
||||
{isSearching ? (
|
||||
<LoadingView />
|
||||
) : !hasQuery ? (
|
||||
<View style={styles.empty}>
|
||||
<Input editable={false} value="Search your library" />
|
||||
</View>
|
||||
) : (
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
{!hasLibraryResults ? (
|
||||
<View style={styles.empty}>
|
||||
<Input editable={false} value={`No results for "${searchQuery}"`} />
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{results?.artists.length ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Artists" content={results.artists} />
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{results?.albums.length ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Albums" content={results.albums} />
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{results?.songs.length ? (
|
||||
<View style={styles.section}>
|
||||
{results.songs.map((song: BrowseSong) => (
|
||||
<SongRow
|
||||
key={song.id}
|
||||
song={song}
|
||||
onPress={() =>
|
||||
void playFromSong(
|
||||
song.id,
|
||||
results.songs.map((s: BrowseSong) => s.id)
|
||||
)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{playlistResults && playlistResults.length > 0 ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Playlists" content={playlistResults} />
|
||||
</View>
|
||||
) : null}
|
||||
</ScrollView>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
searchBox: { paddingHorizontal: spacing.lg, paddingBottom: spacing.md },
|
||||
empty: { padding: spacing.lg },
|
||||
section: { paddingHorizontal: spacing.lg, paddingBottom: spacing.lg, gap: spacing.md },
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useConvexAuth } from "@convex-dev/auth/react"
|
||||
import { Redirect, Stack } from "expo-router"
|
||||
import { View } from "react-native"
|
||||
|
||||
import { PlayerBar } from "@/components/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"
|
||||
|
||||
export default function AppLayout() {
|
||||
const { config } = useServerConfig()
|
||||
const { isLoading, isAuthenticated } = useConvexAuth()
|
||||
|
||||
if (!config) {
|
||||
return <Redirect href="/server" />
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Redirect href="/signin" />
|
||||
}
|
||||
|
||||
return (
|
||||
<PlaybackProvider>
|
||||
<AddToPlaylistProvider>
|
||||
<FavoritesProvider>
|
||||
<View style={{ flex: 1 }}>
|
||||
<Stack screenOptions={{ headerShown: false }} />
|
||||
<PlayerBar />
|
||||
</View>
|
||||
</FavoritesProvider>
|
||||
</AddToPlaylistProvider>
|
||||
</PlaybackProvider>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import { 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"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
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 { BrowseAlbumTrack } from "@otunes/convex/types"
|
||||
import { formatDuration, formatMetadata } from "@/lib/format"
|
||||
import { albumCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function AlbumScreen() {
|
||||
const { id } = useLocalSearchParams<{ id: string }>()
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const album = useQuery(api.library.browseAlbumDetail, { id: id as Id<"albums"> })
|
||||
const { playAlbum, playAlbumShuffled, playFromSong } = usePlayback()
|
||||
const { isAlbumFavorite, toggleAlbumFavorite } = useFavorites()
|
||||
const { openAddAlbumToPlaylist } = useAddToPlaylist()
|
||||
const [actionsOpen, setActionsOpen] = useState(false)
|
||||
|
||||
if (album === undefined || !config) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Album" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
const songIds = album.tracks.map((track: BrowseAlbumTrack) => track.id)
|
||||
const metadata = formatMetadata(album.genre, album.year)
|
||||
|
||||
function handleAlbumAction(action: MediaAction) {
|
||||
if (!album) return
|
||||
switch (action) {
|
||||
case "playlist":
|
||||
void openAddAlbumToPlaylist(album.id)
|
||||
break
|
||||
case "favorite":
|
||||
void toggleAlbumFavorite(album.id)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
}
|
||||
/>
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<View style={styles.hero}>
|
||||
<Image
|
||||
source={{ uri: albumCoverUrl(config.serverUrl, album.id) }}
|
||||
style={styles.cover}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>{album.title}</Text>
|
||||
<Pressable onPress={() => router.push(`/artist/${album.artist.id}`)}>
|
||||
<Text style={[styles.artist, { color: colors.mutedForeground }]}>{album.artist.name}</Text>
|
||||
</Pressable>
|
||||
{metadata ? (
|
||||
<Text style={{ color: colors.mutedForeground }}>{metadata}</Text>
|
||||
) : null}
|
||||
<View style={styles.actions}>
|
||||
<Button title="Play" onPress={() => void playAlbum(album.id)} />
|
||||
<Button title="Shuffle" variant="secondary" onPress={() => void playAlbumShuffled(album.id)} />
|
||||
<Pressable onPress={() => void toggleAlbumFavorite(album.id)} hitSlop={8}>
|
||||
<Ionicons
|
||||
name={isAlbumFavorite(album.id) ? "star" : "star-outline"}
|
||||
size={24}
|
||||
color={isAlbumFavorite(album.id) ? colors.primary : colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{album.tracks.map((track: BrowseAlbumTrack, index: number) => (
|
||||
<Pressable
|
||||
key={track.id}
|
||||
style={[styles.trackRow, { borderBottomColor: colors.border }]}
|
||||
onPress={() => void playFromSong(track.id, songIds)}
|
||||
>
|
||||
<Text style={[styles.trackNumber, { color: colors.mutedForeground }]}>
|
||||
{track.track || index + 1}
|
||||
</Text>
|
||||
<View style={styles.trackMeta}>
|
||||
<Text style={[styles.trackTitle, { color: colors.foreground }]} numberOfLines={1}>
|
||||
{track.title}
|
||||
</Text>
|
||||
{track.artists ? (
|
||||
<Text style={{ color: colors.mutedForeground }} numberOfLines={1}>
|
||||
{track.artists.join(", ")}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
<Text style={{ color: colors.mutedForeground }}>
|
||||
{formatDuration(track.durationSeconds)}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
|
||||
<MediaActionsSheet
|
||||
visible={actionsOpen}
|
||||
title={album.title}
|
||||
favorited={isAlbumFavorite(album.id)}
|
||||
showNavigation={false}
|
||||
onClose={() => setActionsOpen(false)}
|
||||
onAction={handleAlbumAction}
|
||||
/>
|
||||
</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: {
|
||||
width: 220,
|
||||
height: 220,
|
||||
borderRadius: radius.lg,
|
||||
backgroundColor: "#ddd",
|
||||
},
|
||||
title: { fontSize: 24, fontWeight: "800", textAlign: "center" },
|
||||
artist: { fontSize: 16, fontWeight: "600" },
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.sm,
|
||||
marginTop: spacing.sm,
|
||||
},
|
||||
trackRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.sm,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
trackNumber: { width: 24, textAlign: "center" },
|
||||
trackMeta: { flex: 1, minWidth: 0 },
|
||||
trackTitle: { fontSize: 15, fontWeight: "500" },
|
||||
})
|
||||
@@ -0,0 +1,147 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import { 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 { 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"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
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"
|
||||
|
||||
export default function ArtistScreen() {
|
||||
const { id } = useLocalSearchParams<{ id: string }>()
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const data = useQuery(api.library.browseArtistDetail, { id: id as Id<"artists"> })
|
||||
const { playArtist, playArtistShuffled } = usePlayback()
|
||||
const { isArtistFavorite, toggleArtistFavorite } = useFavorites()
|
||||
const { openAddArtistToPlaylist } = useAddToPlaylist()
|
||||
const [actionsOpen, setActionsOpen] = useState(false)
|
||||
|
||||
if (data === undefined || !config) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Artist" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
function handleAction(action: MediaAction) {
|
||||
if (!data) return
|
||||
switch (action) {
|
||||
case "playlist":
|
||||
void openAddArtistToPlaylist(data.artist.id)
|
||||
break
|
||||
case "favorite":
|
||||
void toggleArtistFavorite(data.artist.id)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
}
|
||||
/>
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<View style={styles.hero}>
|
||||
<Image
|
||||
source={{ uri: artistCoverUrl(config.serverUrl, data.artist.id) }}
|
||||
style={styles.avatar}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>{data.artist.name}</Text>
|
||||
<View style={styles.actions}>
|
||||
<Button title="Play" onPress={() => void playArtist(data.artist.id)} />
|
||||
<Button title="Shuffle" variant="secondary" onPress={() => void playArtistShuffled(data.artist.id)} />
|
||||
<Pressable onPress={() => void toggleArtistFavorite(data.artist.id)} hitSlop={8}>
|
||||
<Ionicons
|
||||
name={isArtistFavorite(data.artist.id) ? "star" : "star-outline"}
|
||||
size={24}
|
||||
color={isArtistFavorite(data.artist.id) ? colors.primary : colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{data.recentlyPlayed.length > 0 ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Recently Played" content={data.recentlyPlayed} />
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{data.recentlyAdded.length > 0 ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Recently Added" content={data.recentlyAdded} />
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
<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>
|
||||
</View>
|
||||
</ScrollView>
|
||||
|
||||
<MediaActionsSheet
|
||||
visible={actionsOpen}
|
||||
title={data.artist.name}
|
||||
favorited={isArtistFavorite(data.artist.id)}
|
||||
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: {
|
||||
width: 180,
|
||||
height: 180,
|
||||
borderRadius: 90,
|
||||
backgroundColor: "#ddd",
|
||||
},
|
||||
title: { fontSize: 28, fontWeight: "800", textAlign: "center" },
|
||||
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,39 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { AlbumCard } 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 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)
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
content: { padding: spacing.lg },
|
||||
grid: { flexDirection: "row", flexWrap: "wrap", gap: spacing.lg },
|
||||
})
|
||||
@@ -0,0 +1,66 @@
|
||||
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"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { BrowseArtist } from "@otunes/convex/types"
|
||||
import { artistCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function ArtistsScreen() {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const artists = useQuery(api.library.browseArtists)
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
avatar: {
|
||||
width: 44,
|
||||
height: 44,
|
||||
borderRadius: 22,
|
||||
backgroundColor: "#eee",
|
||||
},
|
||||
name: { fontSize: 16, fontWeight: "600" },
|
||||
})
|
||||
@@ -0,0 +1,136 @@
|
||||
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"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
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 { showSuccess } from "@/lib/toast"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
export default function SongsScreen() {
|
||||
const colors = useThemeColors()
|
||||
const { playFromLibrarySong, addToQueueNext, addToQueueLast, playShuffled } = usePlayback()
|
||||
const { openAddToPlaylist } = useAddToPlaylist()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const [sortKey, setSortKey] = useState<"title" | "artist" | "album">("title")
|
||||
const [sortDirection, setSortDirection] = useState<"asc" | "desc">("asc")
|
||||
const [actionSong, setActionSong] = useState<BrowseSong | null>(null)
|
||||
|
||||
const { results, status, loadMore } = usePaginatedQuery(
|
||||
api.library.browseSongsPaginated,
|
||||
{ sortKey, sortDirection },
|
||||
{ initialNumItems: PAGE_SIZE }
|
||||
)
|
||||
|
||||
function cycleSort(key: "title" | "artist" | "album") {
|
||||
if (sortKey === key) {
|
||||
setSortDirection((d) => (d === "asc" ? "desc" : "asc"))
|
||||
} else {
|
||||
setSortKey(key)
|
||||
setSortDirection("asc")
|
||||
}
|
||||
}
|
||||
|
||||
function handleAction(action: MediaAction) {
|
||||
if (!actionSong) return
|
||||
const songIds = [actionSong.id]
|
||||
switch (action) {
|
||||
case "playlist":
|
||||
openAddToPlaylist(songIds)
|
||||
break
|
||||
case "play-next":
|
||||
void addToQueueNext(songIds).then(() => showSuccess("Queued to play next"))
|
||||
break
|
||||
case "play-last":
|
||||
void addToQueueLast(songIds).then(() => showSuccess("Queued to play last"))
|
||||
break
|
||||
case "shuffle":
|
||||
void playShuffled(songIds)
|
||||
break
|
||||
case "favorite":
|
||||
void toggleSongFavorite(actionSong.id)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (results === undefined) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Songs" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Songs" />
|
||||
<View style={[styles.sortRow, { borderBottomColor: colors.border }]}>
|
||||
{(["title", "artist", "album"] as const).map((key) => (
|
||||
<Pressable key={key} onPress={() => cycleSort(key)} style={styles.sortButton}>
|
||||
<Text
|
||||
style={{
|
||||
color: sortKey === key ? colors.foreground : colors.mutedForeground,
|
||||
fontWeight: sortKey === key ? "700" : "500",
|
||||
}}
|
||||
>
|
||||
{key[0].toUpperCase() + key.slice(1)}
|
||||
{sortKey === key ? (sortDirection === "asc" ? " ↑" : " ↓") : ""}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
|
||||
<FlatList
|
||||
data={results}
|
||||
keyExtractor={(item) => item.id}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
onEndReached={() => {
|
||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
||||
}}
|
||||
onEndReachedThreshold={0.5}
|
||||
renderItem={({ item }) => (
|
||||
<SongRow
|
||||
song={item}
|
||||
onPress={() =>
|
||||
void playFromLibrarySong(item.id as Id<"songs">, { sortKey, sortDirection })
|
||||
}
|
||||
onLongPress={() => setActionSong(item)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<MediaActionsSheet
|
||||
visible={Boolean(actionSong)}
|
||||
title={actionSong?.title ?? ""}
|
||||
favorited={actionSong ? isSongFavorite(actionSong.id) : false}
|
||||
onClose={() => setActionSong(null)}
|
||||
onAction={handleAction}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
sortRow: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-around",
|
||||
paddingVertical: spacing.sm,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
sortButton: { padding: spacing.sm },
|
||||
})
|
||||
@@ -0,0 +1,202 @@
|
||||
import { useMutation, useQuery } from "convex/react"
|
||||
import { Image } from "expo-image"
|
||||
import { 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"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
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 { BrowseSong } from "@otunes/convex/types"
|
||||
import { showError, showSuccess } from "@/lib/toast"
|
||||
import { playlistCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function PlaylistScreen() {
|
||||
const { id } = useLocalSearchParams<{ id: string }>()
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const playlist = useQuery(api.playlists.browsePlaylistDetail, {
|
||||
id: id as Id<"playlists">,
|
||||
})
|
||||
const { playPlaylist, playPlaylistShuffled, playFromSong } = usePlayback()
|
||||
const { openAddToPlaylist, openAddPlaylistToPlaylist } = useAddToPlaylist()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const subscribe = useMutation(api.playlists.subscribeToPlaylist)
|
||||
const unsubscribe = useMutation(api.playlists.unsubscribeFromPlaylist)
|
||||
const deletePlaylist = useMutation(api.playlists.deletePlaylist)
|
||||
const removeSongs = useMutation(api.playlists.removeSongsFromPlaylist)
|
||||
const [actionSong, setActionSong] = useState<BrowseSong | null>(null)
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
|
||||
if (playlist === undefined || !config) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Playlist" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
const songIds = playlist.songs.map((song: BrowseSong) => song.id)
|
||||
|
||||
async function handleSubscribeToggle() {
|
||||
if (!playlist?.id) return
|
||||
try {
|
||||
if (playlist.isSubscribed) {
|
||||
await unsubscribe({ playlistId: playlist.id })
|
||||
showSuccess("Unsubscribed")
|
||||
} else {
|
||||
await subscribe({ playlistId: playlist.id })
|
||||
showSuccess("Subscribed")
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to update subscription")
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
if (!playlist?.id) return
|
||||
try {
|
||||
await deletePlaylist({ playlistId: playlist.id })
|
||||
showSuccess("Playlist deleted")
|
||||
router.back()
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to delete playlist")
|
||||
}
|
||||
}
|
||||
|
||||
function handleSongAction(action: MediaAction) {
|
||||
if (!actionSong) return
|
||||
const ids = [actionSong.id]
|
||||
switch (action) {
|
||||
case "playlist":
|
||||
openAddToPlaylist(ids)
|
||||
break
|
||||
case "favorite":
|
||||
void toggleSongFavorite(actionSong.id)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
}
|
||||
/>
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<View style={styles.hero}>
|
||||
<Image
|
||||
source={{ uri: playlistCoverUrl(config.serverUrl, playlist.id ?? "favorites") }}
|
||||
style={styles.cover}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>{playlist.title}</Text>
|
||||
<Text style={{ color: colors.mutedForeground }}>{playlist.owner.name}</Text>
|
||||
<View style={styles.actions}>
|
||||
<Button title="Play" onPress={() => playlist.id && void playPlaylist(playlist.id)} />
|
||||
<Button
|
||||
title="Shuffle"
|
||||
variant="secondary"
|
||||
onPress={() => playlist.id && void playPlaylistShuffled(playlist.id)}
|
||||
/>
|
||||
</View>
|
||||
{!playlist.isOwner && playlist.id ? (
|
||||
<Button
|
||||
title={playlist.isSubscribed ? "Unsubscribe" : "Subscribe"}
|
||||
variant="ghost"
|
||||
onPress={() => void handleSubscribeToggle()}
|
||||
/>
|
||||
) : null}
|
||||
{playlist.isOwner && playlist.id ? (
|
||||
<Button title="Delete Playlist" variant="destructive" onPress={() => void handleDelete()} />
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
{playlist.songs.map((song: BrowseSong) => (
|
||||
<SongRow
|
||||
key={song.id}
|
||||
song={song}
|
||||
onPress={() => void playFromSong(song.id, songIds)}
|
||||
onLongPress={() => setActionSong(song)}
|
||||
trailing={
|
||||
playlist.isOwner && playlist.id ? (
|
||||
<Pressable
|
||||
onPress={() =>
|
||||
void removeSongs({ playlistId: playlist.id!, songIds: [song.id] }).then(() =>
|
||||
showSuccess("Removed from playlist")
|
||||
)
|
||||
}
|
||||
>
|
||||
<Ionicons name="trash-outline" size={18} color={colors.destructive} />
|
||||
</Pressable>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</ScrollView>
|
||||
|
||||
<MediaActionsSheet
|
||||
visible={Boolean(actionSong)}
|
||||
title={actionSong?.title ?? ""}
|
||||
favorited={actionSong ? isSongFavorite(actionSong.id) : false}
|
||||
onClose={() => setActionSong(null)}
|
||||
onAction={handleSongAction}
|
||||
/>
|
||||
|
||||
<MediaActionsSheet
|
||||
visible={menuOpen}
|
||||
title={playlist.title}
|
||||
showFavorite={false}
|
||||
onClose={() => setMenuOpen(false)}
|
||||
onAction={(action) => {
|
||||
if (action === "playlist" && playlist.id) {
|
||||
void openAddPlaylistToPlaylist(playlist.id)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</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: {
|
||||
width: 200,
|
||||
height: 200,
|
||||
borderRadius: radius.lg,
|
||||
backgroundColor: "#ddd",
|
||||
},
|
||||
title: { fontSize: 24, fontWeight: "800", textAlign: "center" },
|
||||
actions: { flexDirection: "row", gap: spacing.sm, marginTop: spacing.sm },
|
||||
})
|
||||
@@ -0,0 +1,115 @@
|
||||
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"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
import { usePlayback } from "@/contexts/playback"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { playlistCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function FavoritesScreen() {
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
const favorites = useQuery(api.favorites.browseFavoritesPlaylistDetail)
|
||||
const { playInOrder, playShuffled, playFromSong } = usePlayback()
|
||||
const { openAddToPlaylist } = useAddToPlaylist()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
const songIds = favorites.songs.map((song: BrowseSong) => song.id)
|
||||
|
||||
function handleSongAction(action: MediaAction) {
|
||||
if (!actionSong) return
|
||||
switch (action) {
|
||||
case "playlist":
|
||||
openAddToPlaylist([actionSong.id])
|
||||
break
|
||||
case "favorite":
|
||||
void toggleSongFavorite(actionSong.id)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Favorites" />
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<View style={styles.hero}>
|
||||
<Image
|
||||
source={{ uri: playlistCoverUrl(config.serverUrl, "favorites") }}
|
||||
style={styles.cover}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>{favorites.title}</Text>
|
||||
<View style={styles.actions}>
|
||||
<Button title="Play" onPress={() => void playInOrder(songIds)} />
|
||||
<Button title="Shuffle" variant="secondary" onPress={() => void playShuffled(songIds)} />
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{favorites.songs.map((song: BrowseSong) => (
|
||||
<SongRow
|
||||
key={song.id}
|
||||
song={song}
|
||||
onPress={() => void playFromSong(song.id, songIds)}
|
||||
onLongPress={() => setActionSong(song)}
|
||||
/>
|
||||
))}
|
||||
</ScrollView>
|
||||
|
||||
<MediaActionsSheet
|
||||
visible={Boolean(actionSong)}
|
||||
title={actionSong?.title ?? ""}
|
||||
favorited={actionSong ? isSongFavorite(actionSong.id) : true}
|
||||
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: {
|
||||
width: 200,
|
||||
height: 200,
|
||||
borderRadius: radius.lg,
|
||||
backgroundColor: "#ddd",
|
||||
},
|
||||
title: { fontSize: 24, fontWeight: "800" },
|
||||
actions: { flexDirection: "row", gap: spacing.sm, marginTop: spacing.sm },
|
||||
})
|
||||
@@ -0,0 +1,133 @@
|
||||
import { usePaginatedQuery, useQuery } from "convex/react"
|
||||
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"
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
export default function QueueScreen() {
|
||||
const colors = useThemeColors()
|
||||
const {
|
||||
queueSongIds,
|
||||
currentSong,
|
||||
skipToQueueIndex,
|
||||
clearQueue,
|
||||
reorderQueue,
|
||||
} = usePlayback()
|
||||
|
||||
const queueVersion = queueSongIds.length
|
||||
? `${queueSongIds.length}:${queueSongIds[0]}:${queueSongIds[queueSongIds.length - 1]}`
|
||||
: "empty"
|
||||
|
||||
const { results: queueSongs, status, loadMore } = usePaginatedQuery(
|
||||
api.playback.getQueuePaginated,
|
||||
{ queueVersion },
|
||||
{ initialNumItems: PAGE_SIZE }
|
||||
)
|
||||
|
||||
const historySongs = useQuery(api.playback.getQueueHistory)
|
||||
|
||||
function moveSong(fromIndex: number, direction: -1 | 1) {
|
||||
const toIndex = fromIndex + direction
|
||||
if (toIndex < 0 || toIndex >= queueSongIds.length) return
|
||||
const next = [...queueSongIds]
|
||||
const [item] = next.splice(fromIndex, 1)
|
||||
next.splice(toIndex, 0, item)
|
||||
void reorderQueue(next)
|
||||
}
|
||||
|
||||
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()} />
|
||||
) : 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,
|
||||
fontSize: 12,
|
||||
fontWeight: "700",
|
||||
textTransform: "uppercase",
|
||||
},
|
||||
empty: { padding: spacing.lg },
|
||||
queueActions: {
|
||||
flexDirection: "row",
|
||||
gap: spacing.lg,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingBottom: spacing.sm,
|
||||
},
|
||||
history: { marginTop: spacing.lg },
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
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 RecentlyAddedScreen() {
|
||||
const colors = useThemeColors()
|
||||
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
content: { padding: spacing.lg },
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useQuery } from "convex/react"
|
||||
import { ScrollView, StyleSheet, View } 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 RecentlyPlayedScreen() {
|
||||
const colors = useThemeColors()
|
||||
const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed)
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
content: { padding: spacing.lg },
|
||||
})
|
||||
@@ -0,0 +1,395 @@
|
||||
import { useAction, useMutation, useQuery } from "convex/react"
|
||||
import * as ImagePicker from "expo-image-picker"
|
||||
import { useState } from "react"
|
||||
import {
|
||||
Pressable,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Switch,
|
||||
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"
|
||||
import type { Doc, Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { initialsFromName } from "@/lib/format"
|
||||
import { showError, showSuccess } from "@/lib/toast"
|
||||
import type { PlaybackQuality } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
type Section = "profile" | "quality" | "users" | "library"
|
||||
|
||||
const QUALITY_OPTIONS: {
|
||||
value: PlaybackQuality
|
||||
label: string
|
||||
description: string
|
||||
}[] = [
|
||||
{ value: "low", label: "Low", description: "AAC 64kb/s" },
|
||||
{ value: "medium", label: "Medium", description: "AAC 128kb/s" },
|
||||
{ value: "high", label: "High", description: "AAC 256kb/s" },
|
||||
{ value: "lossless", label: "Lossless", description: "ALAC or FLAC" },
|
||||
]
|
||||
|
||||
export default function SettingsScreen() {
|
||||
const colors = useThemeColors()
|
||||
const user = useQuery(api.auth.currentUser)
|
||||
const allUsers = useQuery(api.users.listUsers)
|
||||
const [section, setSection] = useState<Section>("profile")
|
||||
|
||||
if (!user) {
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Settings" />
|
||||
<LoadingView />
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const isAdmin = user.isAdmin === true
|
||||
const sections: { id: Section; label: string; admin?: boolean }[] = [
|
||||
{ id: "profile", label: "Profile" },
|
||||
{ id: "quality", label: "Quality" },
|
||||
{ id: "library", label: "Library", admin: true },
|
||||
{ id: "users", label: "Users", admin: true },
|
||||
]
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
||||
<ScreenHeader title="Settings" />
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} style={styles.tabs}>
|
||||
{sections
|
||||
.filter((item) => !item.admin || isAdmin)
|
||||
.map((item) => (
|
||||
<Pressable
|
||||
key={item.id}
|
||||
onPress={() => setSection(item.id)}
|
||||
style={[
|
||||
styles.tab,
|
||||
{
|
||||
backgroundColor:
|
||||
section === item.id ? colors.foreground : colors.muted,
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
color: section === item.id ? colors.background : colors.foreground,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
>
|
||||
{item.label}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
|
||||
<View style={styles.content}>
|
||||
{section === "profile" ? <ProfileSection user={user} /> : null}
|
||||
{section === "quality" ? <QualitySection user={user} /> : null}
|
||||
{section === "library" && isAdmin ? <LibrarySection /> : null}
|
||||
{section === "users" && isAdmin && allUsers ? (
|
||||
<UsersSection users={allUsers} currentUserId={user._id} />
|
||||
) : null}
|
||||
</View>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
function ProfileSection({ user }: { user: Doc<"users"> }) {
|
||||
const colors = useThemeColors()
|
||||
const updateName = useMutation(api.users.updateProfileName)
|
||||
const updateEmail = useMutation(api.users.updateProfileEmail)
|
||||
const updateImage = useMutation(api.users.updateProfileImage)
|
||||
const updatePassword = useAction(api.users.updateOwnPassword)
|
||||
const [name, setName] = useState(user.name)
|
||||
const [email, setEmail] = useState(user.email)
|
||||
const [newPassword, setNewPassword] = useState("")
|
||||
const [confirmPassword, setConfirmPassword] = useState("")
|
||||
const [changingPassword, setChangingPassword] = useState(false)
|
||||
|
||||
async function pickImage() {
|
||||
const result = await ImagePicker.launchImageLibraryAsync({
|
||||
mediaTypes: ["images"],
|
||||
quality: 0.8,
|
||||
base64: true,
|
||||
})
|
||||
if (result.canceled || !result.assets[0]?.base64) return
|
||||
const mime = result.assets[0].mimeType ?? "image/jpeg"
|
||||
try {
|
||||
await updateImage({ image: `data:${mime};base64,${result.assets[0].base64}` })
|
||||
showSuccess("Profile photo updated")
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to update photo")
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePasswordChange() {
|
||||
if (newPassword !== confirmPassword) {
|
||||
showError("Passwords do not match")
|
||||
return
|
||||
}
|
||||
setChangingPassword(true)
|
||||
try {
|
||||
await updatePassword({ newPassword })
|
||||
setNewPassword("")
|
||||
setConfirmPassword("")
|
||||
showSuccess("Password updated")
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to update password")
|
||||
} finally {
|
||||
setChangingPassword(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.sectionBlock}>
|
||||
<View style={[styles.avatar, { backgroundColor: colors.muted }]}>
|
||||
<Text style={{ color: colors.foreground, fontWeight: "700", fontSize: 20 }}>
|
||||
{initialsFromName(user.name)}
|
||||
</Text>
|
||||
</View>
|
||||
<Button title="Upload profile photo" variant="secondary" onPress={() => void pickImage()} />
|
||||
{user.image ? (
|
||||
<Button title="Remove photo" variant="ghost" onPress={() => void updateImage({ image: null })} />
|
||||
) : null}
|
||||
<Input value={name} onChangeText={setName} placeholder="Name" />
|
||||
<Button
|
||||
title="Save name"
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void updateName({ name }).catch((error: Error) => showError(error.message))
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
value={email}
|
||||
onChangeText={setEmail}
|
||||
placeholder="Email"
|
||||
autoCapitalize="none"
|
||||
keyboardType="email-address"
|
||||
/>
|
||||
<Button
|
||||
title="Save email"
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void updateEmail({ email }).catch((error: Error) => showError(error.message))
|
||||
}
|
||||
/>
|
||||
<Text style={[styles.sectionTitle, { color: colors.foreground }]}>Password</Text>
|
||||
<Input value={newPassword} onChangeText={setNewPassword} placeholder="New password" secureTextEntry />
|
||||
<Input
|
||||
value={confirmPassword}
|
||||
onChangeText={setConfirmPassword}
|
||||
placeholder="Confirm password"
|
||||
secureTextEntry
|
||||
/>
|
||||
<Button
|
||||
title="Update password"
|
||||
loading={changingPassword}
|
||||
disabled={!newPassword || newPassword !== confirmPassword}
|
||||
onPress={() => void handlePasswordChange()}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function QualitySection({ user }: { user: Doc<"users"> }) {
|
||||
const colors = useThemeColors()
|
||||
const updateQuality = useMutation(api.users.updatePlaybackQuality)
|
||||
const updateAtmos = useMutation(api.users.updatePreferAtmos)
|
||||
const quality = user.playbackQuality ?? "medium"
|
||||
|
||||
return (
|
||||
<View style={styles.sectionBlock}>
|
||||
{QUALITY_OPTIONS.map((option) => (
|
||||
<Pressable
|
||||
key={option.value}
|
||||
style={[
|
||||
styles.qualityRow,
|
||||
{
|
||||
borderColor: colors.border,
|
||||
backgroundColor: quality === option.value ? colors.muted : colors.card,
|
||||
},
|
||||
]}
|
||||
onPress={() =>
|
||||
void updateQuality({ playbackQuality: option.value }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
>
|
||||
<Text style={{ color: colors.foreground, fontWeight: "600" }}>{option.label}</Text>
|
||||
<Text style={{ color: colors.mutedForeground }}>{option.description}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
<View style={[styles.switchRow, { borderColor: colors.border }]}>
|
||||
<Text style={{ color: colors.foreground, flex: 1 }}>
|
||||
Prefer Dolby Atmos when available
|
||||
</Text>
|
||||
<Switch
|
||||
value={user.preferAtmos ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void updateAtmos({ preferAtmos: checked }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function LibrarySection() {
|
||||
const updateLibrary = useAction(api.actions.updateLibrary)
|
||||
const cleanupHlsStreams = useAction(api.actions.adminCleanupHlsStreams)
|
||||
const [updating, setUpdating] = useState(false)
|
||||
const [cleaningHls, setCleaningHls] = useState(false)
|
||||
|
||||
return (
|
||||
<View style={styles.sectionBlock}>
|
||||
<Button
|
||||
title="Update library"
|
||||
loading={updating}
|
||||
onPress={async () => {
|
||||
setUpdating(true)
|
||||
try {
|
||||
await updateLibrary({})
|
||||
showSuccess("Library updated")
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to update library")
|
||||
} finally {
|
||||
setUpdating(false)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
title="Clean HLS streams"
|
||||
variant="secondary"
|
||||
loading={cleaningHls}
|
||||
onPress={async () => {
|
||||
setCleaningHls(true)
|
||||
try {
|
||||
const result = await cleanupHlsStreams({})
|
||||
showSuccess(`Removed ${result.removed} idle HLS streams`)
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to clean HLS streams")
|
||||
} finally {
|
||||
setCleaningHls(false)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function UsersSection({
|
||||
users,
|
||||
currentUserId,
|
||||
}: {
|
||||
users: Doc<"users">[]
|
||||
currentUserId: Id<"users">
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
const appSettings = useQuery(api.users.getAppSettings)
|
||||
const setDisableCreation = useMutation(api.users.setDisableAccountCreation)
|
||||
const setAdmin = useMutation(api.users.setUserAdmin)
|
||||
const deleteUserMutation = useMutation(api.users.deleteUser)
|
||||
|
||||
return (
|
||||
<View style={styles.sectionBlock}>
|
||||
<View style={[styles.switchRow, { borderColor: colors.border }]}>
|
||||
<Text style={{ color: colors.foreground, flex: 1 }}>Disable account creation</Text>
|
||||
<Switch
|
||||
value={appSettings?.disableAccountCreation ?? false}
|
||||
onValueChange={(checked) =>
|
||||
void setDisableCreation({ disabled: checked }).catch((error: Error) =>
|
||||
showError(error.message)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
{users.map((user) => (
|
||||
<View key={user._id} style={[styles.userRow, { borderColor: colors.border }]}>
|
||||
<View style={{ flex: 1 }}>
|
||||
<Text style={{ color: colors.foreground, fontWeight: "600" }}>{user.name}</Text>
|
||||
<Text style={{ color: colors.mutedForeground }}>{user.email}</Text>
|
||||
{user.isAdmin ? (
|
||||
<Text style={{ color: colors.mutedForeground }}>Admin</Text>
|
||||
) : null}
|
||||
</View>
|
||||
{user._id !== currentUserId ? (
|
||||
<View style={styles.userActions}>
|
||||
<Button
|
||||
title={user.isAdmin ? "Remove admin" : "Make admin"}
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void setAdmin({ userId: user._id, isAdmin: !user.isAdmin }).then(() =>
|
||||
showSuccess("Updated permissions")
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
title="Delete"
|
||||
variant="destructive"
|
||||
onPress={() =>
|
||||
void deleteUserMutation({ userId: user._id }).then(() =>
|
||||
showSuccess("User deleted")
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
tabs: {
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
},
|
||||
tab: {
|
||||
paddingHorizontal: spacing.md,
|
||||
paddingVertical: spacing.sm,
|
||||
borderRadius: radius.full,
|
||||
marginRight: spacing.sm,
|
||||
},
|
||||
content: { paddingHorizontal: spacing.lg },
|
||||
sectionBlock: { gap: spacing.md, paddingBottom: spacing.xl },
|
||||
sectionTitle: { fontSize: 16, fontWeight: "700", marginTop: spacing.md },
|
||||
avatar: {
|
||||
width: 72,
|
||||
height: 72,
|
||||
borderRadius: 36,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
qualityRow: {
|
||||
borderWidth: 1,
|
||||
borderRadius: radius.md,
|
||||
padding: spacing.md,
|
||||
gap: 4,
|
||||
},
|
||||
switchRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
borderWidth: 1,
|
||||
borderRadius: radius.md,
|
||||
padding: spacing.md,
|
||||
},
|
||||
userRow: {
|
||||
borderWidth: 1,
|
||||
borderRadius: radius.md,
|
||||
padding: spacing.md,
|
||||
gap: spacing.sm,
|
||||
},
|
||||
userActions: { gap: spacing.sm },
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
export default function AuthLayout() {
|
||||
return <Stack screenOptions={{ headerShown: false }} />
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { AuthForm } from "@/components/auth-form"
|
||||
|
||||
export default function SignInScreen() {
|
||||
return <AuthForm flow="signIn" />
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { AuthForm } from "@/components/auth-form"
|
||||
|
||||
export default function SignUpScreen() {
|
||||
return <AuthForm flow="signUp" />
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Stack } from "expo-router"
|
||||
import { StatusBar } from "expo-status-bar"
|
||||
import { GestureHandlerRootView } from "react-native-gesture-handler"
|
||||
import { SafeAreaProvider } from "react-native-safe-area-context"
|
||||
|
||||
import { ConvexAppProvider } from "@/contexts/convex-app"
|
||||
import { ServerConfigProvider } from "@/contexts/server-config"
|
||||
|
||||
export default function RootLayout() {
|
||||
return (
|
||||
<GestureHandlerRootView style={{ flex: 1 }}>
|
||||
<SafeAreaProvider>
|
||||
<ServerConfigProvider>
|
||||
<ConvexAppProvider>
|
||||
<StatusBar style="auto" />
|
||||
<Stack screenOptions={{ headerShown: false }} />
|
||||
</ConvexAppProvider>
|
||||
</ServerConfigProvider>
|
||||
</SafeAreaProvider>
|
||||
</GestureHandlerRootView>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Redirect } from "expo-router"
|
||||
import { useConvexAuth } from "@convex-dev/auth/react"
|
||||
|
||||
import { LoadingView } from "@/components/ui/primitives"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
|
||||
export default function Index() {
|
||||
const { config, isLoading } = useServerConfig()
|
||||
const { isLoading: authLoading, isAuthenticated } = useConvexAuth()
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
return <Redirect href="/server" />
|
||||
}
|
||||
|
||||
if (authLoading) {
|
||||
return <LoadingView />
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Redirect href="/signin" />
|
||||
}
|
||||
|
||||
return <Redirect href="/(app)/(tabs)" />
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { useRouter } from "expo-router"
|
||||
import { useState } from "react"
|
||||
import { KeyboardAvoidingView, Platform, StyleSheet, Text, View } from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { Button, Card, Input } from "@/components/ui/primitives"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
export default function ServerScreen() {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const { setServerHostname } = useServerConfig()
|
||||
const [hostname, setHostname] = useState("")
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
async function handleContinue() {
|
||||
setError(null)
|
||||
setSubmitting(true)
|
||||
const ok = await setServerHostname(hostname)
|
||||
setSubmitting(false)
|
||||
if (!ok) {
|
||||
setError("Enter a valid server address, e.g. music.example.com or localhost:3000")
|
||||
return
|
||||
}
|
||||
router.replace("/signin")
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]}>
|
||||
<KeyboardAvoidingView
|
||||
behavior={Platform.OS === "ios" ? "padding" : undefined}
|
||||
style={styles.container}
|
||||
>
|
||||
<View style={styles.hero}>
|
||||
<Text style={[styles.brand, { color: colors.foreground }]}>oTunes</Text>
|
||||
<Text style={[styles.subtitle, { color: colors.mutedForeground }]}>
|
||||
Connect to your oTunes server to start listening.
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<Card>
|
||||
<Text style={[styles.label, { color: colors.foreground }]}>Server address</Text>
|
||||
<Input
|
||||
value={hostname}
|
||||
onChangeText={setHostname}
|
||||
placeholder="music.example.com"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="url"
|
||||
returnKeyType="go"
|
||||
onSubmitEditing={() => void handleContinue()}
|
||||
/>
|
||||
<Text style={[styles.hint, { color: colors.mutedForeground }]}>
|
||||
Convex will connect to convex.{"{your hostname}"}
|
||||
</Text>
|
||||
{error ? <Text style={[styles.error, { color: colors.destructive }]}>{error}</Text> : null}
|
||||
<Button title="Continue" loading={submitting} onPress={() => void handleContinue()} />
|
||||
</Card>
|
||||
</KeyboardAvoidingView>
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
padding: spacing.xl,
|
||||
gap: spacing.xl,
|
||||
},
|
||||
hero: { gap: spacing.sm },
|
||||
brand: { fontSize: 32, fontWeight: "800" },
|
||||
subtitle: { fontSize: 16, lineHeight: 22 },
|
||||
label: { fontSize: 14, fontWeight: "600" },
|
||||
hint: { fontSize: 13 },
|
||||
error: { fontSize: 14 },
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
module.exports = function (api) {
|
||||
api.cache(true)
|
||||
return {
|
||||
presets: ["babel-preset-expo"],
|
||||
plugins: ["react-native-reanimated/plugin"],
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
import { useAuthActions } from "@convex-dev/auth/react"
|
||||
import { Link, useRouter } from "expo-router"
|
||||
import { useQuery } from "convex/react"
|
||||
import { useState } from "react"
|
||||
import {
|
||||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
} from "react-native"
|
||||
import { SafeAreaView } from "react-native-safe-area-context"
|
||||
|
||||
import { Button, Card, Input } from "@/components/ui/primitives"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
type AuthFlow = "signIn" | "signUp"
|
||||
|
||||
const copy: Record<
|
||||
AuthFlow,
|
||||
{
|
||||
title: string
|
||||
description: string
|
||||
submit: string
|
||||
switchPrompt: string
|
||||
switchLabel: string
|
||||
switchHref: "/signin" | "/signup"
|
||||
}
|
||||
> = {
|
||||
signIn: {
|
||||
title: "Welcome back",
|
||||
description: "Sign in to your oTunes account to keep listening.",
|
||||
submit: "Sign in",
|
||||
switchPrompt: "Don't have an account?",
|
||||
switchLabel: "Sign up",
|
||||
switchHref: "/signup",
|
||||
},
|
||||
signUp: {
|
||||
title: "Create your account",
|
||||
description: "Sign up to start building your oTunes library.",
|
||||
submit: "Sign up",
|
||||
switchPrompt: "Already have an account?",
|
||||
switchLabel: "Sign in",
|
||||
switchHref: "/signin",
|
||||
},
|
||||
}
|
||||
|
||||
export function AuthForm({ flow }: { flow: AuthFlow }) {
|
||||
const { signIn } = useAuthActions()
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const appSettings = useQuery(api.users.getAppSettings)
|
||||
const [name, setName] = useState("")
|
||||
const [email, setEmail] = useState("")
|
||||
const [password, setPassword] = useState("")
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
const text = copy[flow]
|
||||
const accountCreationDisabled = appSettings?.disableAccountCreation ?? false
|
||||
const signupsDisabled = flow === "signUp" && accountCreationDisabled
|
||||
const hideSignUpLink = flow === "signIn" && accountCreationDisabled
|
||||
|
||||
async function handleSubmit() {
|
||||
if (signupsDisabled) return
|
||||
setError(null)
|
||||
setSubmitting(true)
|
||||
|
||||
const formData = new FormData()
|
||||
formData.set("flow", flow)
|
||||
formData.set("email", email.trim())
|
||||
formData.set("password", password)
|
||||
if (flow === "signUp") {
|
||||
formData.set("name", name.trim())
|
||||
}
|
||||
|
||||
try {
|
||||
await signIn("password", formData)
|
||||
router.replace("/(app)/(tabs)")
|
||||
} catch {
|
||||
setError(
|
||||
flow === "signIn"
|
||||
? "Invalid email or password."
|
||||
: "Could not create account. Try a different email."
|
||||
)
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]}>
|
||||
<KeyboardAvoidingView
|
||||
behavior={Platform.OS === "ios" ? "padding" : undefined}
|
||||
style={styles.container}
|
||||
>
|
||||
<Card>
|
||||
<View style={styles.header}>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>{text.title}</Text>
|
||||
<Text style={[styles.description, { color: colors.mutedForeground }]}>
|
||||
{text.description}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{signupsDisabled ? (
|
||||
<Text style={{ color: colors.mutedForeground }}>
|
||||
New account registration is currently disabled. Contact an administrator if you need
|
||||
access.
|
||||
</Text>
|
||||
) : (
|
||||
<View style={styles.form}>
|
||||
{flow === "signUp" ? (
|
||||
<Input
|
||||
value={name}
|
||||
onChangeText={setName}
|
||||
placeholder="Name"
|
||||
autoComplete="name"
|
||||
/>
|
||||
) : null}
|
||||
<Input
|
||||
value={email}
|
||||
onChangeText={setEmail}
|
||||
placeholder="Email"
|
||||
autoCapitalize="none"
|
||||
keyboardType="email-address"
|
||||
autoComplete="email"
|
||||
/>
|
||||
<Input
|
||||
value={password}
|
||||
onChangeText={setPassword}
|
||||
placeholder="Password"
|
||||
secureTextEntry
|
||||
autoComplete={flow === "signIn" ? "current-password" : "new-password"}
|
||||
/>
|
||||
{error ? <Text style={{ color: colors.destructive }}>{error}</Text> : null}
|
||||
<Button title={text.submit} loading={submitting} onPress={() => void handleSubmit()} />
|
||||
{!hideSignUpLink ? (
|
||||
<View style={styles.switchRow}>
|
||||
<Text style={{ color: colors.mutedForeground }}>{text.switchPrompt} </Text>
|
||||
<Link href={text.switchHref} asChild>
|
||||
<Pressable>
|
||||
<Text style={{ color: colors.foreground, fontWeight: "600" }}>
|
||||
{text.switchLabel}
|
||||
</Text>
|
||||
</Pressable>
|
||||
</Link>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Link href="/server" asChild>
|
||||
<Pressable style={styles.changeServer}>
|
||||
<Text style={{ color: colors.mutedForeground }}>Change server</Text>
|
||||
</Pressable>
|
||||
</Link>
|
||||
</KeyboardAvoidingView>
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
safe: { flex: 1 },
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
padding: spacing.xl,
|
||||
gap: spacing.lg,
|
||||
},
|
||||
header: { gap: spacing.xs },
|
||||
title: { fontSize: 22, fontWeight: "700" },
|
||||
description: { fontSize: 14, lineHeight: 20 },
|
||||
form: { gap: spacing.md },
|
||||
switchRow: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
flexWrap: "wrap",
|
||||
},
|
||||
changeServer: {
|
||||
alignItems: "center",
|
||||
padding: spacing.md,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,111 @@
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Modal, Pressable, StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { useThemeColors, spacing, radius } from "@/lib/theme"
|
||||
|
||||
export type MediaAction =
|
||||
| "playlist"
|
||||
| "play-next"
|
||||
| "play-last"
|
||||
| "shuffle"
|
||||
| "favorite"
|
||||
| "go-artist"
|
||||
| "go-album"
|
||||
|
||||
export function MediaActionsSheet({
|
||||
visible,
|
||||
title,
|
||||
selectedCount = 1,
|
||||
favorited,
|
||||
showFavorite = true,
|
||||
showNavigation = false,
|
||||
onClose,
|
||||
onAction,
|
||||
}: {
|
||||
visible: boolean
|
||||
title: string
|
||||
selectedCount?: number
|
||||
favorited?: boolean
|
||||
showFavorite?: boolean
|
||||
showNavigation?: boolean
|
||||
onClose: () => void
|
||||
onAction: (action: MediaAction) => void
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
|
||||
const items: { action: MediaAction; label: string; icon: keyof typeof Ionicons.glyphMap }[] = [
|
||||
{ action: "playlist", label: `Add to Playlist${selectedCount > 1 ? ` (${selectedCount})` : ""}`, icon: "list" },
|
||||
{ action: "play-next", label: `Play Next${selectedCount > 1 ? ` (${selectedCount})` : ""}`, icon: "arrow-down-circle-outline" },
|
||||
{ action: "play-last", label: `Play Last${selectedCount > 1 ? ` (${selectedCount})` : ""}`, icon: "arrow-up-circle-outline" },
|
||||
{ action: "shuffle", label: `Shuffle${selectedCount > 1 ? ` (${selectedCount})` : ""}`, icon: "shuffle" },
|
||||
]
|
||||
|
||||
if (showFavorite) {
|
||||
items.push({
|
||||
action: "favorite",
|
||||
label: favorited ? "Remove from Favorites" : "Add to Favorites",
|
||||
icon: favorited ? "star" : "star-outline",
|
||||
})
|
||||
}
|
||||
|
||||
if (showNavigation) {
|
||||
items.push(
|
||||
{ action: "go-artist", label: "Go to Artist", icon: "person" },
|
||||
{ action: "go-album", label: "Go to Album", icon: "disc" }
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal visible={visible} transparent animationType="fade" onRequestClose={onClose}>
|
||||
<Pressable style={styles.overlay} onPress={onClose}>
|
||||
<Pressable
|
||||
style={[styles.sheet, { backgroundColor: colors.card, borderColor: colors.border }]}
|
||||
onPress={(event) => event.stopPropagation()}
|
||||
>
|
||||
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
||||
{title}
|
||||
</Text>
|
||||
{items.map((item) => (
|
||||
<Pressable
|
||||
key={item.action}
|
||||
style={styles.row}
|
||||
onPress={() => {
|
||||
onAction(item.action)
|
||||
onClose()
|
||||
}}
|
||||
>
|
||||
<Ionicons name={item.icon} size={20} color={colors.foreground} />
|
||||
<Text style={{ color: colors.foreground, fontSize: 16 }}>{item.label}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</Pressable>
|
||||
</Pressable>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
overlay: {
|
||||
flex: 1,
|
||||
backgroundColor: "rgba(0,0,0,0.45)",
|
||||
justifyContent: "flex-end",
|
||||
},
|
||||
sheet: {
|
||||
borderTopLeftRadius: radius.lg,
|
||||
borderTopRightRadius: radius.lg,
|
||||
borderWidth: 1,
|
||||
padding: spacing.lg,
|
||||
gap: spacing.xs,
|
||||
},
|
||||
title: {
|
||||
fontSize: 16,
|
||||
fontWeight: "700",
|
||||
marginBottom: spacing.sm,
|
||||
},
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingVertical: spacing.md,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,151 @@
|
||||
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 { 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"
|
||||
|
||||
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 },
|
||||
{ backgroundColor: colors.muted },
|
||||
]}
|
||||
contentFit="cover"
|
||||
transition={150}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
||||
const router = useRouter()
|
||||
const { config } = useServerConfig()
|
||||
const colors = useThemeColors()
|
||||
if (!config) return null
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={styles.card}
|
||||
onPress={() => router.push(`/album/${album.id}`)}
|
||||
>
|
||||
<CoverImage uri={albumCoverUrl(config.serverUrl, album.id)} size={140} />
|
||||
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
||||
{album.title}
|
||||
</Text>
|
||||
<Text style={[styles.subtitle, { color: colors.mutedForeground }]} numberOfLines={1}>
|
||||
{album.artist.name}
|
||||
</Text>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
export function ArtistCard({ artist }: { artist: BrowseArtist }) {
|
||||
const router = useRouter()
|
||||
const { config } = useServerConfig()
|
||||
const colors = useThemeColors()
|
||||
if (!config) return null
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={styles.card}
|
||||
onPress={() => router.push(`/artist/${artist.id}`)}
|
||||
>
|
||||
<CoverImage uri={artistCoverUrl(config.serverUrl, artist.id)} size={140} rounded />
|
||||
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
||||
{artist.name}
|
||||
</Text>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
|
||||
const router = useRouter()
|
||||
const { config } = useServerConfig()
|
||||
const colors = useThemeColors()
|
||||
if (!config) return null
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={styles.card}
|
||||
onPress={() => router.push(`/playlist/${playlist.id}`)}
|
||||
>
|
||||
<CoverImage uri={playlistCoverUrl(config.serverUrl, playlist.id)} size={140} />
|
||||
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
||||
{playlist.title}
|
||||
</Text>
|
||||
<Text style={[styles.subtitle, { color: colors.mutedForeground }]} numberOfLines={1}>
|
||||
{playlist.owner}
|
||||
</Text>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
export function ContentCarousel({
|
||||
title,
|
||||
href,
|
||||
content,
|
||||
}: {
|
||||
title: string
|
||||
href?: string
|
||||
content: (BrowseAlbum | BrowseArtist | PlaylistSummary)[]
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<Pressable
|
||||
disabled={!href}
|
||||
onPress={() => href && router.push(href as never)}
|
||||
style={styles.sectionHeader}
|
||||
>
|
||||
<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>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
card: {
|
||||
width: 140,
|
||||
gap: spacing.xs,
|
||||
},
|
||||
title: {
|
||||
fontSize: 14,
|
||||
fontWeight: "600",
|
||||
},
|
||||
subtitle: {
|
||||
fontSize: 12,
|
||||
},
|
||||
section: {
|
||||
gap: spacing.md,
|
||||
},
|
||||
sectionHeader: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.xs,
|
||||
},
|
||||
sectionTitle: {
|
||||
fontSize: 20,
|
||||
fontWeight: "700",
|
||||
},
|
||||
grid: {
|
||||
flexDirection: "row",
|
||||
flexWrap: "wrap",
|
||||
gap: spacing.lg,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,270 @@
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
export function SongRow({
|
||||
song,
|
||||
onPress,
|
||||
onLongPress,
|
||||
trailing,
|
||||
}: {
|
||||
song: BrowseSong
|
||||
onPress?: () => void
|
||||
onLongPress?: () => void
|
||||
trailing?: React.ReactNode
|
||||
}) {
|
||||
const { config } = useServerConfig()
|
||||
const colors = useThemeColors()
|
||||
if (!config) return null
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
||||
onPress={onPress}
|
||||
onLongPress={onLongPress}
|
||||
>
|
||||
<Image
|
||||
source={{ uri: albumCoverUrl(config.serverUrl, song.album.id) }}
|
||||
style={styles.rowArtwork}
|
||||
contentFit="cover"
|
||||
/>
|
||||
<View style={styles.rowMeta}>
|
||||
<Text style={[styles.rowTitle, { color: colors.foreground }]} numberOfLines={1}>
|
||||
{song.title}
|
||||
</Text>
|
||||
<Text style={[styles.rowSubtitle, { color: colors.mutedForeground }]} numberOfLines={1}>
|
||||
{song.artist.name} · {song.album.title}
|
||||
</Text>
|
||||
</View>
|
||||
<Text style={[styles.duration, { color: colors.mutedForeground }]}>
|
||||
{formatDuration(song.durationSeconds)}
|
||||
</Text>
|
||||
{trailing}
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
export const contentBottomInset = playerBarHeight + 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",
|
||||
gap: spacing.sm,
|
||||
paddingVertical: spacing.sm,
|
||||
paddingHorizontal: spacing.lg,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
rowArtwork: {
|
||||
width: 44,
|
||||
height: 44,
|
||||
borderRadius: 6,
|
||||
},
|
||||
rowMeta: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
},
|
||||
rowTitle: {
|
||||
fontSize: 15,
|
||||
fontWeight: "500",
|
||||
},
|
||||
rowSubtitle: {
|
||||
fontSize: 13,
|
||||
marginTop: 2,
|
||||
},
|
||||
duration: {
|
||||
fontSize: 12,
|
||||
marginRight: spacing.xs,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
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",
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,140 @@
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Pressable,
|
||||
PressableProps,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TextInput,
|
||||
TextInputProps,
|
||||
View,
|
||||
} from "react-native"
|
||||
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
|
||||
type ButtonProps = Omit<PressableProps, "style"> & {
|
||||
title: string
|
||||
variant?: "primary" | "secondary" | "ghost" | "destructive"
|
||||
loading?: boolean
|
||||
style?: PressableProps["style"]
|
||||
}
|
||||
|
||||
export function Button({
|
||||
title,
|
||||
variant = "primary",
|
||||
loading = false,
|
||||
disabled,
|
||||
...props
|
||||
}: ButtonProps) {
|
||||
const colors = useThemeColors()
|
||||
const isDisabled = disabled || loading
|
||||
|
||||
const backgroundColor =
|
||||
variant === "primary"
|
||||
? colors.primary
|
||||
: variant === "secondary"
|
||||
? colors.muted
|
||||
: variant === "destructive"
|
||||
? colors.destructive
|
||||
: "transparent"
|
||||
|
||||
const textColor =
|
||||
variant === "primary"
|
||||
? colors.primaryForeground
|
||||
: variant === "destructive"
|
||||
? "#fff"
|
||||
: colors.foreground
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
{...props}
|
||||
disabled={isDisabled}
|
||||
style={({ pressed }) => ({
|
||||
minHeight: 44,
|
||||
borderRadius: radius.md,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.sm,
|
||||
backgroundColor,
|
||||
opacity: isDisabled ? 0.5 : pressed ? 0.85 : 1,
|
||||
})}
|
||||
>
|
||||
{loading ? (
|
||||
<ActivityIndicator color={textColor} />
|
||||
) : (
|
||||
<Text style={[styles.buttonText, { color: textColor }]}>{title}</Text>
|
||||
)}
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
export function Input({ style, ...props }: TextInputProps) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<TextInput
|
||||
{...props}
|
||||
placeholderTextColor={colors.mutedForeground}
|
||||
style={[
|
||||
styles.input,
|
||||
{
|
||||
color: colors.foreground,
|
||||
backgroundColor: colors.muted,
|
||||
borderColor: colors.border,
|
||||
},
|
||||
style,
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function Card({ children }: { children: React.ReactNode }) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<View style={[styles.card, { backgroundColor: colors.card, borderColor: colors.border }]}>
|
||||
{children}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export function LoadingView() {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<View style={styles.loading}>
|
||||
<ActivityIndicator color={colors.foreground} size="large" />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
button: {
|
||||
minHeight: 44,
|
||||
borderRadius: radius.md,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.sm,
|
||||
},
|
||||
buttonText: {
|
||||
fontSize: 16,
|
||||
fontWeight: "600",
|
||||
},
|
||||
input: {
|
||||
minHeight: 44,
|
||||
borderRadius: radius.md,
|
||||
borderWidth: 1,
|
||||
paddingHorizontal: spacing.md,
|
||||
fontSize: 16,
|
||||
},
|
||||
card: {
|
||||
borderRadius: radius.lg,
|
||||
borderWidth: 1,
|
||||
padding: spacing.lg,
|
||||
gap: spacing.md,
|
||||
},
|
||||
loading: {
|
||||
flex: 1,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
padding: spacing.xl,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,250 @@
|
||||
import { useConvex, useMutation, useQuery } from "convex/react"
|
||||
import { useRouter } from "expo-router"
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import { Modal, Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { Button, Input } from "@/components/ui/primitives"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { OwnedPlaylistForAdd } from "@otunes/convex/types"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { showError, showSuccess } from "@/lib/toast"
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
|
||||
type AddToPlaylistContextValue = {
|
||||
openAddToPlaylist: (songIds: Id<"songs">[]) => void
|
||||
openAddAlbumToPlaylist: (albumId: Id<"albums">) => Promise<void>
|
||||
openAddPlaylistToPlaylist: (playlistId: Id<"playlists">) => Promise<void>
|
||||
openAddArtistToPlaylist: (artistId: Id<"artists">) => Promise<void>
|
||||
openCreatePlaylist: () => void
|
||||
}
|
||||
|
||||
const AddToPlaylistContext = createContext<AddToPlaylistContextValue | null>(null)
|
||||
|
||||
export function useAddToPlaylist() {
|
||||
const context = useContext(AddToPlaylistContext)
|
||||
if (!context) {
|
||||
throw new Error("useAddToPlaylist must be used within AddToPlaylistProvider")
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
export function AddToPlaylistProvider({ children }: { children: ReactNode }) {
|
||||
const convex = useConvex()
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const ownedPlaylists = useQuery(api.playlists.listOwnedPlaylists)
|
||||
const addSongs = useMutation(api.playlists.addSongsToPlaylist)
|
||||
const createPlaylist = useMutation(api.playlists.createPlaylist)
|
||||
|
||||
const [open, setOpen] = useState(false)
|
||||
const [createOpen, setCreateOpen] = useState(false)
|
||||
const [pendingSongIds, setPendingSongIds] = useState<Id<"songs">[]>([])
|
||||
const [newPlaylistName, setNewPlaylistName] = useState("")
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
const openAddToPlaylist = useCallback((songIds: Id<"songs">[]) => {
|
||||
setPendingSongIds(songIds)
|
||||
setOpen(true)
|
||||
}, [])
|
||||
|
||||
const openAddAlbumToPlaylist = useCallback(
|
||||
async (albumId: Id<"albums">) => {
|
||||
const songIds = await convex.query(api.playlists.getAlbumSongIds, {
|
||||
albumId,
|
||||
})
|
||||
openAddToPlaylist(songIds)
|
||||
},
|
||||
[convex, openAddToPlaylist]
|
||||
)
|
||||
|
||||
const openAddPlaylistToPlaylist = useCallback(
|
||||
async (playlistId: Id<"playlists">) => {
|
||||
const songIds = await convex.query(api.playlists.getPlaylistSongIds, {
|
||||
playlistId,
|
||||
})
|
||||
openAddToPlaylist(songIds)
|
||||
},
|
||||
[convex, openAddToPlaylist]
|
||||
)
|
||||
|
||||
const openAddArtistToPlaylist = useCallback(
|
||||
async (artistId: Id<"artists">) => {
|
||||
const songIds = await convex.query(
|
||||
api.playlists.getOrderedArtistSongIds,
|
||||
{ artistId }
|
||||
)
|
||||
openAddToPlaylist(songIds)
|
||||
},
|
||||
[convex, openAddToPlaylist]
|
||||
)
|
||||
|
||||
const openCreatePlaylist = useCallback(() => {
|
||||
setNewPlaylistName("")
|
||||
setCreateOpen(true)
|
||||
}, [])
|
||||
|
||||
const handleAddToPlaylist = useCallback(
|
||||
async (playlistId: Id<"playlists">, title: string, existing: Id<"songs">[]) => {
|
||||
const existingSet = new Set(existing)
|
||||
const toAdd = pendingSongIds.filter((id) => !existingSet.has(id))
|
||||
if (toAdd.length === 0) {
|
||||
showSuccess(`All selected songs are already in ${title}`)
|
||||
setOpen(false)
|
||||
return
|
||||
}
|
||||
try {
|
||||
await addSongs({ playlistId, songIds: toAdd })
|
||||
showSuccess(
|
||||
toAdd.length > 1
|
||||
? `Added ${toAdd.length} songs to ${title}`
|
||||
: `Added to ${title}`
|
||||
)
|
||||
setOpen(false)
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to add to playlist")
|
||||
}
|
||||
},
|
||||
[addSongs, pendingSongIds]
|
||||
)
|
||||
|
||||
const handleCreatePlaylist = useCallback(async () => {
|
||||
const name = newPlaylistName.trim()
|
||||
if (!name) return
|
||||
setSubmitting(true)
|
||||
try {
|
||||
const playlistId = await createPlaylist({ name })
|
||||
if (pendingSongIds.length > 0) {
|
||||
await addSongs({ playlistId, songIds: pendingSongIds })
|
||||
}
|
||||
showSuccess("Playlist created")
|
||||
setCreateOpen(false)
|
||||
setOpen(false)
|
||||
router.push(`/playlist/${playlistId}`)
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to create playlist")
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}, [newPlaylistName, createPlaylist, pendingSongIds, addSongs, router])
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
openAddToPlaylist,
|
||||
openAddAlbumToPlaylist,
|
||||
openAddPlaylistToPlaylist,
|
||||
openAddArtistToPlaylist,
|
||||
openCreatePlaylist,
|
||||
}),
|
||||
[
|
||||
openAddToPlaylist,
|
||||
openAddAlbumToPlaylist,
|
||||
openAddPlaylistToPlaylist,
|
||||
openAddArtistToPlaylist,
|
||||
openCreatePlaylist,
|
||||
]
|
||||
)
|
||||
|
||||
return (
|
||||
<AddToPlaylistContext.Provider value={value}>
|
||||
{children}
|
||||
|
||||
<Modal visible={open} animationType="slide" transparent onRequestClose={() => setOpen(false)}>
|
||||
<Pressable style={styles.overlay} onPress={() => setOpen(false)}>
|
||||
<Pressable
|
||||
style={[styles.sheet, { backgroundColor: colors.card, borderColor: colors.border }]}
|
||||
onPress={(event) => event.stopPropagation()}
|
||||
>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>Add to Playlist</Text>
|
||||
<ScrollView style={styles.list}>
|
||||
{ownedPlaylists?.map((playlist: OwnedPlaylistForAdd) => (
|
||||
<Pressable
|
||||
key={playlist.id}
|
||||
style={styles.row}
|
||||
onPress={() =>
|
||||
void handleAddToPlaylist(playlist.id, playlist.title, playlist.songIds)
|
||||
}
|
||||
>
|
||||
<Text style={{ color: colors.foreground }}>{playlist.title}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
<Button title="New Playlist" variant="secondary" onPress={() => { setOpen(false); openCreatePlaylist() }} />
|
||||
</Pressable>
|
||||
</Pressable>
|
||||
</Modal>
|
||||
|
||||
<Modal visible={createOpen} animationType="fade" transparent onRequestClose={() => setCreateOpen(false)}>
|
||||
<Pressable style={styles.overlay} onPress={() => setCreateOpen(false)}>
|
||||
<Pressable
|
||||
style={[styles.createSheet, { backgroundColor: colors.card, borderColor: colors.border }]}
|
||||
onPress={(event) => event.stopPropagation()}
|
||||
>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>New Playlist</Text>
|
||||
<Input
|
||||
value={newPlaylistName}
|
||||
onChangeText={setNewPlaylistName}
|
||||
placeholder="Playlist name"
|
||||
autoFocus
|
||||
/>
|
||||
<View style={styles.createActions}>
|
||||
<Button title="Cancel" variant="ghost" onPress={() => setCreateOpen(false)} />
|
||||
<Button
|
||||
title="Create"
|
||||
loading={submitting}
|
||||
disabled={!newPlaylistName.trim()}
|
||||
onPress={() => void handleCreatePlaylist()}
|
||||
/>
|
||||
</View>
|
||||
</Pressable>
|
||||
</Pressable>
|
||||
</Modal>
|
||||
</AddToPlaylistContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
overlay: {
|
||||
flex: 1,
|
||||
backgroundColor: "rgba(0,0,0,0.45)",
|
||||
justifyContent: "flex-end",
|
||||
},
|
||||
sheet: {
|
||||
maxHeight: "60%",
|
||||
borderTopLeftRadius: 16,
|
||||
borderTopRightRadius: 16,
|
||||
borderWidth: 1,
|
||||
padding: 16,
|
||||
gap: 12,
|
||||
},
|
||||
createSheet: {
|
||||
margin: 24,
|
||||
borderRadius: 16,
|
||||
borderWidth: 1,
|
||||
padding: 16,
|
||||
gap: 12,
|
||||
},
|
||||
title: {
|
||||
fontSize: 18,
|
||||
fontWeight: "700",
|
||||
},
|
||||
list: {
|
||||
maxHeight: 280,
|
||||
},
|
||||
row: {
|
||||
paddingVertical: 14,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
borderBottomColor: "#e4e4e7",
|
||||
},
|
||||
createActions: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "flex-end",
|
||||
gap: 8,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,29 @@
|
||||
import { ConvexAuthProvider } from "@convex-dev/auth/react"
|
||||
import { ConvexReactClient } from "convex/react"
|
||||
import { useMemo, type ReactNode } from "react"
|
||||
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { secureStorage } from "@/lib/auth-storage"
|
||||
|
||||
export function ConvexAppProvider({ children }: { children: ReactNode }) {
|
||||
const { config } = useServerConfig()
|
||||
|
||||
const client = useMemo(() => {
|
||||
if (!config) return null
|
||||
return new ConvexReactClient(config.convexUrl)
|
||||
}, [config?.convexUrl])
|
||||
|
||||
if (!client || !config) {
|
||||
return <>{children}</>
|
||||
}
|
||||
|
||||
return (
|
||||
<ConvexAuthProvider
|
||||
client={client}
|
||||
storage={secureStorage}
|
||||
storageNamespace={config.convexUrl}
|
||||
>
|
||||
{children}
|
||||
</ConvexAuthProvider>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { useMutation, useQuery } from "convex/react"
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useMemo,
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { showError, showSuccess } from "@/lib/toast"
|
||||
|
||||
type FavoritesContextValue = {
|
||||
isSongFavorite: (songId: string) => boolean
|
||||
isAlbumFavorite: (albumId: string) => boolean
|
||||
isArtistFavorite: (artistId: string) => boolean
|
||||
toggleSongFavorite: (songId: Id<"songs">) => Promise<void>
|
||||
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
|
||||
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
|
||||
}
|
||||
|
||||
const FavoritesContext = createContext<FavoritesContextValue | null>(null)
|
||||
|
||||
export function useFavorites() {
|
||||
const context = useContext(FavoritesContext)
|
||||
if (!context) {
|
||||
throw new Error("useFavorites must be used within FavoritesProvider")
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
export function FavoritesProvider({ children }: { children: ReactNode }) {
|
||||
const favorites = useQuery(api.favorites.getUserFavorites)
|
||||
const favoriteSong = useMutation(api.favorites.favoriteSong)
|
||||
const unfavoriteSong = useMutation(api.favorites.unfavoriteSong)
|
||||
const favoriteAlbum = useMutation(api.favorites.favoriteAlbum)
|
||||
const unfavoriteAlbum = useMutation(api.favorites.unfavoriteAlbum)
|
||||
const favoriteArtist = useMutation(api.favorites.favoriteArtist)
|
||||
const unfavoriteArtist = useMutation(api.favorites.unfavoriteArtist)
|
||||
|
||||
const songIds = useMemo(
|
||||
() => new Set(favorites?.favoriteSongs.map(String) ?? []),
|
||||
[favorites?.favoriteSongs]
|
||||
)
|
||||
const albumIds = useMemo(
|
||||
() => new Set(favorites?.favoriteAlbums.map(String) ?? []),
|
||||
[favorites?.favoriteAlbums]
|
||||
)
|
||||
const artistIds = useMemo(
|
||||
() => new Set(favorites?.favoriteArtists.map(String) ?? []),
|
||||
[favorites?.favoriteArtists]
|
||||
)
|
||||
|
||||
const toggleSongFavorite = useCallback(
|
||||
async (songId: Id<"songs">) => {
|
||||
try {
|
||||
if (songIds.has(songId)) {
|
||||
await unfavoriteSong({ songId })
|
||||
showSuccess("Removed from favorites")
|
||||
} else {
|
||||
await favoriteSong({ songId })
|
||||
showSuccess("Added to favorites")
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to update favorites")
|
||||
}
|
||||
},
|
||||
[songIds, favoriteSong, unfavoriteSong]
|
||||
)
|
||||
|
||||
const toggleAlbumFavorite = useCallback(
|
||||
async (albumId: Id<"albums">) => {
|
||||
try {
|
||||
if (albumIds.has(albumId)) {
|
||||
await unfavoriteAlbum({ albumId })
|
||||
showSuccess("Removed from favorites")
|
||||
} else {
|
||||
await favoriteAlbum({ albumId })
|
||||
showSuccess("Added to favorites")
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to update favorites")
|
||||
}
|
||||
},
|
||||
[albumIds, favoriteAlbum, unfavoriteAlbum]
|
||||
)
|
||||
|
||||
const toggleArtistFavorite = useCallback(
|
||||
async (artistId: Id<"artists">) => {
|
||||
try {
|
||||
if (artistIds.has(artistId)) {
|
||||
await unfavoriteArtist({ artistId })
|
||||
showSuccess("Removed from favorites")
|
||||
} else {
|
||||
await favoriteArtist({ artistId })
|
||||
showSuccess("Added to favorites")
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : "Failed to update favorites")
|
||||
}
|
||||
},
|
||||
[artistIds, favoriteArtist, unfavoriteArtist]
|
||||
)
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
isSongFavorite: (songId: string) => songIds.has(songId),
|
||||
isAlbumFavorite: (albumId: string) => albumIds.has(albumId),
|
||||
isArtistFavorite: (artistId: string) => artistIds.has(artistId),
|
||||
toggleSongFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
}),
|
||||
[songIds, albumIds, artistIds, toggleSongFavorite, toggleAlbumFavorite, toggleArtistFavorite]
|
||||
)
|
||||
|
||||
return (
|
||||
<FavoritesContext.Provider value={value}>
|
||||
{children}
|
||||
</FavoritesContext.Provider>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,521 @@
|
||||
import { Audio, AVPlaybackStatus } from "expo-av"
|
||||
import { useConvex, useMutation, useQuery } from "convex/react"
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { showError } from "@/lib/toast"
|
||||
import type { PlaybackQuality } from "@/lib/urls"
|
||||
import { songHlsPlaylistUrl, songPlayUrl } from "@/lib/urls"
|
||||
|
||||
type RepeatMode = "none" | "once" | "always"
|
||||
|
||||
const PREVIOUS_TRACK_RESTART_THRESHOLD_SECONDS = 5
|
||||
const VOLUME_STORAGE_KEY = "otunes:volume"
|
||||
const DEFAULT_VOLUME = 0.8
|
||||
|
||||
type PlaybackContextValue = {
|
||||
queueSongIds: Id<"songs">[]
|
||||
queueHistorySongIds: Id<"songs">[]
|
||||
currentSong: BrowseSong | null
|
||||
shuffleEnabled: boolean
|
||||
repeatEnabled: RepeatMode
|
||||
isPlaying: boolean
|
||||
volume: number
|
||||
currentTime: number
|
||||
duration: number
|
||||
seekTo: (seconds: number) => void
|
||||
setIsPlaying: (playing: boolean) => void
|
||||
setVolume: (volume: number) => void
|
||||
playInOrder: (songIds: Id<"songs">[]) => Promise<void>
|
||||
playShuffled: (songIds: Id<"songs">[]) => Promise<void>
|
||||
addToQueueNext: (songIds: Id<"songs">[]) => Promise<void>
|
||||
addToQueueLast: (songIds: Id<"songs">[]) => Promise<void>
|
||||
playFromSong: (songId: Id<"songs">, songIds: Id<"songs">[]) => Promise<void>
|
||||
playFromLibrarySong: (
|
||||
songId: Id<"songs">,
|
||||
sort: {
|
||||
sortKey: "title" | "artist" | "album"
|
||||
sortDirection: "asc" | "desc"
|
||||
}
|
||||
) => Promise<void>
|
||||
playAlbum: (albumId: Id<"albums">) => Promise<void>
|
||||
playAlbumShuffled: (albumId: Id<"albums">) => Promise<void>
|
||||
playArtist: (artistId: Id<"artists">) => Promise<void>
|
||||
playArtistShuffled: (artistId: Id<"artists">) => Promise<void>
|
||||
playPlaylist: (playlistId: Id<"playlists">) => Promise<void>
|
||||
playPlaylistShuffled: (playlistId: Id<"playlists">) => Promise<void>
|
||||
toggleShuffle: () => Promise<void>
|
||||
cycleRepeat: () => Promise<void>
|
||||
clearQueue: () => Promise<void>
|
||||
reorderQueue: (songIds: Id<"songs">[]) => Promise<void>
|
||||
skipToQueueIndex: (index: number) => Promise<void>
|
||||
skipNext: () => Promise<void>
|
||||
skipPrevious: () => Promise<void>
|
||||
}
|
||||
|
||||
const PlaybackContext = createContext<PlaybackContextValue | null>(null)
|
||||
|
||||
function playbackLoadSettings(user: {
|
||||
preferAtmos?: boolean
|
||||
playbackQuality?: PlaybackQuality
|
||||
}) {
|
||||
const preferAtmos = user.preferAtmos ?? false
|
||||
const playbackQuality = user.playbackQuality ?? "medium"
|
||||
const useHls = playbackQuality !== "lossless" && !preferAtmos
|
||||
return { preferAtmos, playbackQuality, useHls }
|
||||
}
|
||||
|
||||
export function usePlayback() {
|
||||
const context = useContext(PlaybackContext)
|
||||
if (!context) {
|
||||
throw new Error("usePlayback must be used within PlaybackProvider")
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
const convex = useConvex()
|
||||
const { config } = useServerConfig()
|
||||
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 autoPlayNextRef = useRef(false)
|
||||
const isPlayingRef = useRef(false)
|
||||
const progressRestoredForSongRef = useRef<Id<"songs"> | null>(null)
|
||||
const lastSavedProgressRef = useRef(-1)
|
||||
|
||||
const [isPlaying, setIsPlayingState] = useState(false)
|
||||
const [currentTime, setCurrentTime] = useState(0)
|
||||
const [duration, setDuration] = useState(0)
|
||||
const [volume, setVolumeState] = useState(DEFAULT_VOLUME)
|
||||
const [progressToRestore, setProgressToRestore] = useState<number | null>(null)
|
||||
|
||||
const playInOrderMutation = useMutation(api.playback.playInOrder)
|
||||
const playShuffledMutation = useMutation(api.playback.playShuffled)
|
||||
const addToQueueNextMutation = useMutation(api.playback.addToQueueNext)
|
||||
const addToQueueLastMutation = useMutation(api.playback.addToQueueLast)
|
||||
const playFromSongMutation = useMutation(api.playback.playFromSong)
|
||||
const playFromLibrarySongMutation = useMutation(
|
||||
api.playback.playFromLibrarySong
|
||||
)
|
||||
const toggleShuffleMutation = useMutation(api.playback.toggleShuffle)
|
||||
const cycleRepeatMutation = useMutation(api.playback.cycleRepeat)
|
||||
const clearQueueMutation = useMutation(api.playback.clearQueue)
|
||||
const reorderQueueMutation = useMutation(api.playback.reorderQueue)
|
||||
const skipToQueueIndexMutation = useMutation(api.playback.skipToQueueIndex)
|
||||
const skipNextMutation = useMutation(api.playback.skipNext)
|
||||
const skipPreviousMutation = useMutation(api.playback.skipPrevious)
|
||||
const updateSongProgressMutation = useMutation(api.playback.updateSongProgress)
|
||||
|
||||
const currentSong = playback?.currentSong ?? null
|
||||
const repeatEnabled = playback?.repeatEnabled ?? "none"
|
||||
const queueLength = playback?.queueSongIds.length ?? 0
|
||||
|
||||
useEffect(() => {
|
||||
void Audio.setAudioModeAsync({
|
||||
playsInSilentModeIOS: true,
|
||||
staysActiveInBackground: true,
|
||||
shouldDuckAndroid: true,
|
||||
})
|
||||
void AsyncStorage.getItem(VOLUME_STORAGE_KEY).then((stored) => {
|
||||
if (stored) {
|
||||
const parsed = Number(stored)
|
||||
if (Number.isFinite(parsed)) {
|
||||
setVolumeState(Math.min(1, Math.max(0, parsed)))
|
||||
}
|
||||
}
|
||||
})
|
||||
return () => {
|
||||
void soundRef.current?.unloadAsync()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const setIsPlaying = useCallback((playing: boolean) => {
|
||||
isPlayingRef.current = playing
|
||||
setIsPlayingState(playing)
|
||||
const sound = soundRef.current
|
||||
if (!sound) return
|
||||
if (playing) {
|
||||
void sound.playAsync()
|
||||
} else {
|
||||
void sound.pauseAsync()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const setVolume = useCallback((nextVolume: number) => {
|
||||
const clamped = Math.min(1, Math.max(0, nextVolume))
|
||||
setVolumeState(clamped)
|
||||
void AsyncStorage.setItem(VOLUME_STORAGE_KEY, String(clamped))
|
||||
void soundRef.current?.setVolumeAsync(clamped)
|
||||
}, [])
|
||||
|
||||
const seekTo = useCallback(
|
||||
async (seconds: number) => {
|
||||
const sound = soundRef.current
|
||||
if (!sound) return
|
||||
const clamped = Math.max(0, Math.min(seconds, duration || 0))
|
||||
await sound.setPositionAsync(clamped * 1000)
|
||||
setCurrentTime(clamped)
|
||||
},
|
||||
[duration]
|
||||
)
|
||||
|
||||
const saveProgress = useCallback(
|
||||
(seconds: number) => {
|
||||
const progressSeconds = Math.max(0, Math.floor(seconds))
|
||||
if (progressSeconds === lastSavedProgressRef.current) return
|
||||
lastSavedProgressRef.current = progressSeconds
|
||||
void updateSongProgressMutation({ progressSeconds })
|
||||
},
|
||||
[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
|
||||
progressRestoredForSongRef.current = currentSong.id
|
||||
lastSavedProgressRef.current = -1
|
||||
setProgressToRestore(playback.currentSongProgress ?? 0)
|
||||
}, [currentSong?.id, playback])
|
||||
|
||||
useEffect(() => {
|
||||
async function loadSong() {
|
||||
if (!config || !currentSong || user === undefined || !user) {
|
||||
if (!currentSong) {
|
||||
loadedSongIdRef.current = null
|
||||
await soundRef.current?.unloadAsync()
|
||||
soundRef.current = null
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const settings = playbackLoadSettings(user)
|
||||
const loadKey = `${currentSong.id}:${settings.playbackQuality}:${settings.useHls ? "hls" : "file"}`
|
||||
if (loadedSongIdRef.current === loadKey) return
|
||||
|
||||
const uri = settings.useHls
|
||||
? songHlsPlaylistUrl(
|
||||
config.serverUrl,
|
||||
currentSong.id,
|
||||
settings.playbackQuality,
|
||||
settings.preferAtmos
|
||||
)
|
||||
: songPlayUrl(
|
||||
config.serverUrl,
|
||||
currentSong.id,
|
||||
settings.playbackQuality,
|
||||
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
|
||||
|
||||
if (progressToRestore && progressToRestore > 0) {
|
||||
await sound.setPositionAsync(progressToRestore * 1000)
|
||||
setProgressToRestore(null)
|
||||
}
|
||||
|
||||
setDuration(currentSong.durationSeconds)
|
||||
}
|
||||
|
||||
void loadSong().catch(() => {
|
||||
showError("Could not play this track. The queue has been cleared.")
|
||||
void clearQueueMutation()
|
||||
setIsPlayingState(false)
|
||||
})
|
||||
}, [
|
||||
config,
|
||||
currentSong?.id,
|
||||
user?.playbackQuality,
|
||||
user?.preferAtmos,
|
||||
user === undefined,
|
||||
volume,
|
||||
onPlaybackStatusUpdate,
|
||||
clearQueueMutation,
|
||||
progressToRestore,
|
||||
currentSong,
|
||||
user,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPlaying || !currentSong) return
|
||||
const interval = setInterval(() => {
|
||||
saveProgress(currentTime)
|
||||
}, 5000)
|
||||
return () => clearInterval(interval)
|
||||
}, [isPlaying, currentSong?.id, currentTime, saveProgress])
|
||||
|
||||
const playInOrder = useCallback(
|
||||
async (songIds: Id<"songs">[]) => {
|
||||
if (songIds.length === 0) return
|
||||
await playInOrderMutation({ songIds })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[playInOrderMutation, setIsPlaying]
|
||||
)
|
||||
|
||||
const playShuffled = useCallback(
|
||||
async (songIds: Id<"songs">[]) => {
|
||||
if (songIds.length === 0) return
|
||||
await playShuffledMutation({ songIds })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[playShuffledMutation, setIsPlaying]
|
||||
)
|
||||
|
||||
const addToQueueNext = useCallback(
|
||||
async (songIds: Id<"songs">[]) => {
|
||||
if (songIds.length === 0) return
|
||||
await addToQueueNextMutation({ songIds })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[addToQueueNextMutation, setIsPlaying]
|
||||
)
|
||||
|
||||
const addToQueueLast = useCallback(
|
||||
async (songIds: Id<"songs">[]) => {
|
||||
if (songIds.length === 0) return
|
||||
await addToQueueLastMutation({ songIds })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[addToQueueLastMutation, setIsPlaying]
|
||||
)
|
||||
|
||||
const playFromSong = useCallback(
|
||||
async (songId: Id<"songs">, songIds: Id<"songs">[]) => {
|
||||
await playFromSongMutation({ songId, songIds })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[playFromSongMutation, setIsPlaying]
|
||||
)
|
||||
|
||||
const playFromLibrarySong = useCallback(
|
||||
async (
|
||||
songId: Id<"songs">,
|
||||
sort: {
|
||||
sortKey: "title" | "artist" | "album"
|
||||
sortDirection: "asc" | "desc"
|
||||
}
|
||||
) => {
|
||||
await playFromLibrarySongMutation({ songId, ...sort })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[playFromLibrarySongMutation, setIsPlaying]
|
||||
)
|
||||
|
||||
const playAlbum = useCallback(
|
||||
async (albumId: Id<"albums">) => {
|
||||
const songIds = await convex.query(api.playlists.getAlbumSongIds, {
|
||||
albumId,
|
||||
})
|
||||
await playInOrder(songIds)
|
||||
},
|
||||
[convex, playInOrder]
|
||||
)
|
||||
|
||||
const playAlbumShuffled = useCallback(
|
||||
async (albumId: Id<"albums">) => {
|
||||
const songIds = await convex.query(api.playlists.getAlbumSongIds, {
|
||||
albumId,
|
||||
})
|
||||
await playShuffled(songIds)
|
||||
},
|
||||
[convex, playShuffled]
|
||||
)
|
||||
|
||||
const playArtist = useCallback(
|
||||
async (artistId: Id<"artists">) => {
|
||||
const songIds = await convex.query(
|
||||
api.playlists.getOrderedArtistSongIds,
|
||||
{ artistId }
|
||||
)
|
||||
await playInOrder(songIds)
|
||||
},
|
||||
[convex, playInOrder]
|
||||
)
|
||||
|
||||
const playArtistShuffled = useCallback(
|
||||
async (artistId: Id<"artists">) => {
|
||||
const songIds = await convex.query(
|
||||
api.playlists.getOrderedArtistSongIds,
|
||||
{ artistId }
|
||||
)
|
||||
await playShuffled(songIds)
|
||||
},
|
||||
[convex, playShuffled]
|
||||
)
|
||||
|
||||
const playPlaylist = useCallback(
|
||||
async (playlistId: Id<"playlists">) => {
|
||||
const songIds = await convex.query(api.playlists.getPlaylistSongIds, {
|
||||
playlistId,
|
||||
})
|
||||
await playInOrderMutation({ songIds, playlistId })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[convex, playInOrderMutation, setIsPlaying]
|
||||
)
|
||||
|
||||
const playPlaylistShuffled = useCallback(
|
||||
async (playlistId: Id<"playlists">) => {
|
||||
const songIds = await convex.query(api.playlists.getPlaylistSongIds, {
|
||||
playlistId,
|
||||
})
|
||||
await playShuffledMutation({ songIds, playlistId })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[convex, playShuffledMutation, setIsPlaying]
|
||||
)
|
||||
|
||||
const value = useMemo<PlaybackContextValue>(
|
||||
() => ({
|
||||
queueSongIds: playback?.queueSongIds ?? [],
|
||||
queueHistorySongIds: playback?.queueHistorySongIds ?? [],
|
||||
currentSong: playback?.currentSong ?? null,
|
||||
shuffleEnabled: playback?.shuffleEnabled ?? false,
|
||||
repeatEnabled: playback?.repeatEnabled ?? "none",
|
||||
isPlaying: Boolean(currentSong && isPlaying),
|
||||
volume,
|
||||
currentTime,
|
||||
duration,
|
||||
seekTo,
|
||||
setIsPlaying,
|
||||
setVolume,
|
||||
playInOrder,
|
||||
playShuffled,
|
||||
addToQueueNext,
|
||||
addToQueueLast,
|
||||
playFromSong,
|
||||
playFromLibrarySong,
|
||||
playAlbum,
|
||||
playAlbumShuffled,
|
||||
playArtist,
|
||||
playArtistShuffled,
|
||||
playPlaylist,
|
||||
playPlaylistShuffled,
|
||||
toggleShuffle: async () => {
|
||||
await toggleShuffleMutation()
|
||||
},
|
||||
cycleRepeat: async () => {
|
||||
await cycleRepeatMutation()
|
||||
},
|
||||
clearQueue: async () => {
|
||||
await clearQueueMutation()
|
||||
setIsPlaying(false)
|
||||
},
|
||||
reorderQueue: async (songIds) => {
|
||||
await reorderQueueMutation({ songIds })
|
||||
},
|
||||
skipToQueueIndex: async (index) => {
|
||||
await skipToQueueIndexMutation({ index })
|
||||
},
|
||||
skipNext: async () => {
|
||||
await skipNextMutation()
|
||||
},
|
||||
skipPrevious: async () => {
|
||||
if (currentTime > PREVIOUS_TRACK_RESTART_THRESHOLD_SECONDS) {
|
||||
await seekTo(0)
|
||||
return
|
||||
}
|
||||
await skipPreviousMutation()
|
||||
},
|
||||
}),
|
||||
[
|
||||
playback,
|
||||
currentSong,
|
||||
isPlaying,
|
||||
volume,
|
||||
currentTime,
|
||||
duration,
|
||||
seekTo,
|
||||
setIsPlaying,
|
||||
setVolume,
|
||||
playInOrder,
|
||||
playShuffled,
|
||||
addToQueueNext,
|
||||
addToQueueLast,
|
||||
playFromSong,
|
||||
playFromLibrarySong,
|
||||
playAlbum,
|
||||
playAlbumShuffled,
|
||||
playArtist,
|
||||
playArtistShuffled,
|
||||
playPlaylist,
|
||||
playPlaylistShuffled,
|
||||
toggleShuffleMutation,
|
||||
cycleRepeatMutation,
|
||||
clearQueueMutation,
|
||||
reorderQueueMutation,
|
||||
skipToQueueIndexMutation,
|
||||
skipNextMutation,
|
||||
skipPreviousMutation,
|
||||
]
|
||||
)
|
||||
|
||||
return (
|
||||
<PlaybackContext.Provider value={value}>{children}</PlaybackContext.Provider>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
|
||||
import {
|
||||
clearServerConfig,
|
||||
loadServerConfig,
|
||||
parseServerHostname,
|
||||
saveServerConfig,
|
||||
type ServerConfig,
|
||||
} from "@/lib/server-config"
|
||||
|
||||
type ServerConfigContextValue = {
|
||||
config: ServerConfig | null
|
||||
isLoading: boolean
|
||||
setServerHostname: (hostname: string) => Promise<boolean>
|
||||
clearServer: () => Promise<void>
|
||||
}
|
||||
|
||||
const ServerConfigContext = createContext<ServerConfigContextValue | null>(null)
|
||||
|
||||
export function ServerConfigProvider({ children }: { children: ReactNode }) {
|
||||
const [config, setConfig] = useState<ServerConfig | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
void loadServerConfig((key) => AsyncStorage.getItem(key)).then((loaded) => {
|
||||
if (!cancelled) {
|
||||
setConfig(loaded)
|
||||
setIsLoading(false)
|
||||
}
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [])
|
||||
|
||||
const setServerHostname = useCallback(async (hostname: string) => {
|
||||
const parsed = parseServerHostname(hostname)
|
||||
if (!parsed) return false
|
||||
await saveServerConfig(
|
||||
(key, value) => AsyncStorage.setItem(key, value),
|
||||
parsed
|
||||
)
|
||||
setConfig(parsed)
|
||||
return true
|
||||
}, [])
|
||||
|
||||
const clearServer = useCallback(async () => {
|
||||
await clearServerConfig((key) => AsyncStorage.removeItem(key))
|
||||
setConfig(null)
|
||||
}, [])
|
||||
|
||||
const value = useMemo(
|
||||
() => ({ config, isLoading, setServerHostname, clearServer }),
|
||||
[config, isLoading, setServerHostname, clearServer]
|
||||
)
|
||||
|
||||
return (
|
||||
<ServerConfigContext.Provider value={value}>
|
||||
{children}
|
||||
</ServerConfigContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useServerConfig() {
|
||||
const context = useContext(ServerConfigContext)
|
||||
if (!context) {
|
||||
throw new Error("useServerConfig must be used within ServerConfigProvider")
|
||||
}
|
||||
return context
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { registerRootComponent } from 'expo';
|
||||
|
||||
import App from './App';
|
||||
|
||||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
|
||||
// It also ensures that whether you load the app in Expo Go or in a native build,
|
||||
// the environment is set up appropriately
|
||||
registerRootComponent(App);
|
||||
@@ -0,0 +1,14 @@
|
||||
import * as SecureStore from "expo-secure-store"
|
||||
import type { TokenStorage } from "@convex-dev/auth/react"
|
||||
|
||||
export const secureStorage: TokenStorage = {
|
||||
getItem(key) {
|
||||
return SecureStore.getItemAsync(key)
|
||||
},
|
||||
setItem(key, value) {
|
||||
return SecureStore.setItemAsync(key, value)
|
||||
},
|
||||
removeItem(key) {
|
||||
return SecureStore.deleteItemAsync(key)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
export function formatDuration(seconds: number): string {
|
||||
const total = Math.max(0, Math.floor(seconds))
|
||||
const minutes = Math.floor(total / 60)
|
||||
const remainingSeconds = total % 60
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`
|
||||
}
|
||||
|
||||
export function sumDurationSeconds(durations: number[]): number {
|
||||
return durations.reduce((sum, value) => sum + value, 0)
|
||||
}
|
||||
|
||||
export function formatMetadata(
|
||||
genre: string | null,
|
||||
year: number | null
|
||||
): string | null {
|
||||
const parts: string[] = []
|
||||
if (genre) parts.push(genre)
|
||||
if (year) parts.push(String(year))
|
||||
return parts.length > 0 ? parts.join(" · ") : null
|
||||
}
|
||||
|
||||
export function initialsFromName(name: string): string {
|
||||
return (
|
||||
name
|
||||
.match(/\b(\w)/g)
|
||||
?.join("")
|
||||
.slice(0, 2)
|
||||
.toUpperCase() ?? "NA"
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
export type PlaybackQuality = "low" | "medium" | "high" | "lossless"
|
||||
|
||||
export type ServerConfig = {
|
||||
/** Raw hostname the user entered, e.g. `music.example.com` or `localhost:3000` */
|
||||
hostname: string
|
||||
/** Base URL for the Next.js server, e.g. `https://music.example.com` */
|
||||
serverUrl: string
|
||||
/** Convex deployment URL, e.g. `https://convex.music.example.com` */
|
||||
convexUrl: string
|
||||
}
|
||||
|
||||
const SERVER_CONFIG_KEY = "otunes:server-config"
|
||||
|
||||
function isLocalHost(hostname: string): boolean {
|
||||
const host = hostname.split(":")[0]?.toLowerCase() ?? ""
|
||||
return (
|
||||
host === "localhost" ||
|
||||
host === "127.0.0.1" ||
|
||||
host.endsWith(".local") ||
|
||||
/^\d{1,3}(\.\d{1,3}){3}$/.test(host)
|
||||
)
|
||||
}
|
||||
|
||||
function normalizeHostnameInput(input: string): string {
|
||||
return input.trim().replace(/^https?:\/\//i, "").replace(/\/+$/, "")
|
||||
}
|
||||
|
||||
function buildServerUrl(hostname: string): string {
|
||||
const protocol = isLocalHost(hostname) ? "http" : "https"
|
||||
return `${protocol}://${hostname}`
|
||||
}
|
||||
|
||||
function buildConvexUrl(hostname: string): string {
|
||||
const [host, port] = hostname.split(":")
|
||||
const convexHost = `convex.${host}`
|
||||
const protocol = isLocalHost(hostname) ? "http" : "https"
|
||||
return port ? `${protocol}://${convexHost}:${port}` : `${protocol}://${convexHost}`
|
||||
}
|
||||
|
||||
export function parseServerHostname(input: string): ServerConfig | null {
|
||||
const hostname = normalizeHostnameInput(input)
|
||||
if (!hostname) return null
|
||||
|
||||
try {
|
||||
const serverUrl = buildServerUrl(hostname)
|
||||
const convexUrl = buildConvexUrl(hostname)
|
||||
new URL(serverUrl)
|
||||
new URL(convexUrl)
|
||||
return { hostname, serverUrl, convexUrl }
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadServerConfig(
|
||||
getItem: (key: string) => Promise<string | null>
|
||||
): Promise<ServerConfig | null> {
|
||||
const raw = await getItem(SERVER_CONFIG_KEY)
|
||||
if (!raw) return null
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as ServerConfig
|
||||
if (parsed.hostname && parsed.serverUrl && parsed.convexUrl) {
|
||||
return parsed
|
||||
}
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export async function saveServerConfig(
|
||||
setItem: (key: string, value: string) => Promise<void>,
|
||||
config: ServerConfig
|
||||
): Promise<void> {
|
||||
await setItem(SERVER_CONFIG_KEY, JSON.stringify(config))
|
||||
}
|
||||
|
||||
export async function clearServerConfig(
|
||||
removeItem: (key: string) => Promise<void>
|
||||
): Promise<void> {
|
||||
await removeItem(SERVER_CONFIG_KEY)
|
||||
}
|
||||
|
||||
export { SERVER_CONFIG_KEY }
|
||||
@@ -0,0 +1,8 @@
|
||||
export function shuffleArray<T>(array: T[]): T[] {
|
||||
const copy = [...array]
|
||||
for (let i = copy.length - 1; i > 0; i -= 1) {
|
||||
const j = Math.floor(Math.random() * (i + 1))
|
||||
;[copy[i], copy[j]] = [copy[j], copy[i]]
|
||||
}
|
||||
return copy
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { useColorScheme } from "react-native"
|
||||
|
||||
export const colors = {
|
||||
light: {
|
||||
background: "#ffffff",
|
||||
foreground: "#0a0a0a",
|
||||
card: "#ffffff",
|
||||
muted: "#f4f4f5",
|
||||
mutedForeground: "#71717a",
|
||||
border: "#e4e4e7",
|
||||
primary: "#18181b",
|
||||
primaryForeground: "#fafafa",
|
||||
destructive: "#dc2626",
|
||||
accent: "#f4f4f5",
|
||||
},
|
||||
dark: {
|
||||
background: "#0a0a0a",
|
||||
foreground: "#fafafa",
|
||||
card: "#171717",
|
||||
muted: "#262626",
|
||||
mutedForeground: "#a1a1aa",
|
||||
border: "#27272a",
|
||||
primary: "#fafafa",
|
||||
primaryForeground: "#18181b",
|
||||
destructive: "#ef4444",
|
||||
accent: "#262626",
|
||||
},
|
||||
} as const
|
||||
|
||||
export type ThemeColors = (typeof colors)[keyof typeof colors]
|
||||
|
||||
export function useThemeColors(): ThemeColors {
|
||||
const scheme = useColorScheme()
|
||||
return scheme === "dark" ? colors.dark : colors.light
|
||||
}
|
||||
|
||||
export const spacing = {
|
||||
xs: 4,
|
||||
sm: 8,
|
||||
md: 12,
|
||||
lg: 16,
|
||||
xl: 24,
|
||||
xxl: 32,
|
||||
} as const
|
||||
|
||||
export const radius = {
|
||||
sm: 6,
|
||||
md: 10,
|
||||
lg: 14,
|
||||
full: 9999,
|
||||
} as const
|
||||
|
||||
export const playerBarHeight = 88
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Alert } from "react-native"
|
||||
|
||||
export function showToast(message: string) {
|
||||
Alert.alert("", message)
|
||||
}
|
||||
|
||||
export function showError(message: string) {
|
||||
Alert.alert("Error", message)
|
||||
}
|
||||
|
||||
export function showSuccess(message: string) {
|
||||
Alert.alert("", message)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
export type PlaybackQuality = "low" | "medium" | "high" | "lossless"
|
||||
|
||||
export function artistCoverUrl(serverUrl: string, artistId: string) {
|
||||
return `${serverUrl}/api/artist/${artistId}/cover`
|
||||
}
|
||||
|
||||
export function albumCoverUrl(serverUrl: string, albumId: string) {
|
||||
return `${serverUrl}/api/album/${albumId}/cover`
|
||||
}
|
||||
|
||||
export function playlistCoverUrl(serverUrl: string, playlistId: string) {
|
||||
return `${serverUrl}/api/playlist/${playlistId}/cover`
|
||||
}
|
||||
|
||||
export function songPlayUrl(
|
||||
serverUrl: string,
|
||||
songId: string,
|
||||
quality: PlaybackQuality | undefined,
|
||||
preferAtmos: boolean | undefined
|
||||
) {
|
||||
const params = new URLSearchParams()
|
||||
if (quality) params.set("quality", quality)
|
||||
if (preferAtmos) params.set("preferAtmos", "true")
|
||||
const query = params.toString()
|
||||
return `${serverUrl}/api/song/${songId}/play${query ? `?${query}` : ""}`
|
||||
}
|
||||
|
||||
export function songHlsPlaylistUrl(
|
||||
serverUrl: string,
|
||||
songId: string,
|
||||
quality: PlaybackQuality | undefined,
|
||||
preferAtmos: boolean | undefined
|
||||
) {
|
||||
const params = new URLSearchParams()
|
||||
if (quality) params.set("quality", quality)
|
||||
if (preferAtmos) params.set("preferAtmos", "true")
|
||||
const query = params.toString()
|
||||
return `${serverUrl}/api/song/${songId}/play/hls${query ? `?${query}` : ""}`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
const { getDefaultConfig } = require("expo/metro-config")
|
||||
const path = require("path")
|
||||
|
||||
const projectRoot = __dirname
|
||||
const workspaceRoot = path.resolve(projectRoot, "../..")
|
||||
|
||||
const config = getDefaultConfig(projectRoot)
|
||||
|
||||
config.watchFolders = [workspaceRoot]
|
||||
config.resolver.nodeModulesPaths = [
|
||||
path.resolve(projectRoot, "node_modules"),
|
||||
path.resolve(workspaceRoot, "node_modules"),
|
||||
]
|
||||
|
||||
module.exports = config
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "@otunes/mobile",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "index.ts",
|
||||
"main": "expo-router/entry",
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
"android": "expo run:android",
|
||||
@@ -12,13 +12,31 @@
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@convex-dev/auth": "^0.0.93",
|
||||
"@expo/vector-icons": "^15.0.2",
|
||||
"@otunes/convex": "workspace:*",
|
||||
"@react-native-async-storage/async-storage": "2.2.0",
|
||||
"convex": "^1.40.0",
|
||||
"expo": "~56.0.11",
|
||||
"expo-av": "^16.0.8",
|
||||
"expo-constants": "~56.0.18",
|
||||
"expo-dev-client": "~56.0.20",
|
||||
"expo-haptics": "~56.0.3",
|
||||
"expo-image": "~56.0.11",
|
||||
"expo-image-picker": "~56.0.17",
|
||||
"expo-linking": "~56.0.14",
|
||||
"expo-router": "~56.2.10",
|
||||
"expo-secure-store": "~56.0.4",
|
||||
"expo-status-bar": "~56.0.4",
|
||||
"react": "19.2.4",
|
||||
"react-native": "0.85.3"
|
||||
"react-native": "0.85.3",
|
||||
"react-native-gesture-handler": "~2.31.1",
|
||||
"react-native-reanimated": "4.3.1",
|
||||
"react-native-safe-area-context": "~5.7.0",
|
||||
"react-native-screens": "4.25.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20",
|
||||
"@types/react": "~19.2.2",
|
||||
"typescript": "~6.0.3"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
{
|
||||
"extends": "expo/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"strict": true
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"types": ["node"],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts"]
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { AlbumView } from "@/components/album-view"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { Metadata } from "next"
|
||||
|
||||
interface PageProps {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import { ArtistView } from "@/components/artist-view"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { Metadata } from "next"
|
||||
|
||||
interface PageProps {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useQuery } from "convex/react"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const albums = useQuery(api.library.browseAlbums)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import { ArtistsView } from "@/components/artists-view"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { Metadata } from "next"
|
||||
|
||||
interface PageProps {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import { ArtistsView } from "@/components/artists-view"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default async function Page() {
|
||||
const artists = await fetchQuery(api.library.browseArtists)
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useQuery } from "convex/react"
|
||||
|
||||
import { ContentCarousel } from "@/components/content-carousel"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { PlaylistView } from "@/components/playlist-view"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { convexAuthNextjsToken } from "@convex-dev/auth/nextjs/server"
|
||||
import { fetchQuery } from "convex/nextjs"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { Metadata } from "next"
|
||||
|
||||
interface PageProps {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useQuery } from "convex/react"
|
||||
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { PlaylistView } from "@/components/playlist-view"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const favorites = useQuery(api.favorites.browseFavoritesPlaylistDetail)
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { PlaylistCard } from "@/components/playlist-card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const playlists = useQuery(api.playlists.listAllPlaylists)
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useQuery } from "convex/react"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const albums = useQuery(api.library.browseRecentlyAdded)
|
||||
|
||||
@@ -5,8 +5,8 @@ import { useQuery } from "convex/react"
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { PlaylistCard } from "@/components/playlist-card"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { BrowseAlbum, PlaylistSummary } from "@/convex/library"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { BrowseAlbum, PlaylistSummary } from "@otunes/convex/types"
|
||||
|
||||
function RecentlyPlayedCard({
|
||||
item,
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ContentCarousel } from "@/components/content-carousel"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { SearchSongItem } from "@/components/search-song-item"
|
||||
import { SearchTopResultCard, type TopResult } from "@/components/search-top-result-card"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
const SEARCH_DEBOUNCE_MS = 300
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { serveCoverFile } from "@/lib/serve-cover"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { serveCoverFile } from "@/lib/serve-cover"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { serveCoverFile } from "@/lib/serve-cover"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { ensureHlsJob, HLS_SEGMENT_SECONDS } from "@/lib/server-hls"
|
||||
import { NextRequest } from "next/server"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { ensureHlsJob, waitForHlsSegment } from "@/lib/server-hls"
|
||||
import { streamFile } from "@/lib/server-audio-stream"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { audioContentTypeForPath } from "@/lib/audio-content-type"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { ffmpegToReadableStream, streamFile } from "@/lib/server-audio-stream"
|
||||
|
||||
@@ -17,8 +17,8 @@ import {
|
||||
} from "@/components/ui/dialog"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
|
||||
function countSongsToAdd(
|
||||
playlistSongIds: Id<"songs">[],
|
||||
|
||||
@@ -14,15 +14,15 @@ import {
|
||||
} from "@/components/media-context-menu"
|
||||
import { usePlayback } from "@/components/playback-provider"
|
||||
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import type { BrowseAlbum } from "@/convex/library"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowseAlbum } from "@otunes/convex/types"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowseAlbumDetail, BrowseAlbumTrack } from "@/convex/library"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseAlbumDetail, BrowseAlbumTrack } from "@otunes/convex/types"
|
||||
import {
|
||||
getSelectionRangePositions,
|
||||
isInSelectionRange,
|
||||
|
||||
@@ -42,7 +42,7 @@ import Link from "next/link"
|
||||
import { useTheme } from "next-themes"
|
||||
import * as React from "react"
|
||||
import { useQuery } from "convex/react"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
const browse = [
|
||||
{ title: "Home", path: "/", icon: House },
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
|
||||
import type { BrowseArtist } from "@/convex/library"
|
||||
import type { BrowseArtist } from "@otunes/convex/types"
|
||||
import { artistCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
export function ArtistCard({ artist }: { artist: BrowseArtist }) {
|
||||
|
||||
@@ -18,9 +18,9 @@ import {
|
||||
} from "@/components/media-context-menu"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowseAlbum, BrowseArtist } from "@/convex/library"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseAlbum, BrowseArtist } from "@otunes/convex/types"
|
||||
import {
|
||||
albumGridCarouselContentClassName,
|
||||
albumGridCarouselSlideClassName,
|
||||
|
||||
@@ -19,10 +19,10 @@ import { usePlayback } from "@/components/playback-provider"
|
||||
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowseAlbum, BrowseArtist } from "@/convex/library"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseAlbum, BrowseArtist } from "@otunes/convex/types"
|
||||
import { artistCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
function ArtistAvatar({ artist }: { artist: BrowseArtist }) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useAuthActions } from "@convex-dev/auth/react"
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
BrowseAlbum,
|
||||
BrowseArtist,
|
||||
PlaylistSummary,
|
||||
} from "@/convex/library"
|
||||
} from "@otunes/convex/types"
|
||||
import {
|
||||
Carousel,
|
||||
CarouselContent,
|
||||
|
||||
@@ -4,8 +4,8 @@ import * as React from "react"
|
||||
import { useMutation, useQuery } from "convex/react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
|
||||
type FavoritesContextValue = {
|
||||
isSongFavorite: (songId: string) => boolean
|
||||
|
||||
@@ -45,8 +45,8 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table"
|
||||
import { usePlayback } from "@/components/playback-provider"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Doc, Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Doc, Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { resizeProfileImageToDataUrl } from "@/lib/resize-profile-image"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ import { useConvex, useMutation, useQuery } from "convex/react"
|
||||
import Hls from "hls.js"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@/convex/library"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { supportsDolbyAtmosPlayback } from "@/lib/dolby-atmos-support"
|
||||
import { songHlsPlaylistUrl, songPlayUrl } from "@/lib/song-play-url"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Link from "next/link"
|
||||
|
||||
import type { BrowseSong } from "@/convex/library"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export function PlaybackSongMeta({
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
|
||||
import type { PlaylistSummary } from "@/convex/library"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { PlaylistSummary } from "@otunes/convex/types"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import { playlistCoverUrl } from "@/lib/cover-urls"
|
||||
import { useConvex } from "convex/react"
|
||||
import { MoreHorizontal, Play } from "lucide-react"
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
|
||||
export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
|
||||
const convex = useConvex()
|
||||
|
||||
@@ -24,9 +24,9 @@ import {
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowsePlaylistDetail, BrowseSong } from "@/convex/library"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowsePlaylistDetail, BrowseSong } from "@otunes/convex/types"
|
||||
import { albumCoverUrl, playlistCoverUrl } from "@/lib/cover-urls"
|
||||
import { copyPlaylistLink } from "@/lib/media-links"
|
||||
import { sumDurationSeconds } from "@/lib/media-summary"
|
||||
|
||||
@@ -12,9 +12,9 @@ import { Button } from "@/components/ui/button"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { Spinner } from "@/components/ui/spinner"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { HistorySong, QueueSong } from "@/convex/playback"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { HistorySong, QueueSong } from "@otunes/convex/types"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
import {
|
||||
getContiguousSelectedIndices,
|
||||
|
||||
@@ -9,8 +9,8 @@ import {
|
||||
MediaContextMenu,
|
||||
type MediaContextAction,
|
||||
} from "@/components/media-context-menu"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@/convex/library"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
export function SearchSongItem({ song }: { song: BrowseSong }) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
|
||||
import type { SearchTopResultItem } from "@/convex/library"
|
||||
import type { SearchTopResultItem } from "@otunes/convex/types"
|
||||
import { albumCoverUrl, artistCoverUrl } from "@/lib/cover-urls"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { Spinner } from "@/components/ui/spinner"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -38,8 +38,8 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@/convex/library"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
import {
|
||||
getSelectionRangePositions,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { toast } from "sonner"
|
||||
|
||||
import { usePlayback } from "@/components/playback-provider"
|
||||
import type { MediaContextAction } from "@/components/media-context-menu"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
|
||||
export type QueueMediaAction = Extract<
|
||||
MediaContextAction,
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
BrowsePlaylistOwner,
|
||||
BrowseSong,
|
||||
PlaylistSummary,
|
||||
} from "@/convex/library"
|
||||
} from "@otunes/convex/types"
|
||||
|
||||
export type Artist = BrowseArtist
|
||||
export type Album = BrowseAlbum
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Doc } from "@/convex/_generated/dataModel"
|
||||
import type { Doc } from "@otunes/convex/_generated/dataModel"
|
||||
import crypto from "node:crypto"
|
||||
import fs from "node:fs/promises"
|
||||
import os from "node:os"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"@auth/core": "^0.37.0",
|
||||
"@base-ui/react": "^1.5.0",
|
||||
"@convex-dev/auth": "^0.0.93",
|
||||
"@otunes/convex": "workspace:*",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.1.1",
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"dev": "pnpm --filter @otunes/web dev",
|
||||
"dev:web": "pnpm --filter @otunes/web dev",
|
||||
"dev:mobile": "pnpm --filter @otunes/mobile start",
|
||||
"dev:convex": "pnpm --filter @otunes/convex dev",
|
||||
"build": "pnpm --filter @otunes/web build",
|
||||
"build:web": "pnpm --filter @otunes/web build",
|
||||
"start": "pnpm --filter @otunes/web start",
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/get-convex/convex-backend/refs/heads/main/npm/convex/schemas/convex.schema.json"
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
Vendored
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 114 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user