| 1 | import { CircleDot, GitMerge, Plus, XCircle } from "lucide-react"; |
| 2 | import { Link } from "react-router"; |
| 3 | |
| 4 | import type { Intent } from "@g1t/contracts"; |
| 5 | |
| 6 | import type { Route } from "./+types/intents"; |
| 7 | import { ButtonLink, EmptyState, TimeAgo } from "../../components/ui"; |
| 8 | import { work } from "../../lib/services.server"; |
| 9 | import { getViewer, unwrap } from "../../lib/session.server"; |
| 10 | |
| 11 | export function meta({ params }: Route.MetaArgs) { |
| 12 | return [{ title: `Intents · ${params.owner}/${params.repo} · g1t` }]; |
| 13 | } |
| 14 | |
| 15 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 16 | const path = { namespace: params.owner, name: params.repo }; |
| 17 | return { |
| 18 | intents: unwrap(await work.listIntents(path, getViewer(context))), |
| 19 | }; |
| 20 | } |
| 21 | |
| 22 | function StatusIcon({ status }: { status: Intent["status"] }) { |
| 23 | if (status === "shipped") return <GitMerge size={16} className="text-shipped" />; |
| 24 | if (status === "withdrawn") return <XCircle size={16} className="text-faint" />; |
| 25 | return <CircleDot size={16} className="text-accent" />; |
| 26 | } |
| 27 | |
| 28 | export default function Intents({ loaderData, params }: Route.ComponentProps) { |
| 29 | const { intents } = loaderData; |
| 30 | const base = `/${params.owner}/${params.repo}/intents`; |
| 31 | const open = intents.filter((intent) => intent.status === "open").length; |
| 32 | return ( |
| 33 | <div> |
| 34 | <div className="flex items-center justify-between gap-4"> |
| 35 | <p className="text-sm text-muted"> |
| 36 | <span className="font-medium text-fg">{open} open</span> |
| 37 | <span className="mx-2 text-faint">·</span> |
| 38 | {intents.length - open} closed |
| 39 | </p> |
| 40 | <ButtonLink to={`${base}/new`}> |
| 41 | <Plus size={15} /> |
| 42 | New intent |
| 43 | </ButtonLink> |
| 44 | </div> |
| 45 | <div className="mt-4"> |
| 46 | {intents.length === 0 ? ( |
| 47 | <EmptyState title="No intents yet"> |
| 48 | An intent is a goal for this repository. Agents attempt it in |
| 49 | parallel, each in its own fork. |
| 50 | </EmptyState> |
| 51 | ) : ( |
| 52 | <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line"> |
| 53 | {intents.map((intent) => ( |
| 54 | <li key={intent.id}> |
| 55 | <Link |
| 56 | to={`${base}/${intent.number}`} |
| 57 | className="flex items-center gap-3 px-4 py-3 transition-colors hover:bg-surface" |
| 58 | > |
| 59 | <StatusIcon status={intent.status} /> |
| 60 | <span className="min-w-0 grow"> |
| 61 | <span className="block truncate font-medium"> |
| 62 | {intent.title} |
| 63 | </span> |
| 64 | <span className="text-xs text-faint"> |
| 65 | #{intent.number} opened <TimeAgo at={intent.createdAt} /> by{" "} |
| 66 | {intent.author.username} |
| 67 | </span> |
| 68 | </span> |
| 69 | {/* One dot per attempt: the lanes at a glance. */} |
| 70 | <span className="flex shrink-0 items-center gap-1" aria-hidden="true"> |
| 71 | {Array.from({ length: Math.min(intent.attemptCount, 12) }, (_, i) => ( |
| 72 | <span key={i} className="size-1.5 rounded-full bg-accent-dim" /> |
| 73 | ))} |
| 74 | </span> |
| 75 | <span className="w-20 shrink-0 text-right text-xs text-muted"> |
| 76 | {intent.attemptCount}{" "} |
| 77 | {intent.attemptCount === 1 ? "attempt" : "attempts"} |
| 78 | </span> |
| 79 | </Link> |
| 80 | </li> |
| 81 | ))} |
| 82 | </ul> |
| 83 | )} |
| 84 | </div> |
| 85 | </div> |
| 86 | ); |
| 87 | } |