import { HStack } from "@yaakapp-internal/ui"; import { useState } from "react"; import { showDialog } from "../lib/dialog"; import { CopyButton } from "./CopyButton"; import { IconButton } from "./core/IconButton"; /** * How much of the value to render at once. Rendering the whole thing would hit exactly the * layout cost this dialog exists to avoid, so it pages instead. */ const PAGE_CHARS = 20_000; interface Props { value: string; } export function LargeValueDialog({ value }: Props) { const [page, setPage] = useState(0); const pageCount = Math.max(1, Math.ceil(value.length / PAGE_CHARS)); const start = page * PAGE_CHARS; const slice = value.slice(start, start + PAGE_CHARS); return (
{value.length.toLocaleString()} characters {pageCount > 1 && ( setPage((p) => Math.max(0, p - 1))} /> {page + 1} / {pageCount} = pageCount - 1} onClick={() => setPage((p) => Math.min(pageCount - 1, p + 1))} /> )}
{slice}
); } LargeValueDialog.show = (value: string) => { showDialog({ id: "large-value", title: "Large Value", size: "lg", className: "h-[calc(100vh-10rem)] max-h-200!", render: () => , }); };