37 lines
1.7 KiB
TypeScript
37 lines
1.7 KiB
TypeScript
import Link from "next/link";
|
||
import { listUserProjects } from "@peppa/core";
|
||
import { AutoRefresh } from "@/components/AutoRefresh";
|
||
import { Flash, ProjectList, QuestionCard, SessionCard } from "@/components/ui";
|
||
import { requireUser } from "@/lib/auth";
|
||
import { db } from "@/lib/db";
|
||
import { activeSessions, inbox } from "@/lib/queries";
|
||
|
||
export default async function Home({ searchParams }: { searchParams: Promise<{ error?: string }> }) {
|
||
const user = await requireUser();
|
||
const { error } = await searchParams;
|
||
const [items, sessions, projects] = await Promise.all([inbox(user.id), activeSessions(user.id), listUserProjects(db, user.id)]);
|
||
return (
|
||
<>
|
||
<AutoRefresh />
|
||
<Flash error={error} />
|
||
<h1>Главная</h1>
|
||
<section>
|
||
<h2>Вопросы агентов {items.length > 0 && <span className="count">{items.length}</span>}</h2>
|
||
{items.length === 0 ? <p className="empty">Агентам от тебя ничего не нужно.</p> : items.map((q) => <QuestionCard key={q.id} q={q} taskKey={q.taskKey} taskStatus={q.taskStatus} back="/" />)}
|
||
</section>
|
||
<section>
|
||
<h2>
|
||
Активные раннеры <Link href="/runners" className="more">все раннеры →</Link>
|
||
</h2>
|
||
{sessions.length === 0 ? <p className="empty">Сейчас ничего не запущено.</p> : sessions.map((s) => <SessionCard key={s.id} s={s} back="/" />)}
|
||
</section>
|
||
<section>
|
||
<h2>
|
||
Мои проекты <Link href="/projects" className="more">все проекты →</Link>
|
||
</h2>
|
||
<ProjectList projects={projects} userId={user.id} />
|
||
</section>
|
||
</>
|
||
);
|
||
}
|