From 629192b610f699585173dcbf681fe47e7eb9119f Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Tue, 3 Nov 2026 21:13:36 -0500 Subject: [PATCH] feat(mobile): search within playlists using native search --- .../app/(app)/(tabs)/home/playlist/[id].tsx | 23 +++++++- .../(app)/(tabs)/home/playlist/favorites.tsx | 20 ++++++- .../mobile/components/playlist-search-bar.tsx | 56 +++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 apps/mobile/components/playlist-search-bar.tsx diff --git a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx index f7e748a..c5214fc 100644 --- a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx @@ -1,3 +1,7 @@ +import { + PlaylistSearchBar, + usePlaylistSearch, +} from "@/components/playlist-search-bar" import { useAndroidScreenPalette } from "@/contexts/android-tab-theme" import { MusicEntityView } from "@/components/music-entity-view" import { useMutation } from "convex/react" @@ -158,6 +162,8 @@ function PlaylistContent({ const isSubscribed = playlist.isSubscribed const canEdit = playlist.isOwner && playlistId !== null const songIds = useMemo(() => songs.map((song) => song.id), [songs]) + const { filteredSongs, onQueryChange, onSearchSubmit } = + usePlaylistSearch(songs) const swipeGroup = useSwipeRowGroup() const handlePlaySong = useCallback( @@ -312,10 +318,14 @@ function PlaylistContent({ ) : null} + + {songs.length ? "No songs found." : "No songs in this playlist."} + + } ListHeaderComponent={ songs.map((song) => song.id), [songs]) + const { filteredSongs, onQueryChange, onSearchSubmit } = + usePlaylistSearch(songs) useEffect(() => { if (favorites) rememberSongs(favorites.songs) @@ -99,14 +105,25 @@ export default function FavoritesScreen() { return ( <> + + {songs.length ? "No songs found." : "No songs in this playlist."} + + } ListHeaderComponent={ { + const query = search.searchQuery.toLowerCase() + if (!query) return songs + return songs.filter((song) => + [song.title, song.artist.name, song.album.title].some((value) => + value.toLowerCase().includes(query) + ) + ) + }, [songs, search.searchQuery]) + + return { ...search, filteredSongs } +} + +export function PlaylistSearchBar({ + onQueryChange, + onSearchSubmit, +}: Pick< + ReturnType, + "onQueryChange" | "onSearchSubmit" +>) { + const colors = useThemeColors() + const handleChangeText = useCallback( + (event: { nativeEvent: { text: string } }) => { + onQueryChange(event.nativeEvent.text) + }, + [onQueryChange] + ) + + return ( + + ) +}