feat: list of pages

This commit is contained in:
Ivan Rezchikov
2026-07-13 20:11:42 +03:00
parent 2e356e4c47
commit 7a7ca2d831
7 changed files with 122 additions and 68 deletions
+14 -30
View File
@@ -16,6 +16,8 @@ import { Alert } from "./ui/alert";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { uploadPageImage, getImagePreviewUrl } from "@/lib/pages/actions";
import { ImageUploader } from "@/components/image-uploader";
import { Slider } from "@/components/ui/slider";
import { Label } from "@/components/ui/label";
export type EditorData = {
title: string;
@@ -621,8 +623,6 @@ function TableEditor({ content, onChange }: { content: { type: "TABLE"; headers:
);
}
const WIDTH_PRESETS = [25, 50, 75, 100] as const;
function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Block; previewUrl?: string; onChange: (c: Block["content"]) => void; onPreviewReady: (id: string, url: string) => void }) {
const content = block.content as { type: "IMAGE"; url: string; caption?: string; width?: number };
const [isUploading, setIsUploading] = useState(false);
@@ -646,17 +646,14 @@ function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Bl
onChange({ type: "IMAGE", url: "", caption: content.caption ?? "", width: content.width });
}
function handleWidthChange(width: number) {
onChange({ type: "IMAGE", url: content.url, caption: content.caption ?? "", width });
}
return (
<div className="flex flex-col gap-2">
<div className="flex flex-col gap-1.5">
<ImageUploader
id={`image-${block.id}`}
label=""
variant="editor"
value={previewUrl}
previewStyle={currentWidth < 100 ? { width: `${currentWidth}%` } : undefined}
onFileSelect={handleFileSelect}
onRemove={handleRemove}
isUploading={isUploading}
@@ -665,30 +662,17 @@ function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Bl
/>
{content.url && (
<div className="flex flex-col gap-2">
<div className="flex items-center gap-3">
<input
type="range"
min={10}
max={100}
value={currentWidth}
onChange={(e) => handleWidthChange(Number(e.target.value))}
className="flex-1 h-1.5 bg-muted rounded-full appearance-none cursor-pointer accent-primary"
/>
<span className="text-xs text-muted-foreground w-8 text-right tabular-nums">{currentWidth}%</span>
</div>
<div className="flex gap-1.5">
{WIDTH_PRESETS.map((preset) => (
<Button
key={preset}
variant={currentWidth === preset ? "default" : "outline"}
size="sm"
className="h-7 px-2 text-xs"
onClick={() => handleWidthChange(preset)}
>
{preset}%
</Button>
))}
<div className="flex items-center justify-between gap-2">
<Label className="text-xs md:text-sm">Image size</Label>
<span className="text-xs md:text-sm text-muted-foreground">{currentWidth}%</span>
</div>
<Slider
value={[currentWidth]}
min={10}
max={100}
step={1}
onValueChange={([v]) => onChange({ type: "IMAGE", url: content.url, caption: content.caption ?? "", width: v })}
/>
</div>
)}
</div>