11import { useState , useEffect } from 'react'
2+ import { usePostHog } from '@posthog/react'
23import type { FakePost } from '@/lib/data/fake-data'
34import cn from '@/lib/utils/cn'
45import { getLikedPosts , toggleLikedPost } from '@/lib/utils/localStorage'
@@ -10,6 +11,7 @@ interface PostCardProps {
1011export function PostCard ( { post } : PostCardProps ) {
1112 const [ liked , setLiked ] = useState ( false )
1213 const [ likes , setLikes ] = useState ( post . likes )
14+ const posthog = usePostHog ( )
1315
1416 useEffect ( ( ) => {
1517 const likedPosts = getLikedPosts ( )
@@ -19,17 +21,26 @@ export function PostCard({ post }: PostCardProps) {
1921 const handleLike = ( ) => {
2022 const newLikedState = toggleLikedPost ( post . id )
2123 setLiked ( newLikedState )
22- setLikes ( ( prev ) => ( prev + ( newLikedState ? 1 : - 1 ) ) )
24+ setLikes ( ( prev ) => prev + ( newLikedState ? 1 : - 1 ) )
25+
26+ if ( newLikedState ) {
27+ posthog ?. capture ( 'post_liked' , {
28+ post_id : post . id ,
29+ post_username : post . username ,
30+ post_verified : post . verified ,
31+ } )
32+ } else {
33+ posthog ?. capture ( 'post_unliked' , {
34+ post_id : post . id ,
35+ post_username : post . username ,
36+ } )
37+ }
2338 }
2439
2540 return (
2641 < div className = "bg-primary/5 border border-primary/20 rounded-lg p-4 mb-4" >
2742 < div className = "flex items-center gap-3 mb-3" >
28- < img
29- src = { post . avatar }
30- alt = { post . username }
31- className = "w-10 h-10 rounded-full"
32- />
43+ < img src = { post . avatar } alt = { post . username } className = "w-10 h-10 rounded-full" />
3344 < div className = "flex-1" >
3445 < div className = "flex items-center gap-2" >
3546 < span className = "font-bold text-primary" > { post . username } </ span >
@@ -47,21 +58,14 @@ export function PostCard({ post }: PostCardProps) {
4758
4859 { post . image && (
4960 < div className = "mb-3 rounded-lg overflow-hidden" >
50- < img
51- src = { post . image }
52- alt = "Post"
53- className = "w-full h-auto"
54- />
61+ < img src = { post . image } alt = "Post" className = "w-full h-auto" />
5562 </ div >
5663 ) }
5764
5865 < div className = "flex items-center gap-6 text-primary/70" >
5966 < button
6067 onClick = { handleLike }
61- className = { cn (
62- 'flex items-center gap-2 hover:text-accent transition' ,
63- liked && 'text-red-500'
64- ) }
68+ className = { cn ( 'flex items-center gap-2 hover:text-accent transition' , liked && 'text-red-500' ) }
6569 >
6670 < span className = "text-xl" > { liked ? '❤️' : '🤍' } </ span >
6771 < span className = "text-sm" >
@@ -84,4 +88,3 @@ export function PostCard({ post }: PostCardProps) {
8488 </ div >
8589 )
8690}
87-
0 commit comments