import Link from "next/link"; import { auth } from "@/auth"; import { listSnippets } from "@/lib/snippets"; import { Container, PageHeader } from "@/app/_components/ui/container"; import { Card, CardBody } from "@/app/_components/ui/card"; import { Badge } from "@/app/_components/ui/badge"; import { Button } from "@/app/_components/ui/button"; import { Input } from "@/app/_components/ui/input"; import { EmptyState } from "@/app/_components/ui/empty-state"; export const dynamic = "force-dynamic"; type Scope = "project" | "user"; function detailHref(name: string, scope: Scope, projectKey: string | null): string { const params = new URLSearchParams({ scope }); if (scope === "project" && projectKey) params.set("project", projectKey); return `/snippets/${encodeURIComponent(name)}?${params.toString()}`; } export default async function SnippetsPage({ searchParams, }: { searchParams: Promise<{ scope?: string; project?: string; tag?: string }>; }) { const session = await auth(); const userId = session!.user.id; const params = await searchParams; const scope: Scope | undefined = params.scope === "user" || params.scope === "project" ? params.scope : undefined; const project = params.project?.trim() || undefined; const tag = params.tag?.trim() || undefined; const rows = await listSnippets(userId, { scope, projectKey: project, tags: tag ? [tag] : undefined, limit: 200, }); return ( New snippet } /> Apply {rows.length === 0 ? ( Create the first one } /> ) : ( {rows.map((s) => ( {s.name} {s.scope} {s.projectKey ? ( · {s.projectKey} ) : null} updated {new Date(s.updatedAt).toLocaleString()} {s.description ? ( {s.description} ) : ( {s.body} )} {s.tags.length ? ( {s.tags.map((t) => ( {t} ))} ) : null} ))} )} ); } function FilterSelect({ name, value, options, placeholder, }: { name: string; value: string | undefined; options: string[]; placeholder: string; }) { return ( {options.map((o) => ( {o === "" ? placeholder : o} ))} ); }
{s.description}
{s.body}