From 7a7ca2d831a97557618bf6d85b39e78d640f1bea Mon Sep 17 00:00:00 2001 From: Ivan Rezchikov Date: Mon, 13 Jul 2026 20:11:42 +0300 Subject: [PATCH] feat: list of pages --- app/[type]/[slug]/page.tsx | 2 -- app/[type]/page.tsx | 33 -------------------- app/list/page.tsx | 45 ++++++++++++++++++++++++++ components/editor.tsx | 44 +++++++++----------------- components/image-uploader.tsx | 5 +-- components/news-card.tsx | 2 +- components/ui/slider.tsx | 59 +++++++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 68 deletions(-) delete mode 100644 app/[type]/page.tsx create mode 100644 app/list/page.tsx create mode 100644 components/ui/slider.tsx diff --git a/app/[type]/[slug]/page.tsx b/app/[type]/[slug]/page.tsx index 3187654..084c4c6 100644 --- a/app/[type]/[slug]/page.tsx +++ b/app/[type]/[slug]/page.tsx @@ -141,8 +141,6 @@ function BlockRenderer({ block }: { block: Block }) { {b.caption }) { - const user = await getCurrentUser(); - if (!user?.isAdmin) redirect("/"); - - const { type } = await params; - if (!PAGE_TYPES.includes(type as PageType)) { - notFound(); - } - - const pages = await getPages(type as PageType, "PUBLISHED"); - - return ( -
-

All pages of type ${type}

-
- { - pages.length > 0 ? pages.map((n) => ( - - )) :

There are no pages of that type yet...

- } -
-
- ); -} diff --git a/app/list/page.tsx b/app/list/page.tsx new file mode 100644 index 0000000..7bb286a --- /dev/null +++ b/app/list/page.tsx @@ -0,0 +1,45 @@ +import { getPages } from "@/lib/pages/repository"; +import { getCurrentUser } from "@/lib/user"; +import { formatDate } from "@/lib/utils"; +import { ArchiveIcon, CalendarIcon } from "lucide-react"; +import { Metadata } from "next"; +import Link from "next/link"; +import { redirect } from "next/navigation"; + +export const metadata: Metadata = { title: "List of pages" }; + +export default async function List() { + const user = await getCurrentUser(); + if (!user?.isAdmin) redirect("/"); + + const pagesPublished = await getPages("PAGE", "PUBLISHED"); + const pagesArchived = await getPages("PAGE", "ARCHIVED"); + + const pages = [...pagesPublished, ...pagesArchived].sort((a, b) => { + const aDate = new Date(a.updatedAt ?? a.publishedAt).getTime(); + const bDate = new Date(b.updatedAt ?? b.publishedAt).getTime(); + + return bDate - aDate; + }); + + return ( +
+

List of pages

+
+ { + pages.length > 0 ? pages.map((p) => ( +
+ +

{p.title}

+ +
+
{formatDate(p.publishedAt)}
+ {p.status === "ARCHIVED" &&
Archived
} +
+
+ )) :

There are no pages yet...

+ } +
+
+ ); +} diff --git a/components/editor.tsx b/components/editor.tsx index b1371eb..dde2d06 100644 --- a/components/editor.tsx +++ b/components/editor.tsx @@ -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 ( -
+
{content.url && (
-
- handleWidthChange(Number(e.target.value))} - className="flex-1 h-1.5 bg-muted rounded-full appearance-none cursor-pointer accent-primary" - /> - {currentWidth}% -
-
- {WIDTH_PRESETS.map((preset) => ( - - ))} +
+ + {currentWidth}%
+ onChange({ type: "IMAGE", url: content.url, caption: content.caption ?? "", width: v })} + />
)}
diff --git a/components/image-uploader.tsx b/components/image-uploader.tsx index ee6e346..0ea1e8c 100644 --- a/components/image-uploader.tsx +++ b/components/image-uploader.tsx @@ -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(null); const [previewUrl, setPreviewUrl] = useState(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 ? (
- +