peppa/apps/web/app/(app)/p/[key]/page.tsx
Асель 2b0f2fd984 PEP-1: web platform with Gitea login, projects, goals, tasks, sessions
- web: Gitea OAuth2 login, signed session cookie, everything behind login;
  inbox with answers, project board (goals → tasks), task page with
  OpenSpec artifacts, questions and session controls; new project form;
  auto-refresh, light/dark, mobile
- users + projects.owner_id; tokens AES-256-GCM encrypted; owner-only access
- provisionProject (runner): new or existing Gitea repo, peppa-bot
  collaborator, template + openspec init, push, rollback; used by web and
  peppa project create (replaces scripts/bootstrap-project.sh)
- peppa web login-link, peppa project owner; Gitea OAuth app script
- bins/template resolved via PEPPA_ROOT (works inside the Next build)
- testkit: mock-gitea + 10 tests (42 e2e total, all green)
- OpenSpec: pep-1-web-platform archived into specs web-auth,
  project-provisioning, web-workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 20:55:02 +05:00

80 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Link from "next/link";
import { notFound } from "next/navigation";
import { loadEnv } from "@peppa/shared";
import { AutoRefresh } from "@/components/AutoRefresh";
import { Badge, Flash, SessionCard } from "@/components/ui";
import { requireUser } from "@/lib/auth";
import { board, projectForUserByKey, projectSessions } from "@/lib/queries";
import { addGoal, addTask } from "../../actions";
export default async function ProjectPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string }> }) {
const user = await requireUser();
const { key } = await params;
const { error } = await searchParams;
const p = await projectForUserByKey(user.id, key).catch(() => null);
if (!p) notFound();
const [{ goals, tasks }, sessions] = await Promise.all([board(p.id), projectSessions(p.id)]);
const back = `/p/${p.key}`;
const groups = [...goals.map((g) => ({ goal: g, tasks: tasks.filter((t) => t.goalId === g.id) })), { goal: null, tasks: tasks.filter((t) => !t.goalId) }];
return (
<>
<AutoRefresh />
<Flash error={error} />
<h1>
<span className="mono">{p.key}</span> {p.name}
</h1>
<p className="muted">
<a href={`${loadEnv().GITEA_URL}/${p.giteaOwner}/${p.giteaRepo}`}>{p.giteaOwner}/{p.giteaRepo}</a> · <span className="mono">{p.workspacePath}</span>
</p>
{groups.map(({ goal, tasks: ts }) =>
goal || ts.length ? (
<section key={goal?.id ?? "none"} className="goal">
<h2>{goal ? `🎯 ${goal.title}` : "Без цели"}</h2>
{goal?.description && <p className="muted">{goal.description}</p>}
<ul className="tasks">
{ts.map((t) => (
<li key={t.id}>
<Link href={`/t/${p.key}-${t.number}`}>
<span className="mono">{p.key}-{t.number}</span> {t.title}
</Link>
<Badge status={t.status} />
</li>
))}
</ul>
<details>
<summary>+ Задача{goal ? " в эту цель" : ""}</summary>
<form action={addTask} className="stack">
<input type="hidden" name="projectId" value={p.id} />
<input type="hidden" name="back" value={back} />
{goal && <input type="hidden" name="goalId" value={goal.id} />}
<input type="text" name="title" required placeholder="Что сделать" aria-label="Название задачи" />
<textarea name="description" rows={3} placeholder="Описание: контекст, критерии готовности" aria-label="Описание задачи" />
<button className="primary">Создать задачу</button>
</form>
</details>
</section>
) : null,
)}
<section>
<details>
<summary>+ Цель</summary>
<form action={addGoal} className="stack">
<input type="hidden" name="projectId" value={p.id} />
<input type="hidden" name="back" value={back} />
<input type="text" name="title" required placeholder="Верхнеуровневая цель" aria-label="Название цели" />
<textarea name="description" rows={3} placeholder="Зачем и какой результат" aria-label="Описание цели" />
<button className="primary">Создать цель</button>
</form>
</details>
</section>
<section>
<h2>Сессии</h2>
{sessions.length === 0 ? <p className="empty">Сессий ещё не было.</p> : sessions.map((s) => <SessionCard key={s.id} s={s} back={back} />)}
</section>
</>
);
}