import Link from "next/link"; import { notFound } from "next/navigation"; import { and, desc, eq, isNull } from "drizzle-orm"; import { auth } from "@/auth"; import { db } from "@/lib/db/client"; import { memories, projects } from "@/lib/db/schema"; import { updateMemoryAction, deleteMemoryAction } from "@/lib/memory-actions"; import { Container, PageHeader } from "@/app/_components/ui/container"; import { Card, CardBody, CardHeader } from "@/app/_components/ui/card"; import { Input, Textarea, Label } from "@/app/_components/ui/input"; import { Button } from "@/app/_components/ui/button"; import { Badge } from "@/app/_components/ui/badge"; export const dynamic = "force-dynamic"; export default async function MemoryDetailPage({ params, searchParams, }: { params: Promise<{ id: string }>; searchParams: Promise<{ edit?: string }>; }) { const session = await auth(); const userId = session!.user.id; const { id } = await params; const { edit } = await searchParams; const rows = await db .select({ id: memories.id, scope: memories.scope, content: memories.content, tags: memories.tags, createdAt: memories.createdAt, updatedAt: memories.updatedAt, projectKey: projects.key, projectId: memories.projectId, }) .from(memories) .leftJoin(projects, eq(memories.projectId, projects.id)) .where( and(eq(memories.id, id), eq(memories.userId, userId), isNull(memories.deletedAt)), ) .limit(1); const m = rows[0]; if (!m) notFound(); const isEditing = edit === "1"; const projectList = isEditing ? await db .select({ key: projects.key, displayName: projects.displayName }) .from(projects) .where(eq(projects.userId, userId)) .orderBy(desc(projects.updatedAt)) .limit(50) : []; return ( {m.id}} actions={ <> {!isEditing ? ( ) : null} } /> {m.scope} {m.projectKey ? {m.projectKey} : null} · Created {new Date(m.createdAt).toLocaleString()} {m.updatedAt.getTime() !== m.createdAt.getTime() ? ( · Updated {new Date(m.updatedAt).toLocaleString()} ) : null} {isEditing ? (
{projectList.length > 0 ? ( {projectList.map((p) => ( ))} ) : null}