1
- import { useCallback } from 'react'
1
+ import { useCallback , useMemo } from 'react'
2
2
3
- import { Name , BNAudio , ChallengeRewardID } from '@audius/common/models'
3
+ import {
4
+ BNAudio ,
5
+ ChallengeName ,
6
+ ChallengeRewardID ,
7
+ Name
8
+ } from '@audius/common/models'
4
9
import { ChallengeRewardNotification as ChallengeRewardNotificationType } from '@audius/common/store'
5
10
import {
6
11
formatNumberCommas ,
@@ -24,14 +29,22 @@ import { IconRewards } from './components/icons'
24
29
25
30
const { REWARDS_PAGE } = route
26
31
32
+ const formatNumber = ( amount : BNAudio ) => {
33
+ return formatNumberCommas ( Number ( amount . toString ( ) ) )
34
+ }
35
+
27
36
const messages = {
28
37
amountEarned : ( amount : BNAudio ) =>
29
- `You've earned ${ formatNumberCommas ( Number ( amount . toString ( ) ) ) } $AUDIO` ,
38
+ `You've earned ${ formatNumber ( amount ) } $AUDIO` ,
30
39
referredText :
31
40
' for being referred! Invite your friends to join to earn more!' ,
32
41
challengeCompleteText : ' for completing this challenge!' ,
33
42
twitterShareText :
34
- 'I earned $AUDIO for completing challenges on @audius #Audius #AudioRewards'
43
+ 'I earned $AUDIO for completing challenges on @audius #Audius #AudioRewards' ,
44
+ streakMilestone : ( amountEarned : number , listenStreak : number ) =>
45
+ `You've earned ${ amountEarned } $AUDIO for hitting Day ${ listenStreak } of your listening streak! You'll now earn an additional $AUDIO reward for every day you keep your streak going!` ,
46
+ streakMaintenance : ( amountEarned : number ) =>
47
+ `You've earned ${ amountEarned } $AUDIO for maintaining your listening streak! Keep your streak going to continue earning daily rewards!`
35
48
}
36
49
37
50
type ChallengeRewardNotificationProps = {
@@ -50,7 +63,7 @@ export const ChallengeRewardNotification = (
50
63
props : ChallengeRewardNotificationProps
51
64
) => {
52
65
const { notification } = props
53
- const { challengeId, timeLabel, isViewed, type } = notification
66
+ const { challengeId, timeLabel, isViewed, type, listenStreak } = notification
54
67
const dispatch = useDispatch ( )
55
68
const record = useRecord ( )
56
69
const mappedChallengeRewardsConfigKey =
@@ -65,17 +78,35 @@ export const ChallengeRewardNotification = (
65
78
)
66
79
} , [ dispatch , record , type ] )
67
80
81
+ const notificationTitle = useMemo ( ( ) => {
82
+ if ( challengeId === ChallengeName . ListenStreakEndless ) {
83
+ return `${ title } : Day ${ listenStreak } `
84
+ }
85
+ return title
86
+ } , [ challengeId , listenStreak , title ] )
87
+
88
+ const amountEarnedText = useMemo ( ( ) => {
89
+ switch ( challengeId ) {
90
+ case ChallengeName . ListenStreakEndless : {
91
+ const amountEarned = Number ( formatNumber ( amount ) )
92
+ if ( amountEarned > 1 ) {
93
+ return messages . streakMilestone ( amountEarned , listenStreak ?? 0 )
94
+ }
95
+ return messages . streakMaintenance ( amountEarned )
96
+ }
97
+ case 'referred' :
98
+ return messages . amountEarned ( amount ) + messages . referredText
99
+ default :
100
+ return messages . amountEarned ( amount ) + messages . challengeCompleteText
101
+ }
102
+ } , [ challengeId , amount , listenStreak ] )
103
+
68
104
return (
69
105
< NotificationTile notification = { notification } onClick = { handleClick } >
70
106
< NotificationHeader icon = { < IconRewards > { icon } </ IconRewards > } >
71
- < NotificationTitle > { title } </ NotificationTitle >
107
+ < NotificationTitle > { notificationTitle } </ NotificationTitle >
72
108
</ NotificationHeader >
73
- < NotificationBody >
74
- { messages . amountEarned ( amount ) }
75
- { challengeId === 'referred'
76
- ? messages . referredText
77
- : messages . challengeCompleteText }
78
- </ NotificationBody >
109
+ < NotificationBody > { amountEarnedText } </ NotificationBody >
79
110
< TwitterShareButton
80
111
type = 'static'
81
112
url = { env . AUDIUS_URL }
0 commit comments