This commit is contained in:
Ivan Rezchikov
2026-07-15 22:35:07 +03:00
parent 687fbaf3a6
commit ac75c72382
4 changed files with 16 additions and 14 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
"use client"; "use client";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { BookOpenTextIcon, SignatureIcon, UserIcon } from "lucide-react"; import { BookOpenTextIcon, UserIcon } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { usePathname } from "next/navigation"; import { usePathname } from "next/navigation";
+14 -11
View File
@@ -7,7 +7,7 @@ import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldGroup, FieldLabel, FieldSet } from "@/components/ui/field"; import { Field, FieldError, FieldGroup, FieldLabel, FieldSet } from "@/components/ui/field";
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group";
import { Block, BlockType, Page, PageMeta, PageType } from "@/lib/pages/types"; import { Block, BlockType, Page, PageMeta, PageType } from "@/lib/pages/types";
import { Globe2Icon, PlusIcon, Trash2Icon, XIcon, ChevronDownIcon, ChevronUpIcon, ImageIcon, QuoteIcon, AlertCircleIcon, MinusIcon, ListIcon, TableIcon, TypeIcon, AlignLeftIcon, InfoIcon, DotIcon, ListOrderedIcon, LinkIcon, MoveDiagonalIcon, MoveDiagonal2Icon } from "lucide-react"; import { Globe2Icon, PlusIcon, Trash2Icon, XIcon, ChevronDownIcon, ChevronUpIcon, ImageIcon, QuoteIcon, AlertCircleIcon, MinusIcon, ListIcon, TableIcon, TypeIcon, AlignLeftIcon, InfoIcon, DotIcon, ListOrderedIcon, LinkIcon, MoveDiagonal2Icon } from "lucide-react";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "./ui/select"; import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
@@ -73,8 +73,13 @@ export default function Editor({ page, initialBlocks = [], onChange, errors }: E
const [previewUrls, setPreviewUrls] = useState<Map<string, string>>(new Map()); const [previewUrls, setPreviewUrls] = useState<Map<string, string>>(new Map());
const previewCacheRef = useRef<Map<string, string>>(new Map()); const previewCacheRef = useRef<Map<string, string>>(new Map());
const onChangeRef = useRef(onChange);
useEffect(() => { useEffect(() => {
onChange({ onChangeRef.current = onChange;
});
useEffect(() => {
onChangeRef.current({
title, title,
type, type,
slug: slug || title.toLowerCase().replace(/\s+/g, "-"), slug: slug || title.toLowerCase().replace(/\s+/g, "-"),
@@ -82,7 +87,7 @@ export default function Editor({ page, initialBlocks = [], onChange, errors }: E
tags, tags,
blocks, blocks,
}); });
}, [title, slug, location, tags, blocks]); }, [title, type, slug, location, tags, blocks]);
useEffect(() => { useEffect(() => {
const imageBlocks = blocks.filter( const imageBlocks = blocks.filter(
@@ -626,15 +631,13 @@ function TableEditor({ content, onChange }: { content: { type: "TABLE"; headers:
function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Block; previewUrl?: string; onChange: (c: Block["content"]) => void; onPreviewReady: (id: string, url: string) => void }) { 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 content = block.content as { type: "IMAGE"; url: string; caption?: string; width?: number };
const [isUploading, setIsUploading] = useState(false); const [isUploading, setIsUploading] = useState(false);
const [isDragging, setIsDragging] = useState(false); const [supportsDrag] = useState(
const [supportsDrag, setSupportsDrag] = useState(false); () => typeof window !== "undefined" && window.matchMedia("(hover: hover) and (pointer: fine)").matches
);
const isDraggingRef = useRef(false);
const dragStartRef = useRef<{ x: number; width: number } | null>(null); const dragStartRef = useRef<{ x: number; width: number } | null>(null);
const imgRef = useRef<HTMLImageElement>(null); const imgRef = useRef<HTMLImageElement>(null);
useEffect(() => {
setSupportsDrag(window.matchMedia("(hover: hover) and (pointer: fine)").matches);
}, []);
const currentWidth = content.width; const currentWidth = content.width;
function handleDragStart(e: React.PointerEvent) { function handleDragStart(e: React.PointerEvent) {
@@ -642,7 +645,7 @@ function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Bl
e.stopPropagation(); e.stopPropagation();
const startWidth = imgRef.current?.offsetWidth ?? 500; const startWidth = imgRef.current?.offsetWidth ?? 500;
dragStartRef.current = { x: e.clientX, width: startWidth }; dragStartRef.current = { x: e.clientX, width: startWidth };
setIsDragging(true); isDraggingRef.current = true;
function handleMove(ev: PointerEvent) { function handleMove(ev: PointerEvent) {
if (!dragStartRef.current) return; if (!dragStartRef.current) return;
@@ -654,7 +657,7 @@ function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Bl
} }
function handleUp() { function handleUp() {
setIsDragging(false); isDraggingRef.current = false;
dragStartRef.current = null; dragStartRef.current = null;
window.removeEventListener("pointermove", handleMove); window.removeEventListener("pointermove", handleMove);
window.removeEventListener("pointerup", handleUp); window.removeEventListener("pointerup", handleUp);
-1
View File
@@ -33,7 +33,6 @@ type Props = {
const MAX_SIZE = 5 * 1024 * 1024; const MAX_SIZE = 5 * 1024 * 1024;
const DEFAULT_ACCEPT = "image/jpeg,image/png,image/webp"; const DEFAULT_ACCEPT = "image/jpeg,image/png,image/webp";
const EDITOR_WRAPPER_CLASS = "flex flex-col gap-2 items-stretch md:items-start"; const EDITOR_WRAPPER_CLASS = "flex flex-col gap-2 items-stretch md:items-start";
const EDITOR_IMG_CLASS = "block max-w-full md:max-w-200 h-auto rounded-md border object-contain";
function formatFileSize(bytes: number): string { function formatFileSize(bytes: number): string {
return bytes < 1024 * 1024 return bytes < 1024 * 1024
+1 -1
View File
@@ -51,7 +51,7 @@ export const submitCitizenshipApplication = formAction(citizenshipApplicationSch
if (!eligibility.eligible) throw new AppError(eligibility.reason!); if (!eligibility.eligible) throw new AppError(eligibility.reason!);
const isEuResidentYes = data.isEuResident === "yes"; const isEuResidentYes = data.isEuResident === "yes";
const { profile, signature, isEuResident, ...applicationData } = data; const { profile, signature, isEuResident: _isEuResident, ...applicationData } = data;
let regionName: string | null = null; let regionName: string | null = null;
if (isEuResidentYes) { if (isEuResidentYes) {