diff --git a/apps/mobile/app/(app)/(tabs)/_layout.tsx b/apps/mobile/app/(app)/(tabs)/_layout.tsx
index bd5f1ae..6bca97e 100644
--- a/apps/mobile/app/(app)/(tabs)/_layout.tsx
+++ b/apps/mobile/app/(app)/(tabs)/_layout.tsx
@@ -96,15 +96,7 @@ export default function TabsLayout() {
Library
-
-
- Playlists
-
-
-
+
Search
diff --git a/apps/mobile/app/(app)/(tabs)/home/_layout.tsx b/apps/mobile/app/(app)/(tabs)/home/_layout.tsx
index 8d84403..438f058 100644
--- a/apps/mobile/app/(app)/(tabs)/home/_layout.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/_layout.tsx
@@ -1,7 +1,21 @@
import { Stack } from "expo-router"
-import { useStackScreenOptions } from "@/lib/navigation"
+import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
+
+export const unstable_settings = {
+ initialRouteName: "index",
+}
export default function HomeLayout() {
- return
+ const baseOptions = useStackScreenOptions({ title: "Home" })
+
+ return (
+ ({
+ ...baseOptions,
+ title: tabStackScreenTitles[route.name] ?? "Home",
+ })}
+ />
+ )
}
diff --git a/apps/mobile/app/(app)/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx
similarity index 94%
rename from apps/mobile/app/(app)/album/[id].tsx
rename to apps/mobile/app/(app)/(tabs)/home/album/[id].tsx
index e585698..d4159c8 100644
--- a/apps/mobile/app/(app)/album/[id].tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx
@@ -1,6 +1,6 @@
import { useQuery } from "convex/react"
import { Image } from "expo-image"
-import { Stack, useLocalSearchParams, useRouter } from "expo-router"
+import { Stack, useLocalSearchParams } from "expo-router"
import { useState } from "react"
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
import { Ionicons } from "@expo/vector-icons"
@@ -16,15 +16,19 @@ 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 { useAppNavigation } from "@/lib/app-navigation"
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 { push } = useAppNavigation()
const colors = useThemeColors()
const { config } = useServerConfig()
- const album = useQuery(api.library.browseAlbumDetail, { id: id as Id<"albums"> })
+ const album = useQuery(
+ api.library.browseAlbumDetail,
+ typeof id === "string" ? { id: id as Id<"albums"> } : "skip"
+ )
const { playAlbum, playAlbumShuffled, playFromSong } = usePlayback()
const { isAlbumFavorite, toggleAlbumFavorite } = useFavorites()
const { openAddAlbumToPlaylist } = useAddToPlaylist()
@@ -84,7 +88,7 @@ export default function AlbumScreen() {
contentFit="cover"
/>
{album.title}
- router.push(`/artist/${album.artist.id}`)}>
+ push(`/artist/${album.artist.id}`)}>
{album.artist.name}
{metadata ? (
diff --git a/apps/mobile/app/(app)/artist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/artist/[id].tsx
similarity index 100%
rename from apps/mobile/app/(app)/artist/[id].tsx
rename to apps/mobile/app/(app)/(tabs)/home/artist/[id].tsx
diff --git a/apps/mobile/app/(app)/library/albums.tsx b/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx
similarity index 100%
rename from apps/mobile/app/(app)/library/albums.tsx
rename to apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx
diff --git a/apps/mobile/app/(app)/library/artists.tsx b/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
similarity index 92%
rename from apps/mobile/app/(app)/library/artists.tsx
rename to apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
index 9a86866..e46ab8c 100644
--- a/apps/mobile/app/(app)/library/artists.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
@@ -1,18 +1,18 @@
import { useQuery } from "convex/react"
-import { useRouter } from "expo-router"
import { Pressable, ScrollView, StyleSheet, Text } from "react-native"
import { Image } from "expo-image"
import { LoadingView } from "@/components/ui/primitives"
import { contentBottomInset } from "@/components/player"
import { useServerConfig } from "@/contexts/server-config"
+import { useAppNavigation } from "@/lib/app-navigation"
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 { push } = useAppNavigation()
const colors = useThemeColors()
const { config } = useServerConfig()
const artists = useQuery(api.library.browseArtists)
@@ -31,7 +31,7 @@ export default function ArtistsScreen() {
router.push(`/artist/${artist.id}`)}
+ onPress={() => push(`/artist/${artist.id}`)}
>
(
setMenuOpen(true)} hitSlop={8}>
diff --git a/apps/mobile/app/(app)/playlist/favorites.tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/favorites.tsx
similarity index 87%
rename from apps/mobile/app/(app)/playlist/favorites.tsx
rename to apps/mobile/app/(app)/(tabs)/home/playlist/favorites.tsx
index 5bc42c8..c6f33d9 100644
--- a/apps/mobile/app/(app)/playlist/favorites.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/playlist/favorites.tsx
@@ -1,7 +1,7 @@
import { useQuery } from "convex/react"
import { Image } from "expo-image"
import { useState } from "react"
-import { ScrollView, StyleSheet, Text, View } from "react-native"
+import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
import { MediaActionsSheet, type MediaAction } from "@/components/media-actions-sheet"
import { Button, LoadingView } from "@/components/ui/primitives"
@@ -14,6 +14,8 @@ 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"
+import { Ionicons } from "@expo/vector-icons"
+import { Stack } from "expo-router"
export default function FavoritesScreen() {
const colors = useThemeColors()
@@ -54,6 +56,12 @@ export default function FavoritesScreen() {
return (
<>
+
- {favorites.title}
+
+ {favorites.title}
+
diff --git a/apps/mobile/app/(app)/queue.tsx b/apps/mobile/app/(app)/(tabs)/home/queue.tsx
similarity index 100%
rename from apps/mobile/app/(app)/queue.tsx
rename to apps/mobile/app/(app)/(tabs)/home/queue.tsx
diff --git a/apps/mobile/app/(app)/recently-added.tsx b/apps/mobile/app/(app)/(tabs)/home/recently-added.tsx
similarity index 100%
rename from apps/mobile/app/(app)/recently-added.tsx
rename to apps/mobile/app/(app)/(tabs)/home/recently-added.tsx
diff --git a/apps/mobile/app/(app)/recently-played.tsx b/apps/mobile/app/(app)/(tabs)/home/recently-played.tsx
similarity index 100%
rename from apps/mobile/app/(app)/recently-played.tsx
rename to apps/mobile/app/(app)/(tabs)/home/recently-played.tsx
diff --git a/apps/mobile/app/(app)/settings.tsx b/apps/mobile/app/(app)/(tabs)/home/settings.tsx
similarity index 100%
rename from apps/mobile/app/(app)/settings.tsx
rename to apps/mobile/app/(app)/(tabs)/home/settings.tsx
diff --git a/apps/mobile/app/(app)/(tabs)/library/_layout.tsx b/apps/mobile/app/(app)/(tabs)/library/_layout.tsx
index 98a5d70..ad3b27c 100644
--- a/apps/mobile/app/(app)/(tabs)/library/_layout.tsx
+++ b/apps/mobile/app/(app)/(tabs)/library/_layout.tsx
@@ -1,7 +1,21 @@
import { Stack } from "expo-router"
-import { useStackScreenOptions } from "@/lib/navigation"
+import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
+
+export const unstable_settings = {
+ initialRouteName: "index",
+}
export default function LibraryLayout() {
- return
+ const baseOptions = useStackScreenOptions({ title: "Library" })
+
+ return (
+ ({
+ ...baseOptions,
+ title: tabStackScreenTitles[route.name] ?? "Library",
+ })}
+ />
+ )
}
diff --git a/apps/mobile/app/(app)/(tabs)/library/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/library/album/[id].tsx
new file mode 100644
index 0000000..33706bf
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/album/[id].tsx
@@ -0,0 +1 @@
+export { default } from "../../home/album/[id]"
diff --git a/apps/mobile/app/(app)/(tabs)/library/artist/[id].tsx b/apps/mobile/app/(app)/(tabs)/library/artist/[id].tsx
new file mode 100644
index 0000000..1320cde
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/artist/[id].tsx
@@ -0,0 +1 @@
+export { default } from "../../home/artist/[id]"
diff --git a/apps/mobile/app/(app)/(tabs)/library/browse/albums.tsx b/apps/mobile/app/(app)/(tabs)/library/browse/albums.tsx
new file mode 100644
index 0000000..12ead6e
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/browse/albums.tsx
@@ -0,0 +1 @@
+export { default } from "../../home/browse/albums"
diff --git a/apps/mobile/app/(app)/(tabs)/library/browse/artists.tsx b/apps/mobile/app/(app)/(tabs)/library/browse/artists.tsx
new file mode 100644
index 0000000..70e0ed0
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/browse/artists.tsx
@@ -0,0 +1 @@
+export { default } from "../../home/browse/artists"
diff --git a/apps/mobile/app/(app)/(tabs)/library/browse/songs.tsx b/apps/mobile/app/(app)/(tabs)/library/browse/songs.tsx
new file mode 100644
index 0000000..a7493e6
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/browse/songs.tsx
@@ -0,0 +1 @@
+export { default } from "../../home/browse/songs"
diff --git a/apps/mobile/app/(app)/(tabs)/library/index.tsx b/apps/mobile/app/(app)/(tabs)/library/index.tsx
index e7d63fe..d5fe525 100644
--- a/apps/mobile/app/(app)/(tabs)/library/index.tsx
+++ b/apps/mobile/app/(app)/(tabs)/library/index.tsx
@@ -1,5 +1,4 @@
import { useQuery } from "convex/react"
-import { useRouter } from "expo-router"
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
import { SymbolView } from "expo-symbols"
import { Platform } from "react-native"
@@ -8,16 +7,16 @@ import { Ionicons } from "@expo/vector-icons"
import { MediaGrid } from "@/components/media-cards"
import { tabContentBottomInset } from "@/components/player"
import { LoadingView } from "@/components/ui/primitives"
+import { useAppNavigation } from "@/lib/app-navigation"
import { api } from "@otunes/convex/_generated/api"
import { appleMusic, spacing, useThemeColors } from "@/lib/theme"
const links = [
- { title: "Playlists", href: "/(app)/(tabs)/playlists", icon: "music.note.list" as const },
- { title: "Artists", href: "/library/artists", icon: "mic.fill" as const },
- { title: "Albums", href: "/library/albums", icon: "square.stack" as const },
- { title: "Songs", href: "/library/songs", icon: "music.note" as const },
+ { title: "Playlists", href: "/playlists", icon: "music.note.list" as const },
+ { title: "Artists", href: "/browse/artists", icon: "mic.fill" as const },
+ { title: "Albums", href: "/browse/albums", icon: "square.stack" as const },
+ { title: "Songs", href: "/browse/songs", icon: "music.note" as const },
{ title: "Recently Played", href: "/recently-played", icon: "clock" as const },
- { title: "Recently Added", href: "/recently-added", icon: "sparkles" as const },
{ title: "Favorites", href: "/playlist/favorites", icon: "star" as const },
]
@@ -45,7 +44,7 @@ function LibraryIcon({ name }: { name: (typeof links)[number]["icon"] }) {
}
export default function LibraryScreen() {
- const router = useRouter()
+ const { push } = useAppNavigation()
const colors = useThemeColors()
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
@@ -59,7 +58,7 @@ export default function LibraryScreen() {
router.push(link.href as never)}
+ onPress={() => push(link.href)}
>
{link.title}
@@ -68,7 +67,7 @@ export default function LibraryScreen() {
))}
- router.push("/recently-added")}>
+ push("/recently-added")}>
Recently Added
diff --git a/apps/mobile/app/(app)/(tabs)/library/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/library/playlist/[id].tsx
new file mode 100644
index 0000000..5d2b1ec
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/playlist/[id].tsx
@@ -0,0 +1 @@
+export { default } from "../../home/playlist/[id]"
diff --git a/apps/mobile/app/(app)/(tabs)/library/playlist/favorites.tsx b/apps/mobile/app/(app)/(tabs)/library/playlist/favorites.tsx
new file mode 100644
index 0000000..aab2512
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/playlist/favorites.tsx
@@ -0,0 +1 @@
+export { default } from "../../home/playlist/favorites"
diff --git a/apps/mobile/app/(app)/(tabs)/library/playlists/index.tsx b/apps/mobile/app/(app)/(tabs)/library/playlists/index.tsx
new file mode 100644
index 0000000..04c6b64
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/playlists/index.tsx
@@ -0,0 +1,56 @@
+import { useQuery } from "convex/react"
+import { Pressable, ScrollView, StyleSheet } from "react-native"
+
+import { MediaGrid } from "@/components/media-cards"
+import { LoadingView } from "@/components/ui/primitives"
+import { tabContentBottomInset } from "@/components/player"
+import { api } from "@otunes/convex/_generated/api"
+import { spacing, useThemeColors } from "@/lib/theme"
+import { Ionicons } from "@expo/vector-icons"
+import { Stack } from "expo-router"
+import { SymbolView } from "expo-symbols"
+import { useAddToPlaylist } from "@/contexts/add-to-playlist"
+
+export default function PlaylistsTabScreen() {
+ const colors = useThemeColors()
+ const playlists = useQuery(api.playlists.listAllPlaylists)
+ const { openCreatePlaylist } = useAddToPlaylist()
+
+ if (playlists === undefined) {
+ return
+ }
+
+ return (
+ <>
+ (
+
+
+
+ ),
+ }}
+ />
+
+
+
+ >
+ )
+}
+
+const styles = StyleSheet.create({
+ content: { padding: spacing.lg },
+})
diff --git a/apps/mobile/app/(app)/(tabs)/library/queue.tsx b/apps/mobile/app/(app)/(tabs)/library/queue.tsx
new file mode 100644
index 0000000..ea0fd22
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/queue.tsx
@@ -0,0 +1 @@
+export { default } from "../home/queue"
diff --git a/apps/mobile/app/(app)/(tabs)/library/recently-added.tsx b/apps/mobile/app/(app)/(tabs)/library/recently-added.tsx
new file mode 100644
index 0000000..2a67054
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/recently-added.tsx
@@ -0,0 +1 @@
+export { default } from "../home/recently-added"
diff --git a/apps/mobile/app/(app)/(tabs)/library/recently-played.tsx b/apps/mobile/app/(app)/(tabs)/library/recently-played.tsx
new file mode 100644
index 0000000..ce9f8f8
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/recently-played.tsx
@@ -0,0 +1 @@
+export { default } from "../home/recently-played"
diff --git a/apps/mobile/app/(app)/(tabs)/library/settings.tsx b/apps/mobile/app/(app)/(tabs)/library/settings.tsx
new file mode 100644
index 0000000..5228f63
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/library/settings.tsx
@@ -0,0 +1 @@
+export { default } from "../home/settings"
diff --git a/apps/mobile/app/(app)/(tabs)/more/index.tsx b/apps/mobile/app/(app)/(tabs)/more/index.tsx
index 6501bf2..14b55a0 100644
--- a/apps/mobile/app/(app)/(tabs)/more/index.tsx
+++ b/apps/mobile/app/(app)/(tabs)/more/index.tsx
@@ -1,11 +1,12 @@
-import { useAuthActions } from "@convex-dev/auth/react"
import { useQuery } from "convex/react"
import { useRouter } from "expo-router"
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
import { Ionicons } from "@expo/vector-icons"
import { tabContentBottomInset } from "@/components/player"
+import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
import { useServerConfig } from "@/contexts/server-config"
+import { useAppNavigation } from "@/lib/app-navigation"
import { signOutToSignIn } from "@/lib/session"
import { api } from "@otunes/convex/_generated/api"
import type { PlaylistSummary } from "@otunes/convex/types"
@@ -14,18 +15,19 @@ import { radius, spacing, useThemeColors } from "@/lib/theme"
export default function MoreScreen() {
const router = useRouter()
+ const { push } = useAppNavigation()
const colors = useThemeColors()
- const { signOut } = useAuthActions()
+ const { invalidateSession } = useInvalidateAuthSession()
const { clearServer } = useServerConfig()
const user = useQuery(api.auth.currentUser)
const sidebarPlaylists = useQuery(api.playlists.listSidebarPlaylists)
async function handleSignOut() {
- await signOutToSignIn(signOut, router)
+ await signOutToSignIn(router, invalidateSession)
}
async function handleChangeServer() {
- await signOut()
+ await invalidateSession()
await clearServer()
router.replace("/server")
}
@@ -51,11 +53,11 @@ export default function MoreScreen() {
- router.push("/settings")}>
+ push("/settings")}>
Settings
- router.push("/queue")}>
+ push("/queue")}>
Queue
@@ -67,7 +69,7 @@ export default function MoreScreen() {
router.push(`/playlist/${playlist.id}`)}
+ onPress={() => push(`/playlist/${playlist.id}`)}
>
{playlist.title}
@@ -81,7 +83,7 @@ export default function MoreScreen() {
router.push(`/playlist/${playlist.id}`)}
+ onPress={() => push(`/playlist/${playlist.id}`)}
>
{playlist.title}
diff --git a/apps/mobile/app/(app)/(tabs)/playlists/_layout.tsx b/apps/mobile/app/(app)/(tabs)/playlists/_layout.tsx
deleted file mode 100644
index 47fff99..0000000
--- a/apps/mobile/app/(app)/(tabs)/playlists/_layout.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import { Stack } from "expo-router"
-import { Pressable, Text } from "react-native"
-
-import { useAddToPlaylist } from "@/contexts/add-to-playlist"
-import { useStackScreenOptions } from "@/lib/navigation"
-import { appleMusic } from "@/lib/theme"
-
-function NewPlaylistButton() {
- const { openCreatePlaylist } = useAddToPlaylist()
-
- return (
-
-
- New
-
-
- )
-}
-
-export default function PlaylistsLayout() {
- return (
- ,
- })}
- />
- )
-}
diff --git a/apps/mobile/app/(app)/(tabs)/playlists/index.tsx b/apps/mobile/app/(app)/(tabs)/playlists/index.tsx
deleted file mode 100644
index b15e374..0000000
--- a/apps/mobile/app/(app)/(tabs)/playlists/index.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import { useQuery } from "convex/react"
-import { ScrollView, StyleSheet } from "react-native"
-
-import { MediaGrid } from "@/components/media-cards"
-import { LoadingView } from "@/components/ui/primitives"
-import { tabContentBottomInset } from "@/components/player"
-import { api } from "@otunes/convex/_generated/api"
-import { spacing, useThemeColors } from "@/lib/theme"
-
-export default function PlaylistsTabScreen() {
- const colors = useThemeColors()
- const playlists = useQuery(api.playlists.listAllPlaylists)
-
- if (playlists === undefined) {
- return
- }
-
- return (
-
-
-
- )
-}
-
-const styles = StyleSheet.create({
- content: { padding: spacing.lg },
-})
diff --git a/apps/mobile/app/(app)/(tabs)/search/_layout.tsx b/apps/mobile/app/(app)/(tabs)/search/_layout.tsx
index f6c0257..6a64c63 100644
--- a/apps/mobile/app/(app)/(tabs)/search/_layout.tsx
+++ b/apps/mobile/app/(app)/(tabs)/search/_layout.tsx
@@ -1,7 +1,21 @@
import { Stack } from "expo-router"
-import { useStackScreenOptions } from "@/lib/navigation"
+import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
+
+export const unstable_settings = {
+ initialRouteName: "index",
+}
export default function SearchLayout() {
- return
+ const baseOptions = useStackScreenOptions({ title: "Search" })
+
+ return (
+ ({
+ ...baseOptions,
+ title: tabStackScreenTitles[route.name] ?? baseOptions.title,
+ })}
+ />
+ )
}
diff --git a/apps/mobile/app/(app)/(tabs)/search/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/search/album/[id].tsx
new file mode 100644
index 0000000..33706bf
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/album/[id].tsx
@@ -0,0 +1 @@
+export { default } from "../../home/album/[id]"
diff --git a/apps/mobile/app/(app)/(tabs)/search/artist/[id].tsx b/apps/mobile/app/(app)/(tabs)/search/artist/[id].tsx
new file mode 100644
index 0000000..1320cde
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/artist/[id].tsx
@@ -0,0 +1 @@
+export { default } from "../../home/artist/[id]"
diff --git a/apps/mobile/app/(app)/(tabs)/search/browse/albums.tsx b/apps/mobile/app/(app)/(tabs)/search/browse/albums.tsx
new file mode 100644
index 0000000..12ead6e
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/browse/albums.tsx
@@ -0,0 +1 @@
+export { default } from "../../home/browse/albums"
diff --git a/apps/mobile/app/(app)/(tabs)/search/browse/artists.tsx b/apps/mobile/app/(app)/(tabs)/search/browse/artists.tsx
new file mode 100644
index 0000000..70e0ed0
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/browse/artists.tsx
@@ -0,0 +1 @@
+export { default } from "../../home/browse/artists"
diff --git a/apps/mobile/app/(app)/(tabs)/search/browse/songs.tsx b/apps/mobile/app/(app)/(tabs)/search/browse/songs.tsx
new file mode 100644
index 0000000..a7493e6
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/browse/songs.tsx
@@ -0,0 +1 @@
+export { default } from "../../home/browse/songs"
diff --git a/apps/mobile/app/(app)/(tabs)/search/index.tsx b/apps/mobile/app/(app)/(tabs)/search/index.tsx
index 59d647b..f5d73a1 100644
--- a/apps/mobile/app/(app)/(tabs)/search/index.tsx
+++ b/apps/mobile/app/(app)/(tabs)/search/index.tsx
@@ -1,130 +1,29 @@
-import { useQuery } from "convex/react"
import { Stack } from "expo-router"
-import { useMemo, useState } from "react"
-import { ScrollView, StyleSheet, Text, View } from "react-native"
+import { useCallback } from "react"
-import { ContentCarousel } from "@/components/media-cards"
-import { tabContentBottomInset, SongRow } from "@/components/player"
-import { LoadingView } from "@/components/ui/primitives"
-import { usePlayback } from "@/contexts/playback"
-import { api } from "@otunes/convex/_generated/api"
-import type { BrowseSong } from "@otunes/convex/types"
-import { spacing, useThemeColors } from "@/lib/theme"
-
-const SEARCH_DEBOUNCE_MS = 300
+import { SearchResults } from "@/components/search-results"
+import { useDebouncedSearch } from "@/hooks/use-debounced-search"
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 { searchQuery, onQueryChange, onSearchSubmit } = useDebouncedSearch()
- 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]
+ const handleChangeText = useCallback(
+ (event: { nativeEvent: { text: string } }) => {
+ onQueryChange(event.nativeEvent.text)
+ },
+ [onQueryChange]
)
return (
<>
handleQueryChange(event.nativeEvent.text)}
- onSearchButtonPress={() => setSearchQuery(query.trim())}
+ onChangeText={handleChangeText}
+ onSearchButtonPress={onSearchSubmit}
autoCapitalize="none"
/>
- {isSearching ? (
-
- ) : !hasQuery ? (
-
-
- Find your favorite music
-
-
- ) : (
-
- {!hasLibraryResults ? (
-
-
- No results for "{searchQuery}"
-
-
- ) : 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({
- empty: { padding: spacing.xl, alignItems: "center" },
- emptyText: { fontSize: 16 },
- section: { paddingHorizontal: spacing.lg, paddingBottom: spacing.lg, gap: spacing.md },
-})
diff --git a/apps/mobile/app/(app)/(tabs)/search/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/search/playlist/[id].tsx
new file mode 100644
index 0000000..5d2b1ec
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/playlist/[id].tsx
@@ -0,0 +1 @@
+export { default } from "../../home/playlist/[id]"
diff --git a/apps/mobile/app/(app)/(tabs)/search/playlist/favorites.tsx b/apps/mobile/app/(app)/(tabs)/search/playlist/favorites.tsx
new file mode 100644
index 0000000..aab2512
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/playlist/favorites.tsx
@@ -0,0 +1 @@
+export { default } from "../../home/playlist/favorites"
diff --git a/apps/mobile/app/(app)/(tabs)/search/queue.tsx b/apps/mobile/app/(app)/(tabs)/search/queue.tsx
new file mode 100644
index 0000000..ea0fd22
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/queue.tsx
@@ -0,0 +1 @@
+export { default } from "../home/queue"
diff --git a/apps/mobile/app/(app)/(tabs)/search/recently-added.tsx b/apps/mobile/app/(app)/(tabs)/search/recently-added.tsx
new file mode 100644
index 0000000..2a67054
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/recently-added.tsx
@@ -0,0 +1 @@
+export { default } from "../home/recently-added"
diff --git a/apps/mobile/app/(app)/(tabs)/search/recently-played.tsx b/apps/mobile/app/(app)/(tabs)/search/recently-played.tsx
new file mode 100644
index 0000000..ce9f8f8
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/recently-played.tsx
@@ -0,0 +1 @@
+export { default } from "../home/recently-played"
diff --git a/apps/mobile/app/(app)/(tabs)/search/settings.tsx b/apps/mobile/app/(app)/(tabs)/search/settings.tsx
new file mode 100644
index 0000000..5228f63
--- /dev/null
+++ b/apps/mobile/app/(app)/(tabs)/search/settings.tsx
@@ -0,0 +1 @@
+export { default } from "../home/settings"
diff --git a/apps/mobile/app/(app)/_layout.tsx b/apps/mobile/app/(app)/_layout.tsx
index ac09ab6..382428a 100644
--- a/apps/mobile/app/(app)/_layout.tsx
+++ b/apps/mobile/app/(app)/_layout.tsx
@@ -1,70 +1,85 @@
-import { useConvexAuth } from "@convex-dev/auth/react"
+import { useConvexAuth as useLocalConvexAuth } from "@convex-dev/auth/react"
+import { useConvexAuth as useServerConvexAuth } from "convex/react"
import { Redirect, Stack } from "expo-router"
import { Platform } from "react-native"
+import { useEffect } from "react"
-import { FloatingMiniPlayer } from "@/components/mini-player"
+import { ConvexAuthRecovery } from "@/components/convex-auth-recovery"
import { LoadingView } from "@/components/ui/primitives"
import { AddToPlaylistProvider } from "@/contexts/add-to-playlist"
+import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
import { FavoritesProvider } from "@/contexts/favorites"
import { PlaybackProvider } from "@/contexts/playback"
import { useServerConfig } from "@/contexts/server-config"
import { useStackScreenOptions } from "@/lib/navigation"
+const AUTH_HANDSHAKE_TIMEOUT_MS = 15_000
+
export default function AppLayout() {
const { config } = useServerConfig()
- const auth = useConvexAuth()
+ const localAuth = useLocalConvexAuth()
+ const serverAuth = useServerConvexAuth()
+ const { invalidateSession } = useInvalidateAuthSession()
const stackOptions = useStackScreenOptions()
+ useEffect(() => {
+ if (!localAuth?.isAuthenticated || serverAuth?.isAuthenticated) {
+ return
+ }
+
+ const timer = setTimeout(() => {
+ void invalidateSession()
+ }, AUTH_HANDSHAKE_TIMEOUT_MS)
+
+ return () => clearTimeout(timer)
+ }, [
+ invalidateSession,
+ localAuth?.isAuthenticated,
+ serverAuth?.isAuthenticated,
+ ])
+
if (!config) {
return
}
- if (!auth) {
+ if (!localAuth || localAuth.isLoading) {
return
}
- const { isLoading, isAuthenticated } = auth
-
- if (isLoading) {
- return
- }
-
- if (!isAuthenticated) {
+ if (!localAuth.isAuthenticated) {
return
}
+ if (!serverAuth || serverAuth.isLoading || serverAuth.isRefreshing) {
+ return
+ }
+
+ if (!serverAuth.isAuthenticated) {
+ return
+ }
+
return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
)
}
diff --git a/apps/mobile/app/(app)/player.tsx b/apps/mobile/app/(app)/player.tsx
index 1562847..ed14445 100644
--- a/apps/mobile/app/(app)/player.tsx
+++ b/apps/mobile/app/(app)/player.tsx
@@ -20,11 +20,13 @@ import { useFavorites } from "@/contexts/favorites"
import { usePlayback } from "@/contexts/playback"
import { useServerConfig } from "@/contexts/server-config"
import { formatDuration, formatRemainingDuration } from "@/lib/format"
+import { useAppNavigation } from "@/lib/app-navigation"
import { albumCoverUrl } from "@/lib/urls"
import { appleMusic, radius, spacing, usePlayerTheme } from "@/lib/theme"
export default function PlayerScreen() {
const router = useRouter()
+ const { push } = useAppNavigation()
const insets = useSafeAreaInsets()
const player = usePlayerTheme()
const { config } = useServerConfig()
@@ -76,10 +78,10 @@ export default function PlayerScreen() {
await playShuffled([currentSong!.id])
break
case "go-artist":
- router.push(`/artist/${currentSong!.artist.id}`)
+ push(`/artist/${currentSong!.artist.id}`)
break
case "go-album":
- router.push(`/album/${currentSong!.album.id}`)
+ push(`/album/${currentSong!.album.id}`)
break
default:
break
@@ -226,7 +228,7 @@ export default function PlayerScreen() {
/>
router.push("/queue")}
+ onPress={() => push("/queue")}
hitSlop={12}
style={styles.footerButton}
disabled={queueSongIds.length === 0}
diff --git a/apps/mobile/components/auth-form.tsx b/apps/mobile/components/auth-form.tsx
index c6bbe87..a7614fa 100644
--- a/apps/mobile/components/auth-form.tsx
+++ b/apps/mobile/components/auth-form.tsx
@@ -1,7 +1,7 @@
-import { useAuthActions } from "@convex-dev/auth/react"
+import { useAuthActions, useConvexAuth } from "@convex-dev/auth/react"
import { Link, useRouter } from "expo-router"
import { useQuery } from "convex/react"
-import { useState } from "react"
+import { useEffect, useState } from "react"
import {
KeyboardAvoidingView,
Platform,
@@ -50,6 +50,7 @@ const copy: Record<
export function AuthForm({ flow }: { flow: AuthFlow }) {
const { signIn } = useAuthActions()
+ const auth = useConvexAuth()
const router = useRouter()
const colors = useThemeColors()
const { config } = useServerConfig()
@@ -60,6 +61,12 @@ export function AuthForm({ flow }: { flow: AuthFlow }) {
const [error, setError] = useState(null)
const [submitting, setSubmitting] = useState(false)
+ useEffect(() => {
+ if (auth.isAuthenticated) {
+ router.replace("/(app)/(tabs)/home")
+ }
+ }, [auth.isAuthenticated, router])
+
const text = copy[flow]
const accountCreationDisabled = appSettings?.disableAccountCreation ?? false
const signupsDisabled = flow === "signUp" && accountCreationDisabled
@@ -80,7 +87,6 @@ export function AuthForm({ flow }: { flow: AuthFlow }) {
try {
await signIn("password", formData)
- router.replace("/(app)/(tabs)/home")
} catch {
setError(
flow === "signIn"
diff --git a/apps/mobile/components/convex-auth-recovery.tsx b/apps/mobile/components/convex-auth-recovery.tsx
new file mode 100644
index 0000000..8959d94
--- /dev/null
+++ b/apps/mobile/components/convex-auth-recovery.tsx
@@ -0,0 +1,114 @@
+import { useConvexAuth as useLocalConvexAuth } from "@convex-dev/auth/react"
+import { useConvexAuth as useServerConvexAuth } from "convex/react"
+import {
+ Component,
+ useCallback,
+ useEffect,
+ useRef,
+ type ErrorInfo,
+ type ReactNode,
+} from "react"
+
+import { LoadingView } from "@/components/ui/primitives"
+import { shouldInvalidateAuthSession } from "@/lib/auth-errors"
+
+type ConvexAuthRecoveryProps = {
+ children: ReactNode
+ onInvalidate: () => Promise
+}
+
+type ConvexAuthErrorBoundaryProps = {
+ children: ReactNode
+ sessionEstablished: boolean
+ onAuthError: () => void
+}
+
+type ConvexAuthErrorBoundaryState = {
+ error: Error | null
+}
+
+class ConvexAuthErrorBoundary extends Component<
+ ConvexAuthErrorBoundaryProps,
+ ConvexAuthErrorBoundaryState
+> {
+ state: ConvexAuthErrorBoundaryState = { error: null }
+
+ static getDerivedStateFromError(error: Error): ConvexAuthErrorBoundaryState {
+ return { error }
+ }
+
+ componentDidCatch(error: Error, _errorInfo: ErrorInfo) {
+ if (shouldInvalidateAuthSession(error, this.props.sessionEstablished)) {
+ this.props.onAuthError()
+ }
+ }
+
+ render() {
+ const { error } = this.state
+ if (error) {
+ if (shouldInvalidateAuthSession(error, this.props.sessionEstablished)) {
+ return
+ }
+ throw error
+ }
+
+ return this.props.children
+ }
+}
+
+export function ConvexAuthRecovery({ children, onInvalidate }: ConvexAuthRecoveryProps) {
+ const localAuth = useLocalConvexAuth()
+ const serverAuth = useServerConvexAuth()
+ const hadServerAuthRef = useRef(false)
+ const invalidatingRef = useRef(false)
+
+ if (serverAuth?.isAuthenticated) {
+ hadServerAuthRef.current = true
+ }
+
+ const invalidateOnce = useCallback(async () => {
+ if (invalidatingRef.current) {
+ return
+ }
+
+ invalidatingRef.current = true
+ try {
+ await onInvalidate()
+ } catch {
+ invalidatingRef.current = false
+ }
+ }, [onInvalidate])
+
+ useEffect(() => {
+ if (!hadServerAuthRef.current) {
+ return
+ }
+ if (!localAuth?.isAuthenticated) {
+ return
+ }
+ if (!serverAuth || serverAuth.isLoading || serverAuth.isRefreshing) {
+ return
+ }
+ if (serverAuth.isAuthenticated) {
+ return
+ }
+
+ void invalidateOnce()
+ }, [invalidateOnce, localAuth, serverAuth])
+
+ const sessionEstablished = Boolean(
+ serverAuth &&
+ !serverAuth.isLoading &&
+ !serverAuth.isRefreshing &&
+ serverAuth.isAuthenticated
+ )
+
+ return (
+ void invalidateOnce()}
+ >
+ {children}
+
+ )
+}
diff --git a/apps/mobile/components/media-cards.tsx b/apps/mobile/components/media-cards.tsx
index 614f2d4..9201d36 100644
--- a/apps/mobile/components/media-cards.tsx
+++ b/apps/mobile/components/media-cards.tsx
@@ -1,9 +1,9 @@
import { Ionicons } from "@expo/vector-icons"
import { Image } from "expo-image"
-import { useRouter } from "expo-router"
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
import { useServerConfig } from "@/contexts/server-config"
+import { useAppNavigation } from "@/lib/app-navigation"
import type { BrowseAlbum, BrowseArtist, PlaylistSummary } from "@otunes/convex/types"
import { albumCoverUrl, artistCoverUrl, playlistCoverUrl } from "@/lib/urls"
import { carouselCardWidth, radius, spacing, useThemeColors, useTwoColumnCardWidth } from "@/lib/theme"
@@ -40,7 +40,7 @@ export function AlbumCard({
album: BrowseAlbum
width?: number
}) {
- const router = useRouter()
+ const { push } = useAppNavigation()
const { config } = useServerConfig()
const colors = useThemeColors()
if (!config) return null
@@ -48,7 +48,7 @@ export function AlbumCard({
return (
router.push(`/album/${album.id}`)}
+ onPress={() => push(`/album/${album.id}`)}
>
@@ -68,7 +68,7 @@ export function ArtistCard({
artist: BrowseArtist
width?: number
}) {
- const router = useRouter()
+ const { push } = useAppNavigation()
const { config } = useServerConfig()
const colors = useThemeColors()
if (!config) return null
@@ -76,7 +76,7 @@ export function ArtistCard({
return (
router.push(`/artist/${artist.id}`)}
+ onPress={() => push(`/artist/${artist.id}`)}
>
@@ -93,7 +93,7 @@ export function PlaylistCard({
playlist: PlaylistSummary
width?: number
}) {
- const router = useRouter()
+ const { push } = useAppNavigation()
const { config } = useServerConfig()
const colors = useThemeColors()
if (!config) return null
@@ -101,7 +101,7 @@ export function PlaylistCard({
return (
router.push(`/playlist/${playlist.id}`)}
+ onPress={() => push(`/playlist/${playlist.id}`)}
>
@@ -143,14 +143,14 @@ export function ContentCarousel({
href?: string
content: MediaItem[]
}) {
- const router = useRouter()
+ const { push } = useAppNavigation()
const colors = useThemeColors()
return (
href && router.push(href as never)}
+ onPress={() => href && push(href)}
style={styles.sectionHeader}
>
{title}
diff --git a/apps/mobile/components/mini-player.tsx b/apps/mobile/components/mini-player.tsx
index 19da219..7a850ef 100644
--- a/apps/mobile/components/mini-player.tsx
+++ b/apps/mobile/components/mini-player.tsx
@@ -1,10 +1,8 @@
import { Ionicons } from "@expo/vector-icons"
-import { BlurView } from "expo-blur"
import { Image } from "expo-image"
import { NativeTabs } from "expo-router/unstable-native-tabs"
-import { useRouter, useSegments } from "expo-router"
+import { useRouter } from "expo-router"
import { Platform, Pressable, StyleSheet, Text, View } from "react-native"
-import { useSafeAreaInsets } from "react-native-safe-area-context"
import { usePlayback } from "@/contexts/playback"
import { useServerConfig } from "@/contexts/server-config"
@@ -12,12 +10,12 @@ import { albumCoverUrl } from "@/lib/urls"
import { miniPlayerHeight, tabBarHeight, useBlurTint, useMiniPlayerBackground, useThemeColors } from "@/lib/theme"
function MiniPlayerContent({
- compact,
+ placement,
variant = "bar",
onOpenPlayer,
}: {
- compact?: boolean
- variant?: "bar" | "accessory"
+ placement: "regular" | "inline"
+ variant: "bar" | "accessory"
onOpenPlayer: () => void
}) {
const colors = useThemeColors()
@@ -33,6 +31,7 @@ function MiniPlayerContent({
return null
}
+ const compact = placement === "inline"
const isAccessory = variant === "accessory"
const artworkStyle = isAccessory ? styles.accessoryArtwork : styles.artwork
const rowStyle = compact ? styles.inlineContent : isAccessory ? styles.accessoryContent : styles.content
@@ -133,18 +132,8 @@ function MiniPlayerContent({
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
const colors = useThemeColors()
- const blurTint = useBlurTint()
const backgroundColor = useMiniPlayerBackground()
- if (Platform.OS === "ios") {
- return (
-
-
- {children}
-
- )
- }
-
return (
@@ -165,7 +154,7 @@ export function TabBottomAccessory() {
const content = (
router.push("/player")}
/>
@@ -178,43 +167,43 @@ export function TabBottomAccessory() {
return content
}
-
-function useFloatingMiniPlayerLayout() {
- const segments = useSegments() as string[]
- const insets = useSafeAreaInsets()
-
- const onPlayerModal = segments.includes("player")
- const onAuthFlow =
- segments.includes("signin") ||
- segments.includes("signup") ||
- segments.includes("server")
- const onTabs = segments.includes("(tabs)")
-
- const bottom = insets.bottom + (onTabs ? 0 : 0)
-
- return {
- bottom,
- hidden: onPlayerModal || onAuthFlow || onTabs,
- }
-}
-
-export function FloatingMiniPlayer() {
- const router = useRouter()
- const { bottom, hidden } = useFloatingMiniPlayerLayout()
- const { currentSong, queueSongIds } = usePlayback()
-
- if (hidden || !currentSong || queueSongIds.length === 0) {
- return null
- }
-
- return (
-
-
- router.push("/player")} />
-
-
- )
-}
+//
+// function useFloatingMiniPlayerLayout() {
+// const segments = useSegments() as string[]
+// const insets = useSafeAreaInsets()
+//
+// const onPlayerModal = segments.includes("player")
+// const onAuthFlow =
+// segments.includes("signin") ||
+// segments.includes("signup") ||
+// segments.includes("server")
+// const onTabs = segments.includes("(tabs)")
+//
+// const bottom = insets.bottom + (onTabs ? 0 : 0)
+//
+// return {
+// bottom,
+// hidden: onPlayerModal || onAuthFlow || onTabs,
+// }
+// }
+//
+// export function FloatingMiniPlayer() {
+// const router = useRouter()
+// const { bottom, hidden } = useFloatingMiniPlayerLayout()
+// const { currentSong, queueSongIds } = usePlayback()
+//
+// if (hidden || !currentSong || queueSongIds.length === 0) {
+// return null
+// }
+//
+// return (
+//
+//
+// router.push("/player")} />
+//
+//
+// )
+// }
const styles = StyleSheet.create({
floatingContainer: {
diff --git a/apps/mobile/components/search-results.tsx b/apps/mobile/components/search-results.tsx
new file mode 100644
index 0000000..eadb407
--- /dev/null
+++ b/apps/mobile/components/search-results.tsx
@@ -0,0 +1,114 @@
+import { useQuery } from "convex/react"
+import { memo, useMemo } from "react"
+import { ScrollView, StyleSheet, Text, View } from "react-native"
+
+import { ContentCarousel } from "@/components/media-cards"
+import { tabContentBottomInset, SongRow } from "@/components/player"
+import { LoadingView } from "@/components/ui/primitives"
+import { usePlayback } from "@/contexts/playback"
+import { api } from "@otunes/convex/_generated/api"
+import type { BrowseSong } from "@otunes/convex/types"
+import { spacing, useThemeColors } from "@/lib/theme"
+
+function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
+ const colors = useThemeColors()
+ const { playFromSong } = usePlayback()
+ 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
+
+ const hasLibraryResults = useMemo(
+ () =>
+ Boolean(
+ results &&
+ (results.topResults.length > 0 ||
+ results.artists.length > 0 ||
+ results.albums.length > 0 ||
+ results.songs.length > 0)
+ ),
+ [results]
+ )
+
+ if (isSearching) {
+ return
+ }
+
+ if (!hasQuery) {
+ return (
+
+
+ Find your favorite music
+
+
+ )
+ }
+
+ return (
+
+ {!hasLibraryResults ? (
+
+
+ No results for "{searchQuery}"
+
+
+ ) : 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}
+
+ )
+}
+
+export const SearchResults = memo(SearchResultsBody)
+
+const styles = StyleSheet.create({
+ empty: { padding: spacing.xl, alignItems: "center" },
+ emptyText: { fontSize: 16 },
+ section: { paddingHorizontal: spacing.lg, paddingBottom: spacing.lg, gap: spacing.md },
+})
diff --git a/apps/mobile/contexts/add-to-playlist.tsx b/apps/mobile/contexts/add-to-playlist.tsx
index 874c560..a467780 100644
--- a/apps/mobile/contexts/add-to-playlist.tsx
+++ b/apps/mobile/contexts/add-to-playlist.tsx
@@ -1,5 +1,4 @@
import { useConvex, useMutation, useQuery } from "convex/react"
-import { useRouter } from "expo-router"
import {
createContext,
useCallback,
@@ -15,6 +14,7 @@ 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 { useAppNavigation } from "@/lib/app-navigation"
import { useThemeColors } from "@/lib/theme"
type AddToPlaylistContextValue = {
@@ -37,7 +37,7 @@ export function useAddToPlaylist() {
export function AddToPlaylistProvider({ children }: { children: ReactNode }) {
const convex = useConvex()
- const router = useRouter()
+ const { push } = useAppNavigation()
const colors = useThemeColors()
const ownedPlaylists = useQuery(api.playlists.listOwnedPlaylists)
const addSongs = useMutation(api.playlists.addSongsToPlaylist)
@@ -126,13 +126,13 @@ export function AddToPlaylistProvider({ children }: { children: ReactNode }) {
showSuccess("Playlist created")
setCreateOpen(false)
setOpen(false)
- router.push(`/playlist/${playlistId}`)
+ push(`/playlist/${playlistId}`)
} catch (error) {
showError(error instanceof Error ? error.message : "Failed to create playlist")
} finally {
setSubmitting(false)
}
- }, [newPlaylistName, createPlaylist, pendingSongIds, addSongs, router])
+ }, [newPlaylistName, createPlaylist, pendingSongIds, addSongs, push])
const value = useMemo(
() => ({
diff --git a/apps/mobile/contexts/convex-app.tsx b/apps/mobile/contexts/convex-app.tsx
index e4d8fe5..812b476 100644
--- a/apps/mobile/contexts/convex-app.tsx
+++ b/apps/mobile/contexts/convex-app.tsx
@@ -1,29 +1,42 @@
import { ConvexAuthProvider } from "@convex-dev/auth/react"
import { ConvexReactClient } from "convex/react"
-import { useMemo, type ReactNode } from "react"
+import { useCallback, useMemo, useState, type ReactNode } from "react"
+import { ConvexAuthSessionProvider } from "@/contexts/convex-auth-session"
import { useServerConfig } from "@/contexts/server-config"
-import { secureStorage } from "@/lib/auth-storage"
+import { clearStoredAuthTokens, secureStorage } from "@/lib/auth-storage"
export function ConvexAppProvider({ children }: { children: ReactNode }) {
const { config } = useServerConfig()
+ const [authEpoch, setAuthEpoch] = useState(0)
const client = useMemo(() => {
if (!config) return null
return new ConvexReactClient(config.convexUrl)
- }, [config?.convexUrl])
+ }, [config?.convexUrl, authEpoch])
+
+ const invalidateSession = useCallback(async () => {
+ if (!config) {
+ return
+ }
+ await clearStoredAuthTokens(config.convexUrl)
+ setAuthEpoch((epoch) => epoch + 1)
+ }, [config])
if (!client || !config) {
return <>{children}>
}
return (
-
- {children}
-
+
+
+ {children}
+
+
)
}
diff --git a/apps/mobile/contexts/convex-auth-session.tsx b/apps/mobile/contexts/convex-auth-session.tsx
new file mode 100644
index 0000000..52db6cc
--- /dev/null
+++ b/apps/mobile/contexts/convex-auth-session.tsx
@@ -0,0 +1,31 @@
+import { createContext, useContext, type ReactNode } from "react"
+
+type ConvexAuthSessionContextValue = {
+ invalidateSession: () => Promise
+}
+
+const ConvexAuthSessionContext = createContext(
+ null
+)
+
+export function ConvexAuthSessionProvider({
+ children,
+ invalidateSession,
+}: {
+ children: ReactNode
+ invalidateSession: () => Promise
+}) {
+ return (
+
+ {children}
+
+ )
+}
+
+export function useInvalidateAuthSession() {
+ const context = useContext(ConvexAuthSessionContext)
+ if (!context) {
+ throw new Error("useInvalidateAuthSession must be used within ConvexAppProvider")
+ }
+ return context
+}
diff --git a/apps/mobile/hooks/use-debounced-search.ts b/apps/mobile/hooks/use-debounced-search.ts
new file mode 100644
index 0000000..4284a02
--- /dev/null
+++ b/apps/mobile/hooks/use-debounced-search.ts
@@ -0,0 +1,43 @@
+import { useCallback, useEffect, useRef, useState } from "react"
+
+const DEFAULT_DEBOUNCE_MS = 300
+
+export function useDebouncedSearch(debounceMs = DEFAULT_DEBOUNCE_MS) {
+ const queryRef = useRef("")
+ const debounceRef = useRef | null>(null)
+ const [searchQuery, setSearchQuery] = useState("")
+
+ useEffect(() => {
+ return () => {
+ if (debounceRef.current) {
+ clearTimeout(debounceRef.current)
+ }
+ }
+ }, [])
+
+ const commitSearch = useCallback((value: string) => {
+ setSearchQuery(value.trim())
+ }, [])
+
+ const onQueryChange = useCallback(
+ (value: string) => {
+ queryRef.current = value
+ if (debounceRef.current) {
+ clearTimeout(debounceRef.current)
+ }
+ debounceRef.current = setTimeout(() => {
+ commitSearch(value)
+ }, debounceMs)
+ },
+ [commitSearch, debounceMs]
+ )
+
+ const onSearchSubmit = useCallback(() => {
+ if (debounceRef.current) {
+ clearTimeout(debounceRef.current)
+ }
+ commitSearch(queryRef.current)
+ }, [commitSearch])
+
+ return { searchQuery, onQueryChange, onSearchSubmit }
+}
diff --git a/apps/mobile/lib/app-navigation.ts b/apps/mobile/lib/app-navigation.ts
new file mode 100644
index 0000000..3f11d25
--- /dev/null
+++ b/apps/mobile/lib/app-navigation.ts
@@ -0,0 +1,34 @@
+import { useRouter, useSegments, type Href } from "expo-router"
+
+export const APP_TABS = ["home", "library", "search"] as const
+export type AppTab = (typeof APP_TABS)[number]
+
+const TAB_SET = new Set(APP_TABS)
+
+export function getActiveTab(segments: string[]): AppTab {
+ for (const segment of segments) {
+ if (TAB_SET.has(segment)) {
+ return segment as AppTab
+ }
+ }
+
+ return "home"
+}
+
+export function tabPath(tab: AppTab, path: string): Href {
+ const normalized = path.startsWith("/") ? path : `/${path}`
+ return `/(app)/(tabs)/${tab}${normalized}` as Href
+}
+
+export function useAppNavigation() {
+ const router = useRouter()
+ const segments = useSegments()
+ const tab = getActiveTab(segments)
+
+ return {
+ tab,
+ href: (path: string) => tabPath(tab, path),
+ push: (path: string) => router.push(tabPath(tab, path)),
+ replace: (path: string) => router.replace(tabPath(tab, path)),
+ }
+}
diff --git a/apps/mobile/lib/auth-errors.ts b/apps/mobile/lib/auth-errors.ts
new file mode 100644
index 0000000..56e27fb
--- /dev/null
+++ b/apps/mobile/lib/auth-errors.ts
@@ -0,0 +1,63 @@
+import { ConvexError, type Value } from "convex/values"
+
+const AUTH_ERROR_MESSAGES = new Set([
+ "Not authenticated",
+ "User not logged in",
+])
+
+function matchesAuthMessage(message: string): boolean {
+ if (AUTH_ERROR_MESSAGES.has(message)) {
+ return true
+ }
+
+ const normalized = message.toLowerCase()
+ return (
+ normalized.includes("not authenticated") ||
+ normalized.includes("unauthenticated") ||
+ normalized.includes("invalid session") ||
+ normalized.includes("invalid token") ||
+ normalized.includes("auth error")
+ )
+}
+
+function convexErrorData(error: ConvexError): string | null {
+ if (typeof error.data === "string") {
+ return error.data
+ }
+ return null
+}
+
+export function isConvexTransportAuthFailure(error: unknown): boolean {
+ if (!(error instanceof Error)) {
+ return false
+ }
+
+ return (
+ error.message.includes("[CONVEX") && error.message.includes("Server Error")
+ )
+}
+
+export function isConvexAuthError(error: unknown): boolean {
+ if (error instanceof ConvexError) {
+ const data = convexErrorData(error)
+ if (data && matchesAuthMessage(data)) {
+ return true
+ }
+ if (matchesAuthMessage(error.message)) {
+ return true
+ }
+ }
+
+ return isConvexTransportAuthFailure(error)
+}
+
+export function shouldInvalidateAuthSession(
+ error: unknown,
+ sessionEstablished: boolean
+): boolean {
+ if (!sessionEstablished) {
+ return false
+ }
+
+ return isConvexAuthError(error)
+}
diff --git a/apps/mobile/lib/auth-storage.ts b/apps/mobile/lib/auth-storage.ts
index 6fa5904..190e717 100644
--- a/apps/mobile/lib/auth-storage.ts
+++ b/apps/mobile/lib/auth-storage.ts
@@ -1,6 +1,13 @@
import * as SecureStore from "expo-secure-store"
import type { TokenStorage } from "@convex-dev/auth/react"
+const AUTH_STORAGE_KEYS = [
+ "__convexAuthOAuthVerifier",
+ "__convexAuthJWT",
+ "__convexAuthRefreshToken",
+ "__convexAuthServerStateFetchTime",
+] as const
+
const secureStoreOptions: SecureStore.SecureStoreOptions = {
keychainAccessible: SecureStore.AFTER_FIRST_UNLOCK,
}
@@ -25,6 +32,19 @@ export async function secureRemoveItem(key: string): Promise {
}
}
+export function authStorageKey(key: string, storageNamespace: string): string {
+ const escapedNamespace = storageNamespace.replace(/[^a-zA-Z0-9]/g, "")
+ return `${key}_${escapedNamespace}`
+}
+
+export async function clearStoredAuthTokens(storageNamespace: string): Promise {
+ await Promise.all(
+ AUTH_STORAGE_KEYS.map((key) =>
+ secureRemoveItem(authStorageKey(key, storageNamespace))
+ )
+ )
+}
+
export const secureStorage: TokenStorage = {
getItem(key) {
return secureGetItem(key)
diff --git a/apps/mobile/lib/navigation.ts b/apps/mobile/lib/navigation.ts
index 56b358f..06b2889 100644
--- a/apps/mobile/lib/navigation.ts
+++ b/apps/mobile/lib/navigation.ts
@@ -1,21 +1,29 @@
import { useColorScheme } from "react-native"
import { colors } from "@/lib/theme"
+import type { ScreenProps as BaseScreenProps } from "expo-router/build/useScreens"
+import type {
+ NativeStackNavigationEventMap,
+ NativeStackNavigationOptions,
+} from "expo-router/build/react-navigation/native-stack"
+import type { ParamListBase, StackNavigationState } from "expo-router/build/react-navigation/native"
-type StackScreenOptions = {
- title?: string
- headerLargeTitle?: boolean
- headerShadowVisible?: boolean
- headerStyle?: { backgroundColor?: string }
- headerTintColor?: string
- headerLargeTitleStyle?: { color?: string }
- headerBackButtonDisplayMode?: "minimal" | "default" | "generic"
- contentStyle?: { backgroundColor?: string }
- headerShown?: boolean
- headerRight?: () => React.ReactNode
- presentation?: "card" | "modal" | "transparentModal" | "containedModal" | "fullScreenModal"
- animation?: "default" | "fade" | "fade_from_bottom" | "flip" | "simple_push" | "slide_from_bottom" | "slide_from_right" | "slide_from_left" | "none"
- gestureEnabled?: boolean
+type StackBaseScreenProps = BaseScreenProps<
+ NativeStackNavigationOptions,
+ StackNavigationState,
+ NativeStackNavigationEventMap
+>
+
+type StackScreenOptions = StackBaseScreenProps["options"]
+
+export const tabStackScreenTitles: Record = {
+ "browse/albums": "Albums",
+ "browse/artists": "Artists",
+ "browse/songs": "Songs",
+ "recently-played": "Recently Played",
+ "recently-added": "Recently Added",
+ playlists: "Playlists",
+ settings: "Settings",
}
export function useStackScreenOptions(
@@ -26,12 +34,10 @@ export function useStackScreenOptions(
return {
headerLargeTitle: true,
- headerShadowVisible: false,
- headerStyle: { backgroundColor: theme.background },
+ headerTransparent: true,
headerTintColor: theme.foreground,
headerLargeTitleStyle: { color: theme.foreground },
headerBackButtonDisplayMode: "minimal",
- contentStyle: { backgroundColor: theme.background },
...overrides,
}
}
diff --git a/apps/mobile/lib/session.ts b/apps/mobile/lib/session.ts
index d7c9407..e9a67b9 100644
--- a/apps/mobile/lib/session.ts
+++ b/apps/mobile/lib/session.ts
@@ -3,9 +3,9 @@ import type { useRouter } from "expo-router"
type AppRouter = ReturnType
export async function signOutToSignIn(
- signOut: () => Promise,
- router: Pick
+ router: Pick,
+ invalidateSession: () => Promise
) {
- await signOut()
+ await invalidateSession()
router.replace("/signin")
}