diff --git a/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx b/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx
index fede3e1..d5caa91 100644
--- a/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/browse/albums.tsx
@@ -1,30 +1,67 @@
-import { usePaginatedQuery } from "convex/react"
+import { usePaginatedQuery, useQuery } from "convex/react"
+import { Stack } from "expo-router"
+import { useCallback } from "react"
import { MediaGridList } from "@/components/media-cards"
import { LoadingView } from "@/components/ui/primitives"
import { contentBottomInset } from "@/components/player"
+import { useDebouncedSearch } from "@/hooks/use-debounced-search"
import { api } from "@otunes/convex/_generated/api"
const PAGE_SIZE = 50
export default function AlbumsScreen() {
+ const { searchQuery, onQueryChange, onSearchSubmit } = useDebouncedSearch()
const { results, status, loadMore } = usePaginatedQuery(
api.library.browseAlbumsPaginated,
{},
{ initialNumItems: PAGE_SIZE }
)
+ const searchResults = useQuery(
+ api.library.searchLibrary,
+ searchQuery ? { query: searchQuery } : "skip"
+ )
+ const albums = searchQuery ? searchResults?.albums : results
- if (results === undefined) {
- return
- }
+ const handleChangeText = useCallback(
+ (event: { nativeEvent: { text: string } }) => {
+ onQueryChange(event.nativeEvent.text)
+ },
+ [onQueryChange]
+ )
- return (
- {
- if (status === "CanLoadMore") loadMore(PAGE_SIZE)
+ const searchBar = (
+
)
+
+ if (albums === undefined) {
+ return (
+ <>
+ {searchBar}
+
+ >
+ )
+ }
+
+ return (
+ <>
+ {searchBar}
+
+ {
+ if (!searchQuery && status === "CanLoadMore") loadMore(PAGE_SIZE)
+ }}
+ />
+ >
+ )
}
diff --git a/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx b/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
index a8679e5..2517606 100644
--- a/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/browse/artists.tsx
@@ -1,4 +1,6 @@
-import { usePaginatedQuery } from "convex/react"
+import { usePaginatedQuery, useQuery } from "convex/react"
+import { Stack } from "expo-router"
+import { useCallback } from "react"
import { FlatList, Pressable, StyleSheet, Text } from "react-native"
import { MediaContextMenu } from "@/components/media-context-menu"
@@ -6,6 +8,7 @@ import { CoverImage } from "@/components/cover-image"
import { LoadingView } from "@/components/ui/primitives"
import { contentBottomInset } from "@/components/player"
import { useServerConfig } from "@/contexts/server-config"
+import { useDebouncedSearch } from "@/hooks/use-debounced-search"
import { useAppNavigation } from "@/lib/app-navigation"
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
import { api } from "@otunes/convex/_generated/api"
@@ -19,48 +22,82 @@ export default function ArtistsScreen() {
const { push } = useAppNavigation()
const colors = useThemeColors()
const { config } = useServerConfig()
+ const { searchQuery, onQueryChange, onSearchSubmit } = useDebouncedSearch()
const { results, status, loadMore } = usePaginatedQuery(
api.library.browseArtistsPaginated,
{},
{ initialNumItems: PAGE_SIZE }
)
+ const searchResults = useQuery(
+ api.library.searchLibrary,
+ searchQuery ? { query: searchQuery } : "skip"
+ )
const { handleArtistAction, isArtistFavorite } = useMediaMenuActions()
+ const artists = searchQuery ? searchResults?.artists : results
- if (results === undefined || !config) {
- return
+ const handleChangeText = useCallback(
+ (event: { nativeEvent: { text: string } }) => {
+ onQueryChange(event.nativeEvent.text)
+ },
+ [onQueryChange]
+ )
+
+ const searchBar = (
+
+ )
+
+ if (artists === undefined || !config) {
+ return (
+ <>
+ {searchBar}
+
+ >
+ )
}
return (
- artist.id}
- style={{ flex: 1, backgroundColor: colors.background }}
- contentContainerStyle={{ paddingBottom: contentBottomInset }}
- contentInsetAdjustmentBehavior="automatic"
- onEndReached={() => {
- if (status === "CanLoadMore") loadMore(PAGE_SIZE)
- }}
- onEndReachedThreshold={0.5}
- renderItem={({ item: artist }: { item: BrowseArtist }) => (
- void handleArtistAction(artist, action)}
- >
- push(`/artist/${artist.id}`)}
+ <>
+ {searchBar}
+
+ artist.id}
+ style={{ flex: 1, backgroundColor: colors.background }}
+ contentContainerStyle={{ paddingBottom: contentBottomInset }}
+ contentInsetAdjustmentBehavior="automatic"
+ onEndReached={() => {
+ if (!searchQuery && status === "CanLoadMore") loadMore(PAGE_SIZE)
+ }}
+ onEndReachedThreshold={0.5}
+ renderItem={({ item: artist }: { item: BrowseArtist }) => (
+ void handleArtistAction(artist, action)}
>
-
- {artist.name}
-
-
- )}
- />
+ push(`/artist/${artist.id}`)}
+ >
+
+ {artist.name}
+
+
+ )}
+ />
+ >
)
}
diff --git a/apps/mobile/app/(app)/(tabs)/home/browse/songs.tsx b/apps/mobile/app/(app)/(tabs)/home/browse/songs.tsx
index 7deb33b..a4716c7 100644
--- a/apps/mobile/app/(app)/(tabs)/home/browse/songs.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/browse/songs.tsx
@@ -1,11 +1,13 @@
-import { usePaginatedQuery } from "convex/react"
-import { useState } from "react"
+import { usePaginatedQuery, useQuery } from "convex/react"
+import { Stack } from "expo-router"
+import { useCallback, useState } from "react"
import { FlatList, StyleSheet } from "react-native"
import { contentBottomInset, SongRow } from "@/components/player"
import { LoadingView } from "@/components/ui/primitives"
import { useFavorites } from "@/contexts/favorites"
import { usePlayback } from "@/contexts/playback"
+import { useDebouncedSearch } from "@/hooks/use-debounced-search"
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
import { api } from "@otunes/convex/_generated/api"
import type { Id } from "@otunes/convex/_generated/dataModel"
@@ -17,6 +19,7 @@ export default function SongsScreen() {
const { playFromLibrarySong } = usePlayback()
const { isSongFavorite } = useFavorites()
const { handleSongAction } = useMediaMenuActions()
+ const { searchQuery, onQueryChange, onSearchSubmit } = useDebouncedSearch()
const [sortKey, setSortKey] = useState<"title" | "artist" | "album">("title")
const [sortDirection, setSortDirection] = useState<"asc" | "desc">("asc")
@@ -25,46 +28,79 @@ export default function SongsScreen() {
{ sortKey, sortDirection },
{ initialNumItems: PAGE_SIZE }
)
+ const searchResults = useQuery(
+ api.library.searchLibrary,
+ searchQuery ? { query: searchQuery } : "skip"
+ )
+ const songs = searchQuery ? searchResults?.songs : results
- if (results === undefined) {
- return
+ const handleChangeText = useCallback(
+ (event: { nativeEvent: { text: string } }) => {
+ onQueryChange(event.nativeEvent.text)
+ },
+ [onQueryChange]
+ )
+
+ const searchBar = (
+
+ )
+
+ if (songs === undefined) {
+ return (
+ <>
+ {searchBar}
+
+ >
+ )
}
return (
- item.id}
- contentContainerStyle={{ paddingBottom: contentBottomInset }}
- contentInsetAdjustmentBehavior="automatic"
- onEndReached={() => {
- if (status === "CanLoadMore") loadMore(PAGE_SIZE)
- }}
- onEndReachedThreshold={0.5}
- renderItem={({ item }) => (
-
- void playFromLibrarySong(item.id as Id<"songs">, {
- sortKey,
- sortDirection,
- })
- }
- contextMenu={{
- favorited: isSongFavorite(item.id),
- navigation: {
- artist: { id: item.artist.id },
- album: { id: item.album.id },
- },
- share: {
- type: "song",
- albumId: item.album.id,
- songId: item.id,
- },
- onAction: (action) => void handleSongAction(item, action),
- }}
- />
- )}
- />
+ <>
+ {searchBar}
+
+ item.id}
+ contentContainerStyle={{ paddingBottom: contentBottomInset }}
+ contentInsetAdjustmentBehavior="automatic"
+ onEndReached={() => {
+ if (!searchQuery && status === "CanLoadMore") loadMore(PAGE_SIZE)
+ }}
+ onEndReachedThreshold={0.5}
+ renderItem={({ item }) => (
+
+ void playFromLibrarySong(item.id as Id<"songs">, {
+ sortKey,
+ sortDirection,
+ })
+ }
+ contextMenu={{
+ favorited: isSongFavorite(item.id),
+ navigation: {
+ artist: { id: item.artist.id },
+ album: { id: item.album.id },
+ },
+ share: {
+ type: "song",
+ albumId: item.album.id,
+ songId: item.id,
+ },
+ onAction: (action) => void handleSongAction(item, action),
+ }}
+ />
+ )}
+ />
+ >
)
}