@@ -8,18 +8,22 @@ import HeartIcon from '../_svg/heart-icon'
88import { api } from '~/trpc/react'
99import { useRouter } from 'next/navigation'
1010import { useState } from 'react'
11+ import { LikedBy } from './liked-by'
12+ import { type RouterOutputs } from '~/trpc/shared'
1113
1214export const MAX_LIKED_BY_SHOWN = 50
1315
1416type LikeButtonProps = {
1517 likeCount : number
1618 isLikedByCurrentUser : boolean
19+ likedBy : RouterOutputs [ 'post' ] [ 'detail' ] [ 'likedBy' ]
1720 id : number
1821}
1922
2023export const ReactionButton = ( {
2124 id,
2225 likeCount,
26+ likedBy,
2327 isLikedByCurrentUser,
2428} : LikeButtonProps ) => {
2529 const [ isAnimating , setIsAnimating ] = useState ( false )
@@ -50,53 +54,58 @@ export const ReactionButton = ({
5054 }
5155
5256 return (
53- < Button
54- variant = "secondary"
55- className = { classNames (
56- 'transition-colors overflow-hidden [transform:translateZ(0)] space-x-1.5' ,
57- {
58- 'border-red-300 !bg-red-100 dark:!bg-red-900 dark:border-red-700' :
59- isLikedByCurrentUser ,
60- '!border-red-600 !bg-red-600 dark:!bg-red-600' : isAnimating ,
61- } ,
62- ) }
63- onClick = { handleReaction }
64- disabled = { like . isLoading }
65- >
66- < span className = "relative block w-4 h-4 shrink-0" >
67- { isLikedByCurrentUser && ! isAnimating ? (
68- < HeartFilledIcon className = "absolute inset-0 text-red scale-1" />
69- ) : (
70- < >
71- < HeartIcon
72- className = { classNames (
73- 'absolute inset-0 transition-all text-red fill-transparent transform-gpu' ,
74- { 'scale-[12] fill-red-600' : isAnimating } ,
75- ) }
76- />
77- < span
78- className = { classNames (
79- 'absolute w-4 h-4 top-0 left-[-.5px] rounded-full ring-inset ring-6 ring-gray-50 transition-all duration-300 transform-gpu z-10' ,
80- isAnimating ? 'scale-150 !ring-0' : 'scale-0' ,
81- ) }
82- > </ span >
83- < HeartFilledIcon
84- className = { classNames (
85- 'absolute inset-0 transition-transform delay-200 duration-300 text-gray-50 transform-gpu z-10 ease-spring' ,
86- isAnimating ? 'scale-1' : 'scale-0' ,
87- ) }
88- />
89- </ >
90- ) }
91- </ span >
57+ < LikedBy
58+ likedBy = { likedBy }
59+ trigger = {
60+ < Button
61+ variant = "secondary"
62+ className = { classNames (
63+ 'transition-colors overflow-hidden [transform:translateZ(0)] space-x-1.5' ,
64+ {
65+ 'border-red-300 !bg-red-100 dark:!bg-red-900 dark:border-red-700' :
66+ isLikedByCurrentUser ,
67+ '!border-red-600 !bg-red-600 dark:!bg-red-600' : isAnimating ,
68+ } ,
69+ ) }
70+ onClick = { handleReaction }
71+ disabled = { like . isLoading }
72+ >
73+ < span className = "relative block w-4 h-4 shrink-0" >
74+ { isLikedByCurrentUser && ! isAnimating ? (
75+ < HeartFilledIcon className = "absolute inset-0 text-red scale-1" />
76+ ) : (
77+ < >
78+ < HeartIcon
79+ className = { classNames (
80+ 'absolute inset-0 transition-all text-red fill-transparent transform-gpu' ,
81+ { 'scale-[12] fill-red-600' : isAnimating } ,
82+ ) }
83+ />
84+ < span
85+ className = { classNames (
86+ 'absolute w-4 h-4 top-0 left-[-.5px] rounded-full ring-inset ring-6 ring-gray-50 transition-all duration-300 transform-gpu z-10' ,
87+ isAnimating ? 'scale-150 !ring-0' : 'scale-0' ,
88+ ) }
89+ > </ span >
90+ < HeartFilledIcon
91+ className = { classNames (
92+ 'absolute inset-0 transition-transform delay-200 duration-300 text-gray-50 transform-gpu z-10 ease-spring' ,
93+ isAnimating ? 'scale-1' : 'scale-0' ,
94+ ) }
95+ />
96+ </ >
97+ ) }
98+ </ span >
9299
93- < span
94- className = { classNames ( 'relative z-10 tabular-nums' , {
95- 'transition-colors duration-100 text-gray-50' : like . isLoading ,
96- } ) }
97- >
98- { likeCount }
99- </ span >
100- </ Button >
100+ < span
101+ className = { classNames ( 'relative z-10 tabular-nums' , {
102+ 'transition-colors duration-100 text-gray-50' : like . isLoading ,
103+ } ) }
104+ >
105+ { likeCount }
106+ </ span >
107+ </ Button >
108+ }
109+ />
101110 )
102111}
0 commit comments