"use client"; import { useEffect, useRef, useState } from "react"; import Link from "next/link"; import * as DialogP from "@radix-ui/react-dialog"; import { useQuery } from "@tanstack/react-query"; import { X, Maximize2, Trash2 } from "lucide-react"; import { Spinner } from "@/components/ui/primitives"; import { Editor } from "@/components/editor/Editor"; import { api } from "@/lib/client/api"; import { debounce } from "@/lib/utils"; import { toast } from "@/components/ui/toast"; import { useDb } from "./hooks"; import { Cell } from "./cells/Cell"; import { TypeIcon } from "./meta"; /** Side peek of a row: title, all properties, and the row page body. */ export function RowPeek({ rowId, onClose }: { rowId: string | null; onClose: () => void }) { const ctx = useDb(); const row = ctx.rows.find((r) => r.id === rowId); const tp = ctx.props.find((p) => p.type === "title"); const { data: page } = useQuery({ queryKey: ["page", row?.pageId], enabled: !!row, queryFn: () => api(`/api/pages/${row!.pageId}`) }); const [editing, setEditing] = useState(null); const [title, setTitle] = useState(""); const saveTitle = useRef(debounce((v: string) => { if (row && tp) ctx.setCell(row.id, { [tp.id]: v }); }, 500)).current; const saveBody = useRef(debounce(async (pageId: string, content: unknown) => { try { await api(`/api/pages/${pageId}`, { method: "PATCH", json: { content } }); } catch (e: any) { toast("Save failed", { description: e?.message, tone: "danger" }); } }, 800)).current; useEffect(() => { if (row) setTitle(row.title === "Untitled" ? "" : row.title); }, [row?.id]); // eslint-disable-line react-hooks/exhaustive-deps return ( { if (!o) onClose(); }}> e.preventDefault()}> RowRow details
{row && Open as page} {row && }
{!row ?
: (