Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
show downloaded collections only
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoback committed Feb 14, 2023
1 parent 0f06a0d commit b712366
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
23 changes: 14 additions & 9 deletions packages/mobile/src/screens/favorites-screen/AlbumsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
Expand All @@ -55,6 +56,7 @@ export const AlbumsTab = () => {
return []
}
}
const offlineCollectionsStatus = getOfflineCollectionsStatus(state)
return getAccountCollections(state, filterValue).filter((collection) => {
if (!collection.is_album) {
return false
Expand All @@ -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
)
}))
Expand All @@ -86,7 +91,7 @@ export const AlbumsTab = () => {
isReachable,
isOfflineModeEnabled,
isDoneLoadingFromDisk,
offlineDownloadStatus
offlineTracksStatus
],
shallowCompare
)
Expand All @@ -95,9 +100,9 @@ export const AlbumsTab = () => {
return buildCollectionIdsToNumPlayableTracksMap(
userAlbums,
isOfflineModeEnabled && !isReachable,
offlineDownloadStatus || {}
offlineTracksStatus || {}
)
}, [isOfflineModeEnabled, isReachable, offlineDownloadStatus, userAlbums])
}, [isOfflineModeEnabled, isReachable, offlineTracksStatus, userAlbums])

return (
<VirtualizedScrollView listKey='favorites-albums-view'>
Expand Down
21 changes: 13 additions & 8 deletions packages/mobile/src/screens/favorites-screen/PlaylistsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -59,6 +60,7 @@ export const PlaylistsTab = () => {
return []
}
}
const offlineCollectionsStatus = getOfflineCollectionsStatus(state)
return getAccountCollections(state, filterValue).filter((collection) => {
if (collection.is_album) {
return false
Expand All @@ -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
)
}))
Expand All @@ -90,7 +95,7 @@ export const PlaylistsTab = () => {
isReachable,
isOfflineModeEnabled,
isDoneLoadingFromDisk,
offlineDownloadStatus
offlineTracksStatus
],
shallowCompare
)
Expand All @@ -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')
Expand Down

0 comments on commit b712366

Please sign in to comment.