diff --git a/src/components/BuildsPanel.tsx b/src/components/BuildsPanel.tsx index 910bf16..11f60fd 100644 --- a/src/components/BuildsPanel.tsx +++ b/src/components/BuildsPanel.tsx @@ -1,16 +1,16 @@ import { useMutation, useQuery } from "convex/react"; import { - Clock, CheckCircle, - XCircle, + Clock, Loader2, - Trash2, RotateCw, - ExternalLink, + Trash2, + XCircle, } from "lucide-react"; import { Link } from "react-router-dom"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; +import { timeAgo } from "@/lib/utils"; import { api } from "../../convex/_generated/api"; import type { Id } from "../../convex/_generated/dataModel"; @@ -84,77 +84,64 @@ export default function BuildsPanel({ profileId }: BuildsPanelProps) { } return ( -
-

Build History

- {builds.map((build) => ( -
-
+
+

Build Status

+
+ {builds.map((build) => ( +
{getStatusIcon(build.status)} - + {build.target} - + {build.status} + + {timeAgo(build.startedAt)} + -
+ +
{build.status === "failure" && ( )}
- - {build.logs && ( -
-							{build.logs.split("\n").slice(-5).join("\n")}
-						
- )} - -
- - View Details - - - {build.artifactUrl && ( - - Download Artifact → - - )} -
- -
- Started: {new Date(build.startedAt).toLocaleString()} -
-
- ))} + ))} +
); } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index ac680b3..ecff906 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -4,3 +4,29 @@ import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } + +export function timeAgo(date: number | string | Date): string { + const now = new Date(); + const past = new Date(date); + const msPerMinute = 60 * 1000; + const msPerHour = msPerMinute * 60; + const msPerDay = msPerHour * 24; + const msPerMonth = msPerDay * 30; + const msPerYear = msPerDay * 365; + + const elapsed = now.getTime() - past.getTime(); + + if (elapsed < msPerMinute) { + return `${Math.round(elapsed / 1000)}s ago`; + } else if (elapsed < msPerHour) { + return `${Math.round(elapsed / msPerMinute)}m ago`; + } else if (elapsed < msPerDay) { + return `${Math.round(elapsed / msPerHour)}h ago`; + } else if (elapsed < msPerMonth) { + return `${Math.round(elapsed / msPerDay)}d ago`; + } else if (elapsed < msPerYear) { + return `${Math.round(elapsed / msPerMonth)}mo ago`; + } else { + return `${Math.round(elapsed / msPerYear)}y ago`; + } +}