import Link from "next/link";
import { notFound } from "next/navigation";
import BrowseHeader from "@/components/BrowseHeader";
import ArticleTable, { articleHref } from "@/components/articles/ArticleTable";
import SiteChips from "@/components/articles/SiteChips";
import WorkspacePanel from "@/components/articles/WorkspacePanel";
import { badgeVariants } from "@/components/ui/badge";
import { readSiteRow, siteById } from "@/lib/articles/sites";
import { openWorkspaceFile, siteWorkspaceListings, takeTally } from "@/lib/articles/files";
import { videoProjects } from "@/lib/articles/links.mjs";
export const dynamic = "force-dynamic";
// One site: its articles, the videos they play, the umtool projects those
// videos were cut in (with their takes), and the workspace files the articles
// were written from. `?ws=&rel=` opens a workspace file below.
export default async function SitePage({
params,
searchParams,
}: {
params: Promise<{ site: string }>;
searchParams: Promise<{ ws?: string; rel?: string }>;
}) {
const { site: siteId } = await params;
const sp = await searchParams;
const site = siteById(siteId);
if (!site) notFound();
const row = await readSiteRow(site);
const projects = await videoProjects();
const linkedIds = [...new Set(row.articles.flatMap((a) => a.projects.linked.map((p) => p.id)))];
const linked = await Promise.all(
linkedIds.map(async (id) => {
const p = projects.find((x: { id: string }) => x.id === id) as { id: string; dir: string };
return { id: p.id, tally: await takeTally(p.dir), articles: row.articles.filter((a) => a.projects.linked.some((l) => l.id === id)) };
}),
);
const videos = row.articles.filter((a) => a.hasVideo);
const workspaces = await siteWorkspaceListings(site.siteId, row.articles.map((a) => a.id));
const opened = sp.ws && sp.rel ? await openWorkspaceFile(sp.ws, sp.rel) : null;
const hrefFor = (ws: string, rel: string) =>
`/sites/${site.siteId}?${new URLSearchParams({ ws, rel }).toString()}#files`;
const media = (id: string, file: string) =>
`/api/sites/media?site=${encodeURIComponent(site.siteId)}&report=${encodeURIComponent(id)}&file=${file}`;
return (
{row.title}
{row.siteId}
report videos {videos.length}
{videos.length === 0 ? (
none
) : (
{videos.map((a) => (
{a.title}
))}
)}
video projects {linked.length}
{linked.length === 0 ? (
none linked
) : (
{linked.map((p) => (
-
{p.id}
{p.articles.map((a) => a.title).join(", ")}
{p.tally.takes} takes
like {p.tally.like}
maybe {p.tally.maybe}
no {p.tally.no}
))}
)}
);
}