Skip to content
Draft
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
9 changes: 8 additions & 1 deletion packages/common/src/hooks/useShareContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const useShareContent = (
request: ShareModalRequest | null
): ShareContent | null => {
const trackId =
request?.type === 'track' || request?.type === 'contest'
request?.type === 'track' ||
request?.type === 'contest' ||
request?.type === 'milestone'
? request.trackId
: null
const profileId = request?.type === 'profile' ? request.profileId : null
Expand All @@ -36,6 +38,11 @@ export const useShareContent = (
return { type: request.type, track, artist: trackArtist }
}

if (request.type === 'milestone') {
if (!track || !trackArtist) return null
return { type: 'milestone', track, artist: trackArtist, stat: request.stat }
}

if (request.type === 'profile') {
if (!profile) return null
return { type: 'profile', profile }
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/models/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ export enum ShareSource {
NOW_PLAYING = 'now playing',
OVERFLOW = 'overflow',
LEFT_NAV = 'left-nav',
UPLOAD = 'upload'
UPLOAD = 'upload',
NOTIFICATION = 'notification'
}
export enum RepostSource {
TILE = 'tile',
Expand Down
12 changes: 12 additions & 0 deletions packages/common/src/store/notifications/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ export type MilestoneListenPushNotification = {
entityId: ID
slot: number
type: PushNotificationType.MilestoneListen
/** Set on pushes that should open the milestone stat card */
shareCard?: boolean
threshold?: number
metadata: {
threshold: number
entity_type: Entity
Expand All @@ -362,6 +365,9 @@ export type MilestoneRepostPushNotification = {
entityId: ID
slot: number
type: PushNotificationType.MilestoneRepost
/** Set on pushes that should open the milestone stat card */
shareCard?: boolean
threshold?: number
metadata: {
threshold: number
entity_type: Entity
Expand All @@ -381,6 +387,9 @@ export type MilestoneFavoritePushNotification = {
entityId: ID
slot: number
type: PushNotificationType.MilestoneFavorite
/** Set on pushes that should open the milestone stat card */
shareCard?: boolean
threshold?: number
metadata: {
threshold: number
entity_type: Entity
Expand Down Expand Up @@ -456,6 +465,9 @@ export type TrendingTrackNotification = BaseNotification & {
entityId: ID
}

/** Trending pushes carry `shareCard` when tapping should open the stat card */
export type TrendingPushFields = { shareCard?: boolean }

export type TrendingUndergroundNotification = BaseNotification & {
type: NotificationType.TrendingUnderground
rank: number
Expand Down
18 changes: 18 additions & 0 deletions packages/common/src/store/ui/share-modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ShareType =
| 'playlist'
| 'contest'
| 'weeklyRotation'
| 'milestone'

type ShareTrackContent = {
type: 'track'
Expand Down Expand Up @@ -61,20 +62,37 @@ type ShareWeeklyRotationContent = {
user: User
}

export type ShareMilestoneStat =
| { kind: 'listens' | 'reposts' | 'favorites'; count: number }
| { kind: 'trending' | 'underground'; rank: number }

/**
* A track milestone (play count, trending rank) shared as a stat card.
* Links to the track like a track share.
*/
type ShareMilestoneContent = {
type: 'milestone'
track: Track
artist: User
stat: ShareMilestoneStat
}

export type ShareContent =
| ShareTrackContent
| ShareContestContent
| ShareProfileContent
| ShareAlbumContent
| SharePlaylistContent
| ShareWeeklyRotationContent
| ShareMilestoneContent

export type ShareModalRequest =
| { type: 'track'; trackId: ID }
| { type: 'contest'; trackId: ID }
| { type: 'profile'; profileId: ID }
| { type: 'collection'; collectionId: ID }
| { type: 'weeklyRotation'; userId: ID }
| { type: 'milestone'; trackId: ID; stat: ShareMilestoneStat }

export type ShareModalState = {
source: Nullable<ShareSource>
Expand Down
39 changes: 25 additions & 14 deletions packages/mobile/src/components/share-drawer/ShareDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { Text } from '../core'
import { ShareToStorySticker } from './ShareToStorySticker'
import { messages } from './messages'
import { useShareToStory } from './useShareToStory'
import { getContentUrl, getXShareUrl } from './utils'
import { getContentUrl, getStatHeadline, getXShareUrl } from './utils'

const { getShareRequest, getShareSource } = shareModalUISelectors
const { shareUser } = usersSocialActions
Expand Down Expand Up @@ -99,8 +99,10 @@ export const ShareDrawer = NiceModal.create(() => {
content?.type === 'track' && accountUserId === content.artist.user_id
const shareType = content?.type ?? 'track'

const isStreamGatedTrack =
content?.type === 'track' && content.track.is_stream_gated
// Content whose track can be rendered into a story
const storyContent =
content?.type === 'track' || content?.type === 'milestone' ? content : null
const isStreamGatedTrack = !!storyContent?.track.is_stream_gated

const handleShareToDirectMessage = useCallback(async () => {
if (!content) return
Expand All @@ -112,7 +114,7 @@ export const ShareDrawer = NiceModal.create(() => {
make({
eventName: Name.CHAT_ENTRY_POINT,
source: 'share',
kind: content.type
kind: content.type === 'milestone' ? 'track' : content.type
})
)
if (source === ShareSource.NOW_PLAYING) {
Expand Down Expand Up @@ -178,6 +180,7 @@ export const ShareDrawer = NiceModal.create(() => {
if (!source || !content) return
switch (content.type) {
case 'track':
case 'milestone':
dispatch(shareTrack(content.track.track_id, source))
break
case 'profile':
Expand Down Expand Up @@ -215,11 +218,11 @@ export const ShareDrawer = NiceModal.create(() => {
// Story sharing renders the track's audio, so skip tracks the API marks
// unstreamable (undefined = not populated).
const isShareableTrack =
content?.type === 'track' &&
!content.track.is_unlisted &&
!content.track.is_invalid &&
!content.track.is_delete &&
content.track.is_streamable !== false &&
!!storyContent &&
!storyContent.track.is_unlisted &&
!storyContent.track.is_invalid &&
!storyContent.track.is_delete &&
storyContent.track.is_streamable !== false &&
!isStreamGatedTrack

const performActionAndClose = useCallback(
Expand Down Expand Up @@ -287,7 +290,10 @@ export const ShareDrawer = NiceModal.create(() => {
result.push(shareToInstagramStoriesAction)
result.push(shareVideoToTiktokAction)
result.push(shareToSnapchatAction)
} else if (content?.type === 'weeklyRotation') {
} else if (
content?.type === 'weeklyRotation' ||
content?.type === 'milestone'
) {
// Story/video shares need a single track; X only needs the link.
result.push(shareToXAction)
}
Expand All @@ -314,6 +320,7 @@ export const ShareDrawer = NiceModal.create(() => {
if (!content) return
switch (content.type) {
case 'track':
case 'milestone':
sendShareAction(content.track.track_id, 'track')
break
case 'album':
Expand All @@ -326,19 +333,23 @@ export const ShareDrawer = NiceModal.create(() => {

return (
<>
{/* Redundant `content?.type === 'track'` needed to make TS happy */}
{content?.type === 'track' ? (
{storyContent ? (
<ViewShot
style={styles.viewShot}
ref={viewShotRef}
options={{ format: 'png', useRenderInContext: true }}
>
<ShareToStorySticker
onLoad={handleShareToStoryStickerLoad}
track={content?.track}
artist={content?.artist}
track={storyContent.track}
artist={storyContent.artist}
omitLogo={selectedPlatform === 'tiktok'}
artworkSource={stickerArtworkSource}
headline={
storyContent.type === 'milestone'
? getStatHeadline(storyContent.stat)
: undefined
}
/>
</ViewShot>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type ShareToStoryStickerProps = {
* When provided, use this instead of TrackImage so the sticker always has a working image URL for capture.
*/
artworkSource?: ImageSourcePropType
/** Stat shown above the artwork for milestone cards, e.g. 1,000 / Plays */
headline?: { value: string; label: string }
}

const useStyles = makeStyles(({ palette, spacing }) => ({
Expand All @@ -49,6 +51,16 @@ const useStyles = makeStyles(({ palette, spacing }) => ({
paddingHorizontal: spacing(3),
borderRadius: 8
},
headline: {
alignItems: 'center',
marginBottom: spacing(3)
},
headlineValue: {
lineHeight: 64
},
headlineLabel: {
letterSpacing: 1
},
trackImage: {
height: 240,
width: 240,
Expand Down Expand Up @@ -89,14 +101,43 @@ export const ShareToStorySticker = ({
style,
onLoad,
omitLogo = false,
artworkSource
artworkSource,
headline
}: ShareToStoryStickerProps) => {
const styles = useStyles()

const { neutralLight2 } = useThemeColors()
return (
<View style={[styles.container, style]}>
<View>
{headline ? (
<View style={styles.headline}>
<Text
color='staticNeutral'
allowFontScaling={false}
weight='heavy'
fontSize='xxxxxl'
noGutter
numberOfLines={1}
adjustsFontSizeToFit
style={styles.headlineValue}
>
{headline.value}
</Text>
<Text
color='staticNeutral'
allowFontScaling={false}
weight='bold'
fontSize='medium'
textTransform='uppercase'
noGutter
numberOfLines={1}
style={styles.headlineLabel}
>
{headline.label}
</Text>
</View>
) : null}
{artworkSource != null ? (
<Artwork
source={artworkSource}
Expand Down
24 changes: 23 additions & 1 deletion packages/mobile/src/components/share-drawer/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const shareTypeMap: Record<ShareType, string> = {
album: 'Album',
playlist: 'Playlist',
contest: 'Contest',
weeklyRotation: 'Weekly Rotation'
weeklyRotation: 'Weekly Rotation',
milestone: 'Milestone'
}

export const messages = {
Expand All @@ -33,6 +34,27 @@ export const messages = {
`Check out ${albumName} by ${handle} @audius $AUDIO`,
playlistShareText: (playlistName: string, handle: string) =>
`Check out ${playlistName} by ${handle} @audius $AUDIO`,
milestoneCountLabel: {
listens: 'Plays',
reposts: 'Reposts',
favorites: 'Favorites'
},
milestoneRankLabel: {
trending: 'On Trending',
underground: 'On Underground Trending'
},
milestoneCountShareText: (
title: string,
count: string,
label: string,
handle: string
) => `${title} by ${handle} just hit ${count} ${label} on @audius $AUDIO`,
milestoneRankShareText: (
title: string,
rank: number,
label: string,
handle: string
) => `${title} by ${handle} is #${rank} ${label} on @audius $AUDIO`,
weeklyRotationShareText: (handle: string) =>
`Check out ${handle}'s Weekly Rotation on @audius $AUDIO`,
loadingStoryModalTitle: 'Generating Story',
Expand Down
Loading
Loading