import { useState, useEffect } from 'react'; import Card from '@/components/ui/Card'; import Button from '@/components/ui/Button'; import Image from 'next/image'; import type { FeedItemDTO } from '@core/social/application/dto/FeedItemDTO'; function timeAgo(timestamp: Date | string): string { const date = typeof timestamp === 'string' ? new Date(timestamp) : timestamp; const diffMs = Date.now() - date.getTime(); const diffMinutes = Math.floor(diffMs / 60000); if (diffMinutes < 1) return 'Just now'; if (diffMinutes < 60) return `${diffMinutes} min ago`; const diffHours = Math.floor(diffMinutes / 60); if (diffHours < 24) return `${diffHours} h ago`; const diffDays = Math.floor(diffHours / 24); return `${diffDays} d ago`; } async function resolveActor(item: FeedItemDTO) { const driverRepo = getDriverRepository(); const imageService = getImageService(); const actorId = item.actorFriendId ?? item.actorDriverId; if (!actorId) { return null; } try { const driver = await driverRepo.findById(actorId); if (driver) { return { name: driver.name, avatarUrl: imageService.getDriverAvatar(driver.id), }; } } catch { // ignore and fall through to generic rendering } return null; } interface FeedItemCardProps { item: FeedItemDTO; } export default function FeedItemCard({ item }: FeedItemCardProps) { const [actor, setActor] = useState<{ name: string; avatarUrl: string } | null>(null); useEffect(() => { let cancelled = false; void (async () => { const resolved = await resolveActor(item); if (!cancelled) { setActor(resolved); } })(); return () => { cancelled = true; }; }, [item]); return (
{item.headline}
{item.body && ({item.body}
)}