-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use superlike weight for superlike toast
- Loading branch information
1 parent
0724a2e
commit 887b780
Showing
3 changed files
with
85 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import Toast from '@/components/Toast' | ||
import { cx } from '@/utils/class-names' | ||
import { QueryClient } from '@tanstack/react-query' | ||
import { ReactNode } from 'react' | ||
import { toast } from 'sonner' | ||
import { SubscribeSuperLikeSubscription } from '../generated-query' | ||
import { | ||
getAddressLikeCountToPostQuery, | ||
getSuperLikeCountQuery, | ||
getTodaySuperLikeCountQuery, | ||
} from './query' | ||
|
||
export function toastSuperLikeNotification( | ||
queryClient: QueryClient, | ||
eventData: SubscribeSuperLikeSubscription['activeStakingSuperLike'], | ||
myAddress: string | undefined | ||
) { | ||
const { post, staker } = eventData.entity | ||
getSuperLikeCountQuery.invalidate(queryClient, post.persistentId) | ||
if (staker.id === myAddress && post.persistentId) { | ||
getAddressLikeCountToPostQuery.invalidate(queryClient, { | ||
address: myAddress, | ||
postId: post.persistentId, | ||
}) | ||
const todayLike = getTodaySuperLikeCountQuery.getQueryData( | ||
queryClient, | ||
myAddress | ||
) | ||
const remaining = 10 - todayLike.count | ||
let desc: ReactNode = | ||
'Great progress today! You used all the available likes. Come back tomorrow 😉' | ||
let icon: ((className: string) => ReactNode) | undefined = (className) => ( | ||
<span | ||
className={cx(className, 'relative top-px mr-1.5 self-start text-base')} | ||
> | ||
✅ | ||
</span> | ||
) | ||
if (remaining > 0) { | ||
desc = ( | ||
<div> | ||
<p> | ||
You earned 💎 {eventData.meta.stakerDistributedRewardPoints} Points | ||
for liking the meme. | ||
</p> | ||
<p className='text-text-muted'> | ||
{remaining} more likes left for today | ||
</p> | ||
</div> | ||
) | ||
icon = (className) => ( | ||
<span | ||
className={cx( | ||
className, | ||
'relative top-px mr-1.5 self-start text-base' | ||
)} | ||
> | ||
ℹ️ | ||
</span> | ||
) | ||
} | ||
toast.custom((t) => <Toast t={t} title={desc} icon={icon} />) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters