"use client"; import { memo } from "react"; import { formatDistanceToNow, differenceInHours, differenceInMinutes, format, } from "date-fns"; import { GitBranch, ArrowRight, ListTodo } from "lucide-react"; import { ThreadWithTasks, useThreads } from "@/providers/Thread"; import { cn } from "@/lib/utils"; import { StatusIndicator } from "@/components/status-indicator"; import { GitHubSVG } from "./icons/github"; import { useQueryState } from "nuqs"; interface ThreadItemProps { thread: ThreadWithTasks; onClick: (thread: ThreadWithTasks) => void; variant?: "sidebar" | "dashboard"; className?: string; } function formatRelativeDate(dateString: string): string { const date = new Date(dateString); const now = new Date(); const minutesAgo = differenceInMinutes(now, date); const hoursAgo = differenceInHours(now, date); // Within the last hour - show minutes ago if (minutesAgo < 60) { return `${minutesAgo} min ago`; } // Between 1-24 hours ago - show hours ago if (hoursAgo < 24) { return `${hoursAgo} hour${hoursAgo === 1 ? "" : "s"} ago`; } // More than 24 hours ago - show month, day format return format(date, "MMM do"); } export const ThreadItem = memo(function ThreadItem({ thread, onClick, variant = "dashboard", className, }: ThreadItemProps) { const [threadId] = useQueryState("threadId"); const { recentlyUpdatedThreads } = useThreads(); const isSelected = thread.thread_id === threadId; const isSidebar = variant === "sidebar"; const isRecentlyUpdated = recentlyUpdatedThreads.has(thread.thread_id); const displayDate = formatRelativeDate(thread.created_at); return (