Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAY-3036] Fix mobile header labels for premium content #8520

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useEffect } from 'react'

import { useGetCurrentUserId, useGetPlaylistById } from '@audius/common/api'
import { Name, PlaybackSource, Status } from '@audius/common/models'
import type {
SmartCollectionVariant,
Expand Down Expand Up @@ -97,11 +98,14 @@ const useRefetchLineupOnTrackAdd = (
}, [previousTrackCount, trackCount, dispatch])
}

const getMessages = (collectionType: 'album' | 'playlist') => ({
const getMessages = (
collectionType: 'album' | 'playlist',
isPremium = false
) => ({
empty: `This ${collectionType} is empty. Start adding tracks to share it or make it public.`,
emptyPublic: `This ${collectionType} is empty`,
detailsPlaceholder: '---',
collectionType,
collectionType: `${isPremium ? 'premium ' : ''}${collectionType}`,
hiddenType: `Hidden ${collectionType}`
})

Expand Down Expand Up @@ -170,6 +174,19 @@ export const CollectionScreenDetailsTile = ({

const isReachable = useSelector(getIsReachable)

const { data: currentUserId } = useGetCurrentUserId({})
// Since we're supporting SmartCollections, need to explicitly check that
// collectionId is a number before fetching the playlist. -1 is a placeholder,
// the request should not go out as the hook is disabled in that case.
const { data: collection } = useGetPlaylistById(
{
playlistId: typeof collectionId === 'number' ? collectionId : -1,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not quite following, whats the scenario for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CollectionId could be a SmartCollectionVariant in which case we don't want to do anything. Ideally these cases would be split out into different components.

Screenshot 2024-05-16 at 3 50 09 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

  • Would be nice to include a comment here explaining why the special number
  • Worth mentioning we could update the useGetPlaylistById() hook to support the special IDs and return something compatible here (if that makes sense)
  • Agreed that it should be separate code paths for the two types. Taking a "collectionId" that isn't actually an ID is code smell.

currentUserId
},
{ disabled: typeof collectionId !== 'number' }
)
const isStreamGated = collection?.is_stream_gated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This won't always resolve to a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wdym? collection could be undefined at this point

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, so isStreamGated wouldn't be true/false, it'll be undefined.


const trackUids = useSelector(selectTrackUids)
const collectionTrackCount = useSelector(selectTrackCount)
const trackCount = trackCountProp ?? collectionTrackCount
Expand All @@ -182,7 +199,7 @@ export const CollectionScreenDetailsTile = ({
const playingTrack = useSelector(getCurrentTrack)
const playingTrackId = playingTrack?.track_id
const firstTrack = useSelector(selectFirstTrack)
const messages = getMessages(isAlbum ? 'album' : 'playlist')
const messages = getMessages(isAlbum ? 'album' : 'playlist', isStreamGated)
useRefetchLineupOnTrackAdd(collectionId)

const play = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const messages = {
hiddenTrack: 'hidden track',
collectibleGated: 'collectible gated',
specialAccess: 'special access',
usdcPurchase: 'premium track',
premiumTrack: 'premium track',
generatedWithAi: 'generated with ai',
trackDeleted: 'track [deleted by artist]'
}
Expand Down Expand Up @@ -304,7 +304,13 @@ export const TrackScreenDetailsTile = ({
streamConditions={streamConditions}
user={user}
renderBottomContent={renderBottomContent}
headerText={isRemix ? messages.remix : messages.track}
headerText={
isRemix
? messages.remix
: isStreamGated
? messages.premiumTrack
: messages.track
}
hideFavorite={hideFavorite}
hideRepost={hideRepost}
hideShare={(is_unlisted && !isOwner) || !field_visibility?.share}
Expand Down