From 73c7283d4d166bddd71638e42ddbcbe9bc693a39 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sun, 14 Jun 2026 19:44:53 -0400 Subject: [PATCH] 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 --- README.md | 7 + apps/mobile/App.tsx | 30 - apps/mobile/app.json | 27 +- apps/mobile/app/(app)/(tabs)/_layout.tsx | 68 + apps/mobile/app/(app)/(tabs)/index.tsx | 55 + apps/mobile/app/(app)/(tabs)/library.tsx | 67 + apps/mobile/app/(app)/(tabs)/more.tsx | 137 ++ apps/mobile/app/(app)/(tabs)/playlists.tsx | 48 + apps/mobile/app/(app)/(tabs)/search.tsx | 127 ++ apps/mobile/app/(app)/_layout.tsx | 40 + apps/mobile/app/(app)/album/[id].tsx | 180 +++ apps/mobile/app/(app)/artist/[id].tsx | 147 +++ apps/mobile/app/(app)/library/albums.tsx | 39 + apps/mobile/app/(app)/library/artists.tsx | 66 + apps/mobile/app/(app)/library/songs.tsx | 136 ++ apps/mobile/app/(app)/playlist/[id].tsx | 202 +++ apps/mobile/app/(app)/playlist/favorites.tsx | 115 ++ apps/mobile/app/(app)/queue.tsx | 133 ++ apps/mobile/app/(app)/recently-added.tsx | 33 + apps/mobile/app/(app)/recently-played.tsx | 33 + apps/mobile/app/(app)/settings.tsx | 395 ++++++ apps/mobile/app/(auth)/_layout.tsx | 5 + apps/mobile/app/(auth)/signin.tsx | 5 + apps/mobile/app/(auth)/signup.tsx | 5 + apps/mobile/app/_layout.tsx | 22 + apps/mobile/app/index.tsx | 28 + apps/mobile/app/server.tsx | 80 ++ apps/mobile/babel.config.js | 7 + apps/mobile/components/auth-form.tsx | 185 +++ .../mobile/components/media-actions-sheet.tsx | 111 ++ apps/mobile/components/media-cards.tsx | 151 +++ apps/mobile/components/player.tsx | 270 ++++ apps/mobile/components/screen-header.tsx | 34 + apps/mobile/components/ui/primitives.tsx | 140 ++ apps/mobile/contexts/add-to-playlist.tsx | 250 ++++ apps/mobile/contexts/convex-app.tsx | 29 + apps/mobile/contexts/favorites.tsx | 123 ++ apps/mobile/contexts/playback.tsx | 521 ++++++++ apps/mobile/contexts/server-config.tsx | 80 ++ apps/mobile/index.ts | 8 - apps/mobile/lib/auth-storage.ts | 14 + apps/mobile/lib/format.ts | 30 + apps/mobile/lib/server-config.ts | 84 ++ apps/mobile/lib/shuffle-array.ts | 8 + apps/mobile/lib/theme.ts | 53 + apps/mobile/lib/toast.ts | 13 + apps/mobile/lib/urls.ts | 39 + apps/mobile/metro.config.js | 15 + apps/mobile/package.json | 22 +- apps/mobile/tsconfig.json | 10 +- apps/web/app/(app)/album/[id]/page.tsx | 4 +- apps/web/app/(app)/artist/[id]/page.tsx | 4 +- apps/web/app/(app)/library/albums/page.tsx | 2 +- .../app/(app)/library/artists/[id]/page.tsx | 2 +- apps/web/app/(app)/library/artists/page.tsx | 2 +- apps/web/app/(app)/page.tsx | 2 +- apps/web/app/(app)/playlist/[id]/page.tsx | 4 +- .../web/app/(app)/playlist/favorites/page.tsx | 2 +- apps/web/app/(app)/playlists/page.tsx | 2 +- apps/web/app/(app)/recently-added/page.tsx | 2 +- apps/web/app/(app)/recently-played/page.tsx | 4 +- apps/web/app/(app)/search/page.tsx | 2 +- apps/web/app/api/album/[id]/cover/route.ts | 4 +- apps/web/app/api/artist/[id]/cover/route.ts | 4 +- apps/web/app/api/playlist/[id]/cover/route.ts | 4 +- apps/web/app/api/song/[id]/play/hls/route.ts | 4 +- .../[id]/play/hls/segment/[segment]/route.ts | 4 +- apps/web/app/api/song/[id]/play/route.ts | 4 +- .../components/add-to-playlist-provider.tsx | 4 +- apps/web/components/album-card.tsx | 6 +- apps/web/components/album-view.tsx | 4 +- apps/web/components/app-sidebar.tsx | 2 +- apps/web/components/artist-card.tsx | 2 +- apps/web/components/artist-view.tsx | 6 +- apps/web/components/artists-view.tsx | 6 +- apps/web/components/auth-form.tsx | 2 +- apps/web/components/content-carousel.tsx | 2 +- apps/web/components/favorites-provider.tsx | 4 +- apps/web/components/options-modal.tsx | 4 +- apps/web/components/playback-provider.tsx | 6 +- apps/web/components/playback-song-meta.tsx | 2 +- apps/web/components/playlist-card.tsx | 6 +- apps/web/components/playlist-view.tsx | 6 +- apps/web/components/queue-panel.tsx | 6 +- apps/web/components/search-song-item.tsx | 4 +- .../web/components/search-top-result-card.tsx | 2 +- apps/web/components/songs-view.tsx | 6 +- apps/web/hooks/use-queue-media-actions.ts | 2 +- apps/web/lib/data.ts | 2 +- apps/web/lib/server-hls.ts | 2 +- apps/web/package.json | 1 + package.json | 1 + packages/convex/convex.json | 3 + .../convex}/convex/_generated/api.d.ts | 0 .../convex}/convex/_generated/api.js | 0 .../convex}/convex/_generated/dataModel.d.ts | 0 .../convex}/convex/_generated/server.d.ts | 0 .../convex}/convex/_generated/server.js | 0 .../web => packages/convex}/convex/actions.ts | 0 .../convex}/convex/auth.config.ts | 0 {apps/web => packages/convex}/convex/auth.ts | 0 {apps/web => packages/convex}/convex/crons.ts | 0 .../convex}/convex/favorites.ts | 0 {apps/web => packages/convex}/convex/http.ts | 0 .../web => packages/convex}/convex/library.ts | 119 +- .../convex}/convex/playback.ts | 5 +- .../convex}/convex/playlists.ts | 0 .../web => packages/convex}/convex/schema.ts | 0 .../convex}/convex/tsconfig.json | 0 packages/convex/convex/types.ts | 94 ++ {apps/web => packages/convex}/convex/users.ts | 0 packages/convex/package.json | 35 + pnpm-lock.yaml | 1127 +++++++++++++++-- pnpm-workspace.yaml | 1 + 114 files changed, 5660 insertions(+), 295 deletions(-) delete mode 100644 apps/mobile/App.tsx create mode 100644 apps/mobile/app/(app)/(tabs)/_layout.tsx create mode 100644 apps/mobile/app/(app)/(tabs)/index.tsx create mode 100644 apps/mobile/app/(app)/(tabs)/library.tsx create mode 100644 apps/mobile/app/(app)/(tabs)/more.tsx create mode 100644 apps/mobile/app/(app)/(tabs)/playlists.tsx create mode 100644 apps/mobile/app/(app)/(tabs)/search.tsx create mode 100644 apps/mobile/app/(app)/_layout.tsx create mode 100644 apps/mobile/app/(app)/album/[id].tsx create mode 100644 apps/mobile/app/(app)/artist/[id].tsx create mode 100644 apps/mobile/app/(app)/library/albums.tsx create mode 100644 apps/mobile/app/(app)/library/artists.tsx create mode 100644 apps/mobile/app/(app)/library/songs.tsx create mode 100644 apps/mobile/app/(app)/playlist/[id].tsx create mode 100644 apps/mobile/app/(app)/playlist/favorites.tsx create mode 100644 apps/mobile/app/(app)/queue.tsx create mode 100644 apps/mobile/app/(app)/recently-added.tsx create mode 100644 apps/mobile/app/(app)/recently-played.tsx create mode 100644 apps/mobile/app/(app)/settings.tsx create mode 100644 apps/mobile/app/(auth)/_layout.tsx create mode 100644 apps/mobile/app/(auth)/signin.tsx create mode 100644 apps/mobile/app/(auth)/signup.tsx create mode 100644 apps/mobile/app/_layout.tsx create mode 100644 apps/mobile/app/index.tsx create mode 100644 apps/mobile/app/server.tsx create mode 100644 apps/mobile/babel.config.js create mode 100644 apps/mobile/components/auth-form.tsx create mode 100644 apps/mobile/components/media-actions-sheet.tsx create mode 100644 apps/mobile/components/media-cards.tsx create mode 100644 apps/mobile/components/player.tsx create mode 100644 apps/mobile/components/screen-header.tsx create mode 100644 apps/mobile/components/ui/primitives.tsx create mode 100644 apps/mobile/contexts/add-to-playlist.tsx create mode 100644 apps/mobile/contexts/convex-app.tsx create mode 100644 apps/mobile/contexts/favorites.tsx create mode 100644 apps/mobile/contexts/playback.tsx create mode 100644 apps/mobile/contexts/server-config.tsx delete mode 100644 apps/mobile/index.ts create mode 100644 apps/mobile/lib/auth-storage.ts create mode 100644 apps/mobile/lib/format.ts create mode 100644 apps/mobile/lib/server-config.ts create mode 100644 apps/mobile/lib/shuffle-array.ts create mode 100644 apps/mobile/lib/theme.ts create mode 100644 apps/mobile/lib/toast.ts create mode 100644 apps/mobile/lib/urls.ts create mode 100644 apps/mobile/metro.config.js create mode 100644 packages/convex/convex.json rename {apps/web => packages/convex}/convex/_generated/api.d.ts (100%) rename {apps/web => packages/convex}/convex/_generated/api.js (100%) rename {apps/web => packages/convex}/convex/_generated/dataModel.d.ts (100%) rename {apps/web => packages/convex}/convex/_generated/server.d.ts (100%) rename {apps/web => packages/convex}/convex/_generated/server.js (100%) rename {apps/web => packages/convex}/convex/actions.ts (100%) rename {apps/web => packages/convex}/convex/auth.config.ts (100%) rename {apps/web => packages/convex}/convex/auth.ts (100%) rename {apps/web => packages/convex}/convex/crons.ts (100%) rename {apps/web => packages/convex}/convex/favorites.ts (100%) rename {apps/web => packages/convex}/convex/http.ts (100%) rename {apps/web => packages/convex}/convex/library.ts (93%) rename {apps/web => packages/convex}/convex/playback.ts (99%) rename {apps/web => packages/convex}/convex/playlists.ts (100%) rename {apps/web => packages/convex}/convex/schema.ts (100%) rename {apps/web => packages/convex}/convex/tsconfig.json (100%) create mode 100644 packages/convex/convex/types.ts rename {apps/web => packages/convex}/convex/users.ts (100%) create mode 100644 packages/convex/package.json diff --git a/README.md b/README.md index 4f2b6df..18eb6e3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/apps/mobile/App.tsx b/apps/mobile/App.tsx deleted file mode 100644 index 591fa9b..0000000 --- a/apps/mobile/App.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { StatusBar } from "expo-status-bar" -import { StyleSheet, Text, View } from "react-native" - -export default function App() { - return ( - - oTunes - Mobile app coming soon - - - ) -} - -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", - }, -}) diff --git a/apps/mobile/app.json b/apps/mobile/app.json index 70e533c..0dd12f4 100644 --- a/apps/mobile/app.json +++ b/apps/mobile/app.json @@ -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 } } } diff --git a/apps/mobile/app/(app)/(tabs)/_layout.tsx b/apps/mobile/app/(app)/(tabs)/_layout.tsx new file mode 100644 index 0000000..daf3aa3 --- /dev/null +++ b/apps/mobile/app/(app)/(tabs)/_layout.tsx @@ -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 ( + + ( + + ), + }} + /> + ( + + ), + }} + /> + ( + + ), + }} + /> + ( + + ), + }} + /> + ( + + ), + }} + /> + + ) +} diff --git a/apps/mobile/app/(app)/(tabs)/index.tsx b/apps/mobile/app/(app)/(tabs)/index.tsx new file mode 100644 index 0000000..bd93a04 --- /dev/null +++ b/apps/mobile/app/(app)/(tabs)/index.tsx @@ -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 ( + + + + + ) + } + + return ( + + + + {recentlyPlayed.length > 0 ? ( + + ) : null} + + + + ) +} + +const styles = StyleSheet.create({ + safe: { flex: 1 }, + content: { + padding: spacing.lg, + gap: spacing.xl, + }, +}) diff --git a/apps/mobile/app/(app)/(tabs)/library.tsx b/apps/mobile/app/(app)/(tabs)/library.tsx new file mode 100644 index 0000000..696b91b --- /dev/null +++ b/apps/mobile/app/(app)/(tabs)/library.tsx @@ -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 ( + + + + {links.map((link) => ( + router.push(link.href as never)} + > + + + + {link.title} + + + ))} + + + ) +} + +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", + }, +}) diff --git a/apps/mobile/app/(app)/(tabs)/more.tsx b/apps/mobile/app/(app)/(tabs)/more.tsx new file mode 100644 index 0000000..2eb2cee --- /dev/null +++ b/apps/mobile/app/(app)/(tabs)/more.tsx @@ -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 ( + + + + + + + {initialsFromName(user?.name ?? "NA")} + + + + {user?.name ?? "..."} + {user?.email} + + + + router.push("/settings")}> + + Settings + + router.push("/queue")}> + + Queue + + + {owned.length > 0 ? ( + Your playlists + ) : null} + {owned.map((playlist: PlaylistSummary) => ( + router.push(`/playlist/${playlist.id}`)} + > + + {playlist.title} + + ))} + + {subscribed.length > 0 ? ( + Subscribed + ) : null} + {subscribed.map((playlist: PlaylistSummary) => ( + router.push(`/playlist/${playlist.id}`)} + > + + {playlist.title} + + ))} + + void handleSignOut()}> + + Sign out + + void handleChangeServer()}> + + Change server + + + + ) +} + +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", + }, +}) diff --git a/apps/mobile/app/(app)/(tabs)/playlists.tsx b/apps/mobile/app/(app)/(tabs)/playlists.tsx new file mode 100644 index 0000000..415f00a --- /dev/null +++ b/apps/mobile/app/(app)/(tabs)/playlists.tsx @@ -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 ( + + } + /> + {playlists === undefined ? ( + + ) : ( + + + {playlists.map((playlist: PlaylistSummary) => ( + + ))} + + + )} + + ) +} + +const styles = StyleSheet.create({ + safe: { flex: 1 }, + content: { padding: spacing.lg }, + grid: { + flexDirection: "row", + flexWrap: "wrap", + gap: spacing.lg, + }, +}) diff --git a/apps/mobile/app/(app)/(tabs)/search.tsx b/apps/mobile/app/(app)/(tabs)/search.tsx new file mode 100644 index 0000000..6fe2f3a --- /dev/null +++ b/apps/mobile/app/(app)/(tabs)/search.tsx @@ -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 | 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 ( + + + + setSearchQuery(query.trim())} + /> + + + {isSearching ? ( + + ) : !hasQuery ? ( + + + + ) : ( + + {!hasLibraryResults ? ( + + + + ) : null} + + {results?.artists.length ? ( + + + + ) : null} + + {results?.albums.length ? ( + + + + ) : null} + + {results?.songs.length ? ( + + {results.songs.map((song: BrowseSong) => ( + + void playFromSong( + song.id, + results.songs.map((s: BrowseSong) => s.id) + ) + } + /> + ))} + + ) : null} + + {playlistResults && playlistResults.length > 0 ? ( + + + + ) : null} + + )} + + ) +} + +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 }, +}) diff --git a/apps/mobile/app/(app)/_layout.tsx b/apps/mobile/app/(app)/_layout.tsx new file mode 100644 index 0000000..e31307f --- /dev/null +++ b/apps/mobile/app/(app)/_layout.tsx @@ -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 + } + + if (isLoading) { + return + } + + if (!isAuthenticated) { + return + } + + return ( + + + + + + + + + + + ) +} diff --git a/apps/mobile/app/(app)/album/[id].tsx b/apps/mobile/app/(app)/album/[id].tsx new file mode 100644 index 0000000..bece4a1 --- /dev/null +++ b/apps/mobile/app/(app)/album/[id].tsx @@ -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 ( + + + + + ) + } + + if (album === null) { + return ( + + + + Album not found. + + + ) + } + + 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 ( + + setActionsOpen(true)} hitSlop={8}> + + + } + /> + + + + {album.title} + router.push(`/artist/${album.artist.id}`)}> + {album.artist.name} + + {metadata ? ( + {metadata} + ) : null} + +