feat: list of pages
This commit is contained in:
+14
-30
@@ -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>
|
||||
|
||||
@@ -16,6 +16,7 @@ type Props = {
|
||||
error?: string;
|
||||
variant?: "default" | "editor";
|
||||
previewClassName?: string;
|
||||
previewStyle?: React.CSSProperties;
|
||||
accept?: string;
|
||||
required?: boolean;
|
||||
value?: string;
|
||||
@@ -55,7 +56,7 @@ function fileToFileList(file: File): FileList {
|
||||
return dt.files;
|
||||
}
|
||||
|
||||
export function ImageUploader({ id, name, label, description, error, variant = "default", previewClassName, accept = DEFAULT_ACCEPT, required, value, onFileSelect, onRemove, isUploading, children, caption, onCaptionChange }: Props) {
|
||||
export function ImageUploader({ id, name, label, description, error, variant = "default", previewClassName, previewStyle, accept = DEFAULT_ACCEPT, required, value, onFileSelect, onRemove, isUploading, children, caption, onCaptionChange }: Props) {
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
||||
const [fileInfo, setFileInfo] = useState<{ name: string; size: number } | null>(null);
|
||||
@@ -124,7 +125,7 @@ export function ImageUploader({ id, name, label, description, error, variant = "
|
||||
{displayUrl ? (
|
||||
<div className={EDITOR_WRAPPER_CLASS}>
|
||||
<div className="group relative rounded-md">
|
||||
<img src={displayUrl} alt="" className={previewClassName ?? EDITOR_IMG_CLASS} />
|
||||
<img src={displayUrl} alt="" className={previewClassName ?? EDITOR_IMG_CLASS} style={previewStyle} />
|
||||
|
||||
<div className="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<Button type="button" variant="secondary" size="sm" onClick={() => inputRef.current?.click()} disabled={isUploading}>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { formatDate } from "@/lib/utils";
|
||||
|
||||
export function NewsCard({ news }: { news: PagePublic }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex flex-col gap-1">
|
||||
<Link href={`/news/${news.slug}`} className="w-max">
|
||||
<h2 className="hover:underline underline-offset-8 decoration-2 hover:duration-200 cursor-pointer">{news.title}</h2>
|
||||
</Link>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Slider as SliderPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Slider({
|
||||
className,
|
||||
defaultValue,
|
||||
value,
|
||||
min = 0,
|
||||
max = 100,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SliderPrimitive.Root>) {
|
||||
const _values = React.useMemo(
|
||||
() =>
|
||||
Array.isArray(value)
|
||||
? value
|
||||
: Array.isArray(defaultValue)
|
||||
? defaultValue
|
||||
: [min, max],
|
||||
[value, defaultValue, min, max]
|
||||
)
|
||||
|
||||
return (
|
||||
<SliderPrimitive.Root
|
||||
data-slot="slider"
|
||||
defaultValue={defaultValue}
|
||||
value={value}
|
||||
min={min}
|
||||
max={max}
|
||||
className={cn(
|
||||
"relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-vertical:h-full data-vertical:min-h-40 data-vertical:w-auto data-vertical:flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<SliderPrimitive.Track
|
||||
data-slot="slider-track"
|
||||
className="relative grow overflow-hidden rounded-2xl bg-input/90 data-horizontal:h-1 data-horizontal:w-full data-vertical:h-full data-vertical:w-1"
|
||||
>
|
||||
<SliderPrimitive.Range
|
||||
data-slot="slider-range"
|
||||
className="absolute bg-primary select-none data-horizontal:h-full data-vertical:w-full"
|
||||
/>
|
||||
</SliderPrimitive.Track>
|
||||
{Array.from({ length: _values.length }, (_, index) => (
|
||||
<SliderPrimitive.Thumb
|
||||
data-slot="slider-thumb"
|
||||
key={index}
|
||||
className="block size-4 shrink-0 rounded-2xl bg-white shadow-md ring-1 ring-black/10 transition-[color,box-shadow] duration-200 select-none not-dark:bg-clip-padding hover:ring-4 hover:ring-ring/30 focus-visible:ring-4 focus-visible:ring-ring/30 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
||||
/>
|
||||
))}
|
||||
</SliderPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Slider }
|
||||
Reference in New Issue
Block a user