diff --git a/src/components/content-staking/SuperLike.tsx b/src/components/content-staking/SuperLike.tsx index 0c033f0d8..1c82e787e 100644 --- a/src/components/content-staking/SuperLike.tsx +++ b/src/components/content-staking/SuperLike.tsx @@ -179,36 +179,22 @@ export default function SuperLike({ }) => { if (superLikeCount <= 0 && !showWhenZero) return null const button = ( - // To make the post reward stat not jumping when its liked, maybe its a mac issue -
- -
+ { + sendEventWithRef(myAddress ?? '', (refId) => { + sendEvent( + 'click_superlike', + { eventSource: 'message', postId }, + { ref: refId } + ) + }) + handleClick() + }} + disabled={isDisabled} + /> ) return (
7 return { canBeLiked: !isPostMadeMoreThan1WeekAgo, isLoading } } + +export type SuperLikeButtonProps = ComponentProps<'button'> & { + superLikeCount: number + isMyMessage?: boolean + hasILiked?: boolean +} +export function SuperLikeButton({ + superLikeCount, + isMyMessage, + hasILiked, + ...props +}: SuperLikeButtonProps) { + return ( + // To make the post reward stat not jumping when its liked, maybe its a mac issue +
+ +
+ ) +} diff --git a/src/components/extensions/common/CommonChatItem.tsx b/src/components/extensions/common/CommonChatItem.tsx index f9b8ce7f5..601b52094 100644 --- a/src/components/extensions/common/CommonChatItem.tsx +++ b/src/components/extensions/common/CommonChatItem.tsx @@ -7,7 +7,9 @@ import MessageStatusIndicator from '@/components/chats/ChatItem/MessageStatusInd import RepliedMessagePreview from '@/components/chats/ChatItem/RepliedMessagePreview' import UnapprovedMemeCount from '@/components/chats/UnapprovedMemeCount' import { getRepliedMessageId } from '@/components/chats/utils' -import SuperLike from '@/components/content-staking/SuperLike' +import SuperLike, { + SuperLikeButton, +} from '@/components/content-staking/SuperLike' import useAuthorizedForModeration from '@/hooks/useAuthorizedForModeration' import useIsMessageBlocked from '@/hooks/useIsMessageBlocked' import { getSuperLikeCountQuery } from '@/services/datahub/content-staking/query' @@ -42,7 +44,7 @@ type CommonChatItemProps = ExtensionChatItemProps & { othersMessage?: OthersMessageConfig className?: string textColor?: string - bg?: 'background' | 'background-light' + bg?: 'background' | 'background-light' | 'background-lighter' showSuperLikeWhenZero?: boolean enableProfileModal?: boolean } @@ -70,6 +72,7 @@ export default function CommonChatItem({ hubId, bg = 'background', showApproveButton, + dummySuperLike, }: CommonChatItemProps) { const { inView, ref } = useInView() const myAddress = useMyMainAddress() @@ -194,7 +197,9 @@ export default function CommonChatItem({ ? 'bg-background-primary-light text-text dark:bg-background-primary/70 dark:text-text-on-primary' : bg === 'background' ? 'bg-background' - : 'bg-background-light', + : bg === 'background-light' + ? 'bg-background-light' + : 'bg-background-lighter', className )} > @@ -328,7 +333,15 @@ export default function CommonChatItem({ myMessageConfig.children === 'bottom' && childrenElement} - {showApproveButton ? ( + {dummySuperLike ? ( + + ) : showApproveButton ? (
) : message.struct.approvedInRootPost ? ( {({ isMyMessage }) => (
diff --git a/src/components/extensions/types.ts b/src/components/extensions/types.ts index e08e2df20..cb8b1126d 100644 --- a/src/components/extensions/types.ts +++ b/src/components/extensions/types.ts @@ -1,5 +1,6 @@ import { PostContent, PostData } from '@subsocial/api/types' import { ComponentType } from 'react' +import { SuperLikeButtonProps } from '../content-staking/SuperLike' export type ExtensionChatItemProps = { message: PostData @@ -8,8 +9,10 @@ export type ExtensionChatItemProps = { chatId: string hubId: string enableProfileModal?: boolean - bg?: 'background' | 'background-light' + bg?: 'background' | 'background-light' | 'background-lighter' showApproveButton?: boolean + className?: string + dummySuperLike?: SuperLikeButtonProps } export type RepliedMessagePreviewPartProps = { diff --git a/src/components/modals/LikeIntroModal.tsx b/src/components/modals/LikeIntroModal.tsx index 0bd306603..82cebe9b3 100644 --- a/src/components/modals/LikeIntroModal.tsx +++ b/src/components/modals/LikeIntroModal.tsx @@ -1,15 +1,105 @@ +import Diamond from '@/assets/emojis/diamond.png' import LikeButtonImage from '@/assets/graphics/like-button.png' -import LikeDemoImage from '@/assets/graphics/like-message.png' +import { getTokenomicsMetadataQuery } from '@/services/datahub/content-staking/query' import { useSendEvent } from '@/stores/analytics' import { LocalStorage } from '@/utils/storage' +import { formatNumber } from '@/utils/strings' +import { PostData } from '@subsocial/api/types' +import dayjs from 'dayjs' import Image from 'next/image' -import { useEffect, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' +import SlotCounter from 'react-slot-counter' import Button from '../Button' +import Card from '../Card' +import ImageChatItem from '../extensions/image/ImageChatItem' import Modal from './Modal' const hasOpenedModal = new LocalStorage(() => 'has-opened-like-intro-modal') +const DUMMY_MESSAGES: { message: PostData; superLikeCount: number }[] = [ + { + message: { + id: '0x123', + struct: { + id: '0x123', + createdAtBlock: 0, + createdAtTime: dayjs().subtract(1, 'day').toDate().getTime(), + createdByAccount: '0x123', + downvotesCount: 0, + hidden: false, + isComment: true, + isRegularPost: true, + isSharedPost: false, + ownerId: '0x123', + rootPostId: '0x123', + upvotesCount: 0, + }, + content: { + body: '', + canonical: '', + image: '', + isShowMore: false, + summary: '', + tags: [], + title: '', + extensions: [ + { + id: 'subsocial-image', + properties: { + image: + 'bafybeia2mhukwxqb4gifjs63sgtoc5flcskizemmamwwc3eq6q7ftihlo4', + }, + }, + ], + }, + }, + superLikeCount: 52, + }, + { + message: { + id: '0x123', + struct: { + id: '0x123', + createdAtBlock: 0, + createdAtTime: dayjs().subtract(1, 'day').toDate().getTime(), + createdByAccount: '0x123', + downvotesCount: 0, + hidden: false, + isComment: true, + isRegularPost: true, + isSharedPost: false, + ownerId: '0x123', + rootPostId: '0x123', + upvotesCount: 0, + }, + content: { + body: '', + canonical: '', + image: '', + isShowMore: false, + summary: '', + tags: [], + title: '', + extensions: [ + { + id: 'subsocial-image', + properties: { + image: + 'bafybeie3vdprrn4exypqyb36t3r3ua2jmv2fnh6oy5rh5knwcljij7q4h4', + }, + }, + ], + }, + }, + superLikeCount: 30, + }, +] export default function LikeIntroModal() { + const [step, setStep] = useState(0) + const [pointsEarned, setPointsEarned] = useState(0) + const [hasILiked, setHasILiked] = useState(false) + const { data: tokenomics } = getTokenomicsMetadataQuery.useQuery(null) + const sendEvent = useSendEvent() const [isOpenModal, setIsOpenModal] = useState(false) useEffect(() => { @@ -20,35 +110,108 @@ export default function LikeIntroModal() { } }, [sendEvent]) + const splitted = useMemo( + () => formatNumber(pointsEarned).split(''), + [pointsEarned] + ) + const current = DUMMY_MESSAGES[step] + + const pointsPerLike = tokenomics + ? (tokenomics.likerRewardDistributionPercent / 100) * + Number(tokenomics.superLikeWeightPoints) + : 4000 + + const isFinished = !current + return ( undefined} - title='Earn Points by liking memes!' + title={ + isFinished ? 'Good job! Keep liking!' : 'Earn Points by liking memes!' + } description={ - - To get your Points for liking a meme, simply tap on{' '} - {' '} - below the meme. - + isFinished ? null : ( + + To get your Points for liking a meme, simply tap on{' '} + {' '} + below the meme. + + ) } > - - + {isFinished ? ( +
+ + + For liking 2 memes you earned: + +
+ + + {formatNumber(pointsPerLike * DUMMY_MESSAGES.length)} + +
+
+ +
+ ) : ( + <> + { + if (hasILiked) return + + sendEvent('like_intro_modal_meme', { step: step + 1 }) + setHasILiked(true) + setPointsEarned((prev) => prev + pointsPerLike) + setTimeout(() => { + setStep((prev) => prev + 1) + setHasILiked(false) + }, 1000) + }, + }} + /> +
+ Points earned +
+ + + + +
+
+ + )}
) } diff --git a/src/modules/points/PointsPreview.tsx b/src/modules/points/PointsPreview.tsx index 792556d74..69e229531 100644 --- a/src/modules/points/PointsPreview.tsx +++ b/src/modules/points/PointsPreview.tsx @@ -33,6 +33,7 @@ function Points({ if (!withPointsAnimation) return {splitValues} + // Slot counter needs to be inside a span with font-bold and text-xl or bigger to work properly, otherwise, it will always rerender return (