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

C-2119 Show downloaded collections only #2842

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor Author

@nicoback2 nicoback2 Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in this file and the other file are pretty much identical so working on another PR to decomp them

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