Skip to content

Commit

Permalink
Disable play button if all collection tracks deleted (#7743)
Browse files Browse the repository at this point in the history
Co-authored-by: Saliou Diallo <saliou@audius.co>
  • Loading branch information
sddioulde and Saliou Diallo authored Feb 29, 2024
1 parent 5f28d5d commit 557142b
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
collectionPageLineupActions as tracksActions,
collectionPageSelectors,
reachabilitySelectors,
playerSelectors
playerSelectors,
cacheTracksSelectors
} from '@audius/common/store'
import { formatSecondsAsText, removeNullable } from '@audius/common/utils'
import type { Maybe } from '@audius/common/utils'
Expand All @@ -32,6 +33,7 @@ const { getPlaying, getUid, getCurrentTrack } = playerSelectors
const { getIsReachable } = reachabilitySelectors
const { getCollectionTracksLineup } = collectionPageSelectors
const { getCollection } = cacheCollectionsSelectors
const { getTracks } = cacheTracksSelectors

const selectTrackUids = createSelector(
(state: AppState) => getCollectionTracksLineup(state).entries,
Expand Down Expand Up @@ -233,6 +235,14 @@ export const CollectionScreenDetailsTile = ({
const numericCollectionId =
typeof collectionId === 'number' ? collectionId : undefined

const uids = isLineupLoading ? Array(Math.min(5, trackCount ?? 0)) : trackUids
const tracks = useSelector((state) => getTracks(state, { uids }))
const areAllTracksDeleted = Object.values(tracks).every(
(track) => track.is_delete
)
const isPlayable =
!areAllTracksDeleted && (isQueued || (trackCount > 0 && !!firstTrack))

const renderTrackList = useCallback(() => {
return (
<TrackList
Expand All @@ -242,7 +252,7 @@ export const CollectionScreenDetailsTile = ({
showSkeleton={isLineupLoading}
togglePlay={handlePressTrackListItemPlay}
isAlbumPage={isAlbum}
uids={isLineupLoading ? Array(Math.min(5, trackCount ?? 0)) : trackUids}
uids={uids}
ListEmptyComponent={
isLineupLoading ? null : (
<Text fontSize='medium' weight='medium' style={styles.empty}>
Expand All @@ -258,14 +268,11 @@ export const CollectionScreenDetailsTile = ({
handlePressTrackListItemPlay,
isLineupLoading,
styles,
trackUids,
trackCount,
uids,
isOwner,
messages
])

const isPlayable = isQueued || (trackCount > 0 && !!firstTrack)

return (
<DetailsTile
{...detailsTileProps}
Expand Down

0 comments on commit 557142b

Please sign in to comment.