66 lines
3.4 KiB
TypeScript
66 lines
3.4 KiB
TypeScript
import Link from "next/link";
|
||
import { ago } from "@/components/common";
|
||
import { requireUser, words } from "@/lib/auth";
|
||
import { activeSessions, inbox } from "@/lib/queries";
|
||
import { SESSION_STATUS, TONE_BG } from "@/lib/status";
|
||
import { cn } from "@/lib/utils";
|
||
|
||
/** 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 w = await words();
|
||
const [items, sessions] = await Promise.all([questions ? inbox(user.id) : [], activeSessions(user.id)]);
|
||
return (
|
||
<div className="flex flex-col gap-6">
|
||
{questions && (
|
||
<PanelSection title="Ждут вас" count={items.length} href="/" more="на Главную">
|
||
{items.length === 0 ? (
|
||
<p className="text-sm text-muted-foreground">Агентам ничего не нужно.</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="Агенты за работой" count={sessions.length} href={w.engineer ? "/runners" : undefined} more="все">
|
||
{sessions.length === 0 ? (
|
||
<p className="text-sm text-muted-foreground">Сейчас ничего не запущено.</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={w.engineer ? `/runners?id=${s.id}` : s.taskKey ? `/t/${s.taskKey}` : `/p/${s.projectKey}`} 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={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)}</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>
|
||
);
|
||
}
|