// components/social/SocialPost.tsx import React from 'react'; import { View, TouchableOpacity } from 'react-native'; import { Text } from '@/components/ui/text'; import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; import { Badge } from '@/components/ui/badge'; import { Heart, MessageSquare, Repeat, Share2, Zap, Clock, Dumbbell, CheckCircle } from 'lucide-react-native'; import { cn } from '@/lib/utils'; // Type definition for a social post interface PostAuthor { name: string; handle: string; avatar: string; pubkey: string; verified?: boolean; } interface WorkoutInfo { title: string; exercises: string[]; duration?: number; isProgramPreview?: boolean; } interface PostMetrics { likes: number; comments: number; reposts: number; zaps?: number; } interface SocialPostProps { post: { id: string; author: PostAuthor; content: string; createdAt: Date; metrics: PostMetrics; workout?: WorkoutInfo; featured?: boolean; }; } export default function SocialPost({ post }: SocialPostProps) { const [liked, setLiked] = React.useState(false); const [reposted, setReposted] = React.useState(false); const formatDate = (date: Date) => { const now = new Date(); const diffInHours = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60)); if (diffInHours < 1) { return 'now'; } else if (diffInHours < 24) { return `${diffInHours}h`; } else { const diffInDays = Math.floor(diffInHours / 24); return `${diffInDays}d`; } }; const formatDuration = (minutes: number) => { if (minutes < 60) { return `${minutes}m`; } else { const hours = Math.floor(minutes / 60); const mins = minutes % 60; return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`; } }; return ( {/* Author info */} {post.author.name.substring(0, 2)} {post.author.name} {post.author.verified && ( )} @{post.author.handle} ยท {formatDate(post.createdAt)} {post.author.pubkey.substring(0, 10)}... {/* Post content */} {post.content} {/* Workout card - slimmer version */} {post.workout && ( {post.workout.title} {post.workout.isProgramPreview ? ( Program ) : ( post.workout.exercises.map((ex, index) => ( {ex} )) )} {post.workout.duration && ( {formatDuration(post.workout.duration)} )} )} {/* Action buttons */} {/* Comment button */} {post.metrics.comments > 0 && ( {post.metrics.comments} )} {/* Repost button */} setReposted(!reposted)} > {(reposted || post.metrics.reposts > 0) && ( {reposted ? post.metrics.reposts + 1 : post.metrics.reposts} )} {/* Like button */} setLiked(!liked)} > {(liked || post.metrics.likes > 0) && ( {liked ? post.metrics.likes + 1 : post.metrics.likes} )} {/* Zap button */} {post.metrics.zaps && post.metrics.zaps > 0 && ( {post.metrics.zaps} )} {/* Share button */} ); }