From b7123666387d3dd19e629002e9a2a478344a04f6 Mon Sep 17 00:00:00 2001 From: Nikki Kang Date: Tue, 14 Feb 2023 15:29:39 +0100 Subject: [PATCH] show downloaded collections only --- .../screens/favorites-screen/AlbumsTab.tsx | 23 +++++++++++-------- .../screens/favorites-screen/PlaylistsTab.tsx | 21 ++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/packages/mobile/src/screens/favorites-screen/AlbumsTab.tsx b/packages/mobile/src/screens/favorites-screen/AlbumsTab.tsx index 8ebafb383f..5c38f75f4b 100644 --- a/packages/mobile/src/screens/favorites-screen/AlbumsTab.tsx +++ b/packages/mobile/src/screens/favorites-screen/AlbumsTab.tsx @@ -14,7 +14,8 @@ import { useIsOfflineModeEnabled } from 'app/hooks/useIsOfflineModeEnabled' import type { AppState } from 'app/store' import { getOfflineTrackStatus, - getIsDoneLoadingFromDisk + getIsDoneLoadingFromDisk, + getOfflineCollectionsStatus } from 'app/store/offline-downloads/selectors' import { OfflineDownloadStatus } from 'app/store/offline-downloads/slice' @@ -37,7 +38,7 @@ export const AlbumsTab = () => { const isOfflineModeEnabled = useIsOfflineModeEnabled() const isDoneLoadingFromDisk = useSelector(getIsDoneLoadingFromDisk) - const offlineDownloadStatus = useProxySelector( + const offlineTracksStatus = useProxySelector( (state: AppState) => { if (isDoneLoadingFromDisk && isOfflineModeEnabled && !isReachable) { return getOfflineTrackStatus(state) @@ -55,6 +56,7 @@ export const AlbumsTab = () => { return [] } } + const offlineCollectionsStatus = getOfflineCollectionsStatus(state) return getAccountCollections(state, filterValue).filter((collection) => { if (!collection.is_album) { return false @@ -64,15 +66,18 @@ export const AlbumsTab = () => { collection.playlist_contents.track_ids.map( (trackData) => trackData.track ) ?? [] - - // Don't show a playlist in Offline Mode if it has at least one track but none of the tracks have been downloaded yet + const collectionDownloadStatus = + offlineCollectionsStatus[collection.playlist_id] + // Don't show a playlist in Offline Mode if it has at least one track but none of the tracks have been downloaded yet OR if it is not marked for download return ( collection.is_album && + Boolean(collectionDownloadStatus) && + collectionDownloadStatus !== OfflineDownloadStatus.INACTIVE && (trackIds.length === 0 || trackIds.some((t) => { return ( - offlineDownloadStatus && - offlineDownloadStatus[t.toString()] === + offlineTracksStatus && + offlineTracksStatus[t.toString()] === OfflineDownloadStatus.SUCCESS ) })) @@ -86,7 +91,7 @@ export const AlbumsTab = () => { isReachable, isOfflineModeEnabled, isDoneLoadingFromDisk, - offlineDownloadStatus + offlineTracksStatus ], shallowCompare ) @@ -95,9 +100,9 @@ export const AlbumsTab = () => { return buildCollectionIdsToNumPlayableTracksMap( userAlbums, isOfflineModeEnabled && !isReachable, - offlineDownloadStatus || {} + offlineTracksStatus || {} ) - }, [isOfflineModeEnabled, isReachable, offlineDownloadStatus, userAlbums]) + }, [isOfflineModeEnabled, isReachable, offlineTracksStatus, userAlbums]) return ( diff --git a/packages/mobile/src/screens/favorites-screen/PlaylistsTab.tsx b/packages/mobile/src/screens/favorites-screen/PlaylistsTab.tsx index 5365e4c1b2..be3ff48a25 100644 --- a/packages/mobile/src/screens/favorites-screen/PlaylistsTab.tsx +++ b/packages/mobile/src/screens/favorites-screen/PlaylistsTab.tsx @@ -16,6 +16,7 @@ import { useNavigation } from 'app/hooks/useNavigation' import type { AppState } from 'app/store' import { getIsDoneLoadingFromDisk, + getOfflineCollectionsStatus, getOfflineTrackStatus } from 'app/store/offline-downloads/selectors' import { OfflineDownloadStatus } from 'app/store/offline-downloads/slice' @@ -41,7 +42,7 @@ export const PlaylistsTab = () => { const isOfflineModeEnabled = useIsOfflineModeEnabled() const isReachable = useSelector(getIsReachable) const isDoneLoadingFromDisk = useSelector(getIsDoneLoadingFromDisk) - const offlineDownloadStatus = useProxySelector( + const offlineTracksStatus = useProxySelector( (state: AppState) => { if (isDoneLoadingFromDisk && isOfflineModeEnabled && !isReachable) { return getOfflineTrackStatus(state) @@ -59,6 +60,7 @@ export const PlaylistsTab = () => { return [] } } + const offlineCollectionsStatus = getOfflineCollectionsStatus(state) return getAccountCollections(state, filterValue).filter((collection) => { if (collection.is_album) { return false @@ -68,15 +70,18 @@ export const PlaylistsTab = () => { collection.playlist_contents.track_ids.map( (trackData) => trackData.track ) ?? [] - - // Don't show a playlist in Offline Mode if it has at least one track but none of the tracks have been downloaded yet + const collectionDownloadStatus = + offlineCollectionsStatus[collection.playlist_id] + // Don't show a playlist in Offline Mode if it has at least one track but none of the tracks have been downloaded yet OR if it is not marked for download return ( !collection.is_album && + Boolean(collectionDownloadStatus) && + collectionDownloadStatus !== OfflineDownloadStatus.INACTIVE && (trackIds.length === 0 || trackIds.some((t) => { return ( - offlineDownloadStatus && - offlineDownloadStatus[t.toString()] === + offlineTracksStatus && + offlineTracksStatus[t.toString()] === OfflineDownloadStatus.SUCCESS ) })) @@ -90,7 +95,7 @@ export const PlaylistsTab = () => { isReachable, isOfflineModeEnabled, isDoneLoadingFromDisk, - offlineDownloadStatus + offlineTracksStatus ], shallowCompare ) @@ -99,9 +104,9 @@ export const PlaylistsTab = () => { return buildCollectionIdsToNumPlayableTracksMap( userPlaylists, isOfflineModeEnabled && !isReachable, - offlineDownloadStatus || {} + offlineTracksStatus || {} ) - }, [isOfflineModeEnabled, isReachable, offlineDownloadStatus, userPlaylists]) + }, [isOfflineModeEnabled, isReachable, offlineTracksStatus, userPlaylists]) const handleNavigateToNewPlaylist = useCallback(() => { navigation.push('CreatePlaylist')