diff --git a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx index 3b4b9ec..5167c07 100644 --- a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx @@ -39,10 +39,7 @@ import { contentBottomInset, SongListRow } from "@/components/player" import { useFavorites } from "@/contexts/favorites" import { usePlaybackActions } from "@/contexts/playback" import { useServerConfig } from "@/contexts/server-config" -import { - useCachedPaginatedQuery, - useCachedQuery, -} from "@/hooks/use-cached-query" +import { useCachedQuery } from "@/hooks/use-cached-query" import { useCoverPalette } from "@/hooks/use-cover-palette" import { useMediaMenuActions } from "@/hooks/use-media-menu-actions" import { api } from "@otunes/convex/_generated/api" @@ -55,7 +52,6 @@ import { showError } from "@/lib/toast" import { playlistCoverUrl } from "@/lib/urls" import { radius, spacing, useThemeColors } from "@/lib/theme" -const PAGE_SIZE = 50 const PLAYLIST_LABEL = "Add to Another Playlist" const OWNER_MENU_ACTIONS: MediaAction[] = [ "share", @@ -74,27 +70,9 @@ export default function PlaylistScreen() { const playlistId = typeof id === "string" ? (id as Id<"playlists">) : null const playlist = useCachedQuery( api.playlists.browsePlaylistDetail, - playlistId - ? { - id: playlistId, - includeSongs: false, - } - : "skip" - ) - const { - results: songs, - status, - loadMore, - isCached, - } = useCachedPaginatedQuery( - api.playlists.browsePlaylistSongsPaginated, - playlistId ? { id: playlistId } : "skip", - { initialNumItems: PAGE_SIZE } - ) - const allSongIds = useCachedQuery( - api.playlists.getPlaylistSongIds, - playlistId ? { playlistId } : "skip" + playlistId ? { id: playlistId } : "skip" ) + const songs = playlist?.songs const coverUri = config && playlistId ? playlistCoverUrl(config.serverUrl, playlist?.id ?? playlistId) @@ -106,15 +84,10 @@ export default function PlaylistScreen() { const { palette, onLayout } = useAndroidScreenPalette(artworkPalette) useEffect(() => { - rememberSongs(songs) + if (songs) rememberSongs(songs) }, [songs]) - if ( - playlist === undefined || - (status === "LoadingFirstPage" && !isCached) || - !config || - !settled - ) { + if (playlist === undefined || !config || !settled) { return ( <> { - if (status === "CanLoadMore") loadMore(PAGE_SIZE) - }} /> ) } @@ -165,18 +134,14 @@ function PlaylistContent({ onLayout, playlist, songs, - allSongIds, coverUri, palette, - onEndReached, }: { onLayout?: () => void playlist: BrowsePlaylistDetail songs: BrowseSong[] - allSongIds: Id<"songs">[] | undefined coverUri: string palette: CoverPalette - onEndReached: () => void }) { const router = useRouter() const isFocused = useIsFocused() @@ -192,8 +157,7 @@ function PlaylistContent({ const playlistId = playlist.id const isSubscribed = playlist.isSubscribed const canEdit = playlist.isOwner && playlistId !== null - const loadedSongIds = useMemo(() => songs.map((song) => song.id), [songs]) - const songIds = allSongIds ?? loadedSongIds + const songIds = useMemo(() => songs.map((song) => song.id), [songs]) const swipeGroup = useSwipeRowGroup() const handlePlaySong = useCallback( @@ -226,12 +190,12 @@ function PlaylistContent({ ) const handlePlay = useCallback(() => { - if (playlistId) void playPlaylist(playlistId, allSongIds) - }, [allSongIds, playPlaylist, playlistId]) + if (playlistId) void playPlaylist(playlistId, songIds) + }, [playPlaylist, playlistId, songIds]) const handleShuffle = useCallback(() => { - if (playlistId) void playPlaylistShuffled(playlistId, allSongIds) - }, [allSongIds, playPlaylistShuffled, playlistId]) + if (playlistId) void playPlaylistShuffled(playlistId, songIds) + }, [playPlaylistShuffled, playlistId, songIds]) const handleSubscribeToggle = useCallback(async () => { if (!playlistId) return @@ -355,8 +319,6 @@ function PlaylistContent({ indicatorStyle={palette.isDark ? "white" : "black"} contentContainerStyle={styles.listContent} contentInsetAdjustmentBehavior="automatic" - onEndReached={onEndReached} - onEndReachedThreshold={0.5} onScrollBeginDrag={swipeGroup.closeOpenRow} ListHeaderComponent={ songs.map((song) => song.id), [songs]) - const songIds = favorites?.songIds ?? loadedSongIds + const songIds = useMemo(() => songs.map((song) => song.id), [songs]) useEffect(() => { - rememberSongs(songs) - }, [songs]) + if (favorites) rememberSongs(favorites.songs) + }, [favorites]) const handlePlaySong = useCallback( (song: BrowseSong) => void playFromSong(song.id, songIds), @@ -88,11 +74,7 @@ export default function FavoritesScreen() { [handlePlaySong, handleSongMenuAction, isSongFavorite] ) - if ( - favorites === undefined || - (status === "LoadingFirstPage" && !isCached) || - !config - ) { + if (favorites === undefined || !config) { return ( <> @@ -125,10 +107,6 @@ export default function FavoritesScreen() { style={{ flex: 1, backgroundColor: colors.background }} contentContainerStyle={styles.listContent} contentInsetAdjustmentBehavior="automatic" - onEndReached={() => { - if (status === "CanLoadMore") loadMore(PAGE_SIZE) - }} - onEndReachedThreshold={0.5} ListHeaderComponent={