fix(mobile): remove playlist pagination (#38)
This commit was merged in pull request #38.
This commit is contained in:
1 parent
55d5382ee6
commit
96c571cf36
2 files changed
+18
-78
No files matched your search
@@ -39,10 +39,7 @@ import { contentBottomInset, SongListRow } from "@/components/player"
|
|||||||
import { useFavorites } from "@/contexts/favorites"
|
import { useFavorites } from "@/contexts/favorites"
|
||||||
import { usePlaybackActions } from "@/contexts/playback"
|
import { usePlaybackActions } from "@/contexts/playback"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import {
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||||
useCachedPaginatedQuery,
|
|
||||||
useCachedQuery,
|
|
||||||
} from "@/hooks/use-cached-query"
|
|
||||||
import { useCoverPalette } from "@/hooks/use-cover-palette"
|
import { useCoverPalette } from "@/hooks/use-cover-palette"
|
||||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||||
import { api } from "@otunes/convex/_generated/api"
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
@@ -55,7 +52,6 @@ import { showError } from "@/lib/toast"
|
|||||||
import { playlistCoverUrl } from "@/lib/urls"
|
import { playlistCoverUrl } from "@/lib/urls"
|
||||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||||
|
|
||||||
const PAGE_SIZE = 50
|
|
||||||
const PLAYLIST_LABEL = "Add to Another Playlist"
|
const PLAYLIST_LABEL = "Add to Another Playlist"
|
||||||
const OWNER_MENU_ACTIONS: MediaAction[] = [
|
const OWNER_MENU_ACTIONS: MediaAction[] = [
|
||||||
"share",
|
"share",
|
||||||
@@ -74,27 +70,9 @@ export default function PlaylistScreen() {
|
|||||||
const playlistId = typeof id === "string" ? (id as Id<"playlists">) : null
|
const playlistId = typeof id === "string" ? (id as Id<"playlists">) : null
|
||||||
const playlist = useCachedQuery(
|
const playlist = useCachedQuery(
|
||||||
api.playlists.browsePlaylistDetail,
|
api.playlists.browsePlaylistDetail,
|
||||||
playlistId
|
playlistId ? { id: playlistId } : "skip"
|
||||||
? {
|
|
||||||
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"
|
|
||||||
)
|
)
|
||||||
|
const songs = playlist?.songs
|
||||||
const coverUri =
|
const coverUri =
|
||||||
config && playlistId
|
config && playlistId
|
||||||
? playlistCoverUrl(config.serverUrl, playlist?.id ?? playlistId)
|
? playlistCoverUrl(config.serverUrl, playlist?.id ?? playlistId)
|
||||||
@@ -106,15 +84,10 @@ export default function PlaylistScreen() {
|
|||||||
const { palette, onLayout } = useAndroidScreenPalette(artworkPalette)
|
const { palette, onLayout } = useAndroidScreenPalette(artworkPalette)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
rememberSongs(songs)
|
if (songs) rememberSongs(songs)
|
||||||
}, [songs])
|
}, [songs])
|
||||||
|
|
||||||
if (
|
if (playlist === undefined || !config || !settled) {
|
||||||
playlist === undefined ||
|
|
||||||
(status === "LoadingFirstPage" && !isCached) ||
|
|
||||||
!config ||
|
|
||||||
!settled
|
|
||||||
) {
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
@@ -150,13 +123,9 @@ export default function PlaylistScreen() {
|
|||||||
<PlaylistContent
|
<PlaylistContent
|
||||||
onLayout={onLayout}
|
onLayout={onLayout}
|
||||||
playlist={playlist}
|
playlist={playlist}
|
||||||
songs={songs}
|
songs={playlist.songs}
|
||||||
allSongIds={allSongIds}
|
|
||||||
coverUri={coverUri}
|
coverUri={coverUri}
|
||||||
palette={palette}
|
palette={palette}
|
||||||
onEndReached={() => {
|
|
||||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -165,18 +134,14 @@ function PlaylistContent({
|
|||||||
onLayout,
|
onLayout,
|
||||||
playlist,
|
playlist,
|
||||||
songs,
|
songs,
|
||||||
allSongIds,
|
|
||||||
coverUri,
|
coverUri,
|
||||||
palette,
|
palette,
|
||||||
onEndReached,
|
|
||||||
}: {
|
}: {
|
||||||
onLayout?: () => void
|
onLayout?: () => void
|
||||||
playlist: BrowsePlaylistDetail
|
playlist: BrowsePlaylistDetail
|
||||||
songs: BrowseSong[]
|
songs: BrowseSong[]
|
||||||
allSongIds: Id<"songs">[] | undefined
|
|
||||||
coverUri: string
|
coverUri: string
|
||||||
palette: CoverPalette
|
palette: CoverPalette
|
||||||
onEndReached: () => void
|
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const isFocused = useIsFocused()
|
const isFocused = useIsFocused()
|
||||||
@@ -192,8 +157,7 @@ function PlaylistContent({
|
|||||||
const playlistId = playlist.id
|
const playlistId = playlist.id
|
||||||
const isSubscribed = playlist.isSubscribed
|
const isSubscribed = playlist.isSubscribed
|
||||||
const canEdit = playlist.isOwner && playlistId !== null
|
const canEdit = playlist.isOwner && playlistId !== null
|
||||||
const loadedSongIds = useMemo(() => songs.map((song) => song.id), [songs])
|
const songIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||||
const songIds = allSongIds ?? loadedSongIds
|
|
||||||
const swipeGroup = useSwipeRowGroup()
|
const swipeGroup = useSwipeRowGroup()
|
||||||
|
|
||||||
const handlePlaySong = useCallback(
|
const handlePlaySong = useCallback(
|
||||||
@@ -226,12 +190,12 @@ function PlaylistContent({
|
|||||||
)
|
)
|
||||||
|
|
||||||
const handlePlay = useCallback(() => {
|
const handlePlay = useCallback(() => {
|
||||||
if (playlistId) void playPlaylist(playlistId, allSongIds)
|
if (playlistId) void playPlaylist(playlistId, songIds)
|
||||||
}, [allSongIds, playPlaylist, playlistId])
|
}, [playPlaylist, playlistId, songIds])
|
||||||
|
|
||||||
const handleShuffle = useCallback(() => {
|
const handleShuffle = useCallback(() => {
|
||||||
if (playlistId) void playPlaylistShuffled(playlistId, allSongIds)
|
if (playlistId) void playPlaylistShuffled(playlistId, songIds)
|
||||||
}, [allSongIds, playPlaylistShuffled, playlistId])
|
}, [playPlaylistShuffled, playlistId, songIds])
|
||||||
|
|
||||||
const handleSubscribeToggle = useCallback(async () => {
|
const handleSubscribeToggle = useCallback(async () => {
|
||||||
if (!playlistId) return
|
if (!playlistId) return
|
||||||
@@ -355,8 +319,6 @@ function PlaylistContent({
|
|||||||
indicatorStyle={palette.isDark ? "white" : "black"}
|
indicatorStyle={palette.isDark ? "white" : "black"}
|
||||||
contentContainerStyle={styles.listContent}
|
contentContainerStyle={styles.listContent}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
onEndReached={onEndReached}
|
|
||||||
onEndReachedThreshold={0.5}
|
|
||||||
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
<PlaylistHero
|
<PlaylistHero
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ import { contentBottomInset, SongListRow } from "@/components/player"
|
|||||||
import { useFavorites } from "@/contexts/favorites"
|
import { useFavorites } from "@/contexts/favorites"
|
||||||
import { usePlaybackActions } from "@/contexts/playback"
|
import { usePlaybackActions } from "@/contexts/playback"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import {
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||||
useCachedPaginatedQuery,
|
|
||||||
useCachedQuery,
|
|
||||||
} from "@/hooks/use-cached-query"
|
|
||||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||||
import { api } from "@otunes/convex/_generated/api"
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
import type { MediaAction } from "@/components/media-context-menu"
|
import type { MediaAction } from "@/components/media-context-menu"
|
||||||
@@ -29,32 +26,21 @@ import { radius, spacing, useThemeColors } from "@/lib/theme"
|
|||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
const PAGE_SIZE = 50
|
|
||||||
const SCREEN_OPTIONS = { title: "", headerLargeTitle: false }
|
const SCREEN_OPTIONS = { title: "", headerLargeTitle: false }
|
||||||
|
|
||||||
export default function FavoritesScreen() {
|
export default function FavoritesScreen() {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
const { config } = useServerConfig()
|
const { config } = useServerConfig()
|
||||||
const favorites = useCachedQuery(api.favorites.browseFavoritesSummary)
|
const favorites = useCachedQuery(api.favorites.browseFavoritesPlaylistDetail)
|
||||||
const {
|
const songs = favorites?.songs ?? []
|
||||||
results: songs,
|
|
||||||
status,
|
|
||||||
loadMore,
|
|
||||||
isCached,
|
|
||||||
} = useCachedPaginatedQuery(
|
|
||||||
api.favorites.browseFavoritesSongsPaginated,
|
|
||||||
{},
|
|
||||||
{ initialNumItems: PAGE_SIZE }
|
|
||||||
)
|
|
||||||
const { playInOrder, playShuffled, playFromSong } = usePlaybackActions()
|
const { playInOrder, playShuffled, playFromSong } = usePlaybackActions()
|
||||||
const { isSongFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const { handleSongAction } = useMediaMenuActions()
|
const { handleSongAction } = useMediaMenuActions()
|
||||||
const loadedSongIds = useMemo(() => songs.map((song) => song.id), [songs])
|
const songIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||||
const songIds = favorites?.songIds ?? loadedSongIds
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
rememberSongs(songs)
|
if (favorites) rememberSongs(favorites.songs)
|
||||||
}, [songs])
|
}, [favorites])
|
||||||
|
|
||||||
const handlePlaySong = useCallback(
|
const handlePlaySong = useCallback(
|
||||||
(song: BrowseSong) => void playFromSong(song.id, songIds),
|
(song: BrowseSong) => void playFromSong(song.id, songIds),
|
||||||
@@ -88,11 +74,7 @@ export default function FavoritesScreen() {
|
|||||||
[handlePlaySong, handleSongMenuAction, isSongFavorite]
|
[handlePlaySong, handleSongMenuAction, isSongFavorite]
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if (favorites === undefined || !config) {
|
||||||
favorites === undefined ||
|
|
||||||
(status === "LoadingFirstPage" && !isCached) ||
|
|
||||||
!config
|
|
||||||
) {
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen options={SCREEN_OPTIONS} />
|
<Stack.Screen options={SCREEN_OPTIONS} />
|
||||||
@@ -125,10 +107,6 @@ export default function FavoritesScreen() {
|
|||||||
style={{ flex: 1, backgroundColor: colors.background }}
|
style={{ flex: 1, backgroundColor: colors.background }}
|
||||||
contentContainerStyle={styles.listContent}
|
contentContainerStyle={styles.listContent}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
onEndReached={() => {
|
|
||||||
if (status === "CanLoadMore") loadMore(PAGE_SIZE)
|
|
||||||
}}
|
|
||||||
onEndReachedThreshold={0.5}
|
|
||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
<FavoritesHero
|
<FavoritesHero
|
||||||
title={favorites.title}
|
title={favorites.title}
|
||||||
|
|||||||
Reference in new issue
Block a user