Skip to content
49 linesCodeBlameRaw
1import type { Folio } from "@g1t/contracts";
2import { AlertTriangle } from "lucide-react";
3import { data } from "react-router";
4
5import type { Route } from "./+types/stale";
6import { useViewerZone } from "../../../components/folios/actions";
7import { FolioDays } from "../../../components/folios/list";
8import { EmptyState } from "../../../components/ui";
9import { page } from "../../../lib/meta";
10import { folios } from "../../../lib/services.server";
11import { requireUser, roleIn } from "../../../lib/session.server";
12
13export function meta({ params, ...args }: Route.MetaArgs) {
14 return page(args, { title: `Possibly out of date · Artifacts · ${params.owner} · g1t` });
15}
16
17/** The most recently edited artifacts looked through for ones marked possibly out of date. */
18const LOOK_AT = 100;
19
20export async function loader({ params, context, request }: Route.LoaderArgs): Promise<{ items: Folio[] | null }> {
21 const viewer = requireUser(context, request);
22 if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 });
23 const found = await folios.list(params.owner.toLowerCase(), viewer, { tab: "all", limit: LOOK_AT }).catch(() => null);
24 return { items: found?.ok ? found.value.items.filter((f) => f.stale) : null };
25}
26
27/** Artifacts whose cited code changed since someone last marked them current. */
28export default function FoliosStale({ loaderData, params }: Route.ComponentProps) {
29 const slug = params.owner.toLowerCase();
30 const zone = useViewerZone();
31 const { items } = loaderData;
32 return (
33 <div className="mx-auto max-w-5xl">
34 <h1 className="flex items-center gap-2 text-xl font-semibold tracking-tight">
35 <AlertTriangle size={18} className="text-warn" /> Possibly out of date
36 </h1>
37 <p className="mt-1 text-sm text-muted">A merged pull request or a push to a default branch changed code these artifacts cite. Read what changed, update it (or ask an agent to), then mark it current.</p>
38 <div className="mt-6">
39 {items === null ? (
40 <EmptyState title="Artifacts didn't answer">Try again in a moment.</EmptyState>
41 ) : items.length === 0 ? (
42 <EmptyState title="Everything is current">Nothing you can open cites code that changed since it was last checked.</EmptyState>
43 ) : (
44 <FolioDays slug={slug} items={items} zone={zone} />
45 )}
46 </div>
47 </div>
48 );
49}