peppa/apps/web/components/ActivityAside.tsx
Асель 1b0f6063cb Merge main into task/pep-98: PEP-94/97/100/101/102 texts through the dictionary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:11:59 +05:00

67 lines
3.4 KiB
TypeScript

import Link from "next/link";
import { ago } from "@/components/common";
import { requireUser } from "@/lib/auth";
import { activeSessions, inbox } from "@/lib/queries";
import { SESSION_STATUS, TONE_BG } from "@/lib/status";
import { cn } from "@/lib/utils";
import { getT } from "@/lib/i18n";
/** Default right panel: what waits for the PM and what is running now. */
export async function ActivityAside({ questions = true }: { questions?: boolean }) {
const user = await requireUser();
const t = await getT();
const [items, sessions] = await Promise.all([questions ? inbox(user.id) : [], activeSessions(user.id)]);
return (
<div className="flex flex-col gap-6">
{questions && (
<PanelSection title={t("Ждут тебя")} count={items.length} href="/" more={t("на Главную")}>
{items.length === 0 ? (
<p className="text-sm text-muted-foreground">{t("Агентам ничего не нужно.")}</p>
) : (
items.slice(0, 6).map((q) => (
<Link key={q.id} href={q.taskKey ? `/t/${q.taskKey}` : "/"} className="block rounded-md border border-primary/25 bg-primary/5 px-3 py-2 text-sm text-foreground hover:border-primary/50 hover:no-underline">
<span className="font-mono text-xs text-primary">{q.taskKey ?? `#${q.id}`}</span>{" "}
<span className="line-clamp-2 text-muted-foreground">{q.text}</span>
</Link>
))
)}
</PanelSection>
)}
<PanelSection title={t("Агенты за работой")} count={sessions.length} href="/runners" more={t("все")}>
{sessions.length === 0 ? (
<p className="text-sm text-muted-foreground">{t("Сейчас ничего не запущено.")}</p>
) : (
sessions.slice(0, 12).map((s) => {
const st = SESSION_STATUS[s.status] ?? { label: s.status, tone: "muted" as const };
return (
<Link key={s.id} href={`/runners?id=${s.id}`} className="flex items-center gap-2 rounded-md px-2 py-1.5 text-sm text-foreground hover:bg-accent hover:no-underline">
<span className={cn("size-2 shrink-0 rounded-full", TONE_BG[st.tone], s.status === "running" && "animate-pulse")} title={t.text(st.label)} />
<span className="shrink-0 font-mono text-xs">{s.taskKey ?? s.projectKey}</span>
<span className="min-w-0 flex-1 truncate text-muted-foreground">{s.taskTitle}</span>
<span className="shrink-0 font-mono text-[11px] text-muted-foreground">{ago(s.lastActivityAt, t)}</span>
</Link>
);
})
)}
</PanelSection>
</div>
);
}
export function PanelSection({ title, count, href, more, children }: { title: string; count?: number; href?: string; more?: string; children: React.ReactNode }) {
return (
<section className="flex flex-col gap-2">
<h2 className="m-0 flex items-center gap-2 font-mono text-[11px] font-semibold tracking-wider text-muted-foreground uppercase">
{title}
{count != null && count > 0 && <span className="rounded bg-muted px-1.5 text-foreground tabular-nums">{count}</span>}
{href && more && (
<Link href={href} className="ml-auto font-sans text-xs font-normal tracking-normal normal-case text-muted-foreground hover:text-foreground">
{more} →
</Link>
)}
</h2>
{children}
</section>
);
}