diff --git a/app/account/account-menu.tsx b/app/account/account-menu.tsx index 5cde60b..026fbaf 100644 --- a/app/account/account-menu.tsx +++ b/app/account/account-menu.tsx @@ -1,7 +1,7 @@ "use client"; import { cn } from "@/lib/utils"; -import { BookOpenTextIcon, SignatureIcon, UserIcon } from "lucide-react"; +import { BookOpenTextIcon, UserIcon } from "lucide-react"; import Link from "next/link"; import { usePathname } from "next/navigation"; diff --git a/components/editor.tsx b/components/editor.tsx index c345449..4ff22b6 100644 --- a/components/editor.tsx +++ b/components/editor.tsx @@ -7,7 +7,7 @@ import { Button } from "@/components/ui/button"; import { Field, FieldError, FieldGroup, FieldLabel, FieldSet } from "@/components/ui/field"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group"; 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 { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { cn } from "@/lib/utils"; @@ -73,8 +73,13 @@ export default function Editor({ page, initialBlocks = [], onChange, errors }: E const [previewUrls, setPreviewUrls] = useState>(new Map()); const previewCacheRef = useRef>(new Map()); + const onChangeRef = useRef(onChange); useEffect(() => { - onChange({ + onChangeRef.current = onChange; + }); + + useEffect(() => { + onChangeRef.current({ title, type, slug: slug || title.toLowerCase().replace(/\s+/g, "-"), @@ -82,7 +87,7 @@ export default function Editor({ page, initialBlocks = [], onChange, errors }: E tags, blocks, }); - }, [title, slug, location, tags, blocks]); + }, [title, type, slug, location, tags, blocks]); useEffect(() => { 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 }) { const content = block.content as { type: "IMAGE"; url: string; caption?: string; width?: number }; const [isUploading, setIsUploading] = useState(false); - const [isDragging, setIsDragging] = useState(false); - const [supportsDrag, setSupportsDrag] = useState(false); + const [supportsDrag] = useState( + () => 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 imgRef = useRef(null); - useEffect(() => { - setSupportsDrag(window.matchMedia("(hover: hover) and (pointer: fine)").matches); - }, []); - const currentWidth = content.width; function handleDragStart(e: React.PointerEvent) { @@ -642,7 +645,7 @@ function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Bl e.stopPropagation(); const startWidth = imgRef.current?.offsetWidth ?? 500; dragStartRef.current = { x: e.clientX, width: startWidth }; - setIsDragging(true); + isDraggingRef.current = true; function handleMove(ev: PointerEvent) { if (!dragStartRef.current) return; @@ -654,7 +657,7 @@ function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Bl } function handleUp() { - setIsDragging(false); + isDraggingRef.current = false; dragStartRef.current = null; window.removeEventListener("pointermove", handleMove); window.removeEventListener("pointerup", handleUp); diff --git a/components/image-uploader.tsx b/components/image-uploader.tsx index 0a6479d..0bcc7e0 100644 --- a/components/image-uploader.tsx +++ b/components/image-uploader.tsx @@ -33,7 +33,6 @@ type Props = { const MAX_SIZE = 5 * 1024 * 1024; 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_IMG_CLASS = "block max-w-full md:max-w-200 h-auto rounded-md border object-contain"; function formatFileSize(bytes: number): string { return bytes < 1024 * 1024 diff --git a/lib/citizenship/actions.ts b/lib/citizenship/actions.ts index b7c06bf..a5c3d75 100644 --- a/lib/citizenship/actions.ts +++ b/lib/citizenship/actions.ts @@ -51,7 +51,7 @@ export const submitCitizenshipApplication = formAction(citizenshipApplicationSch if (!eligibility.eligible) throw new AppError(eligibility.reason!); const isEuResidentYes = data.isEuResident === "yes"; - const { profile, signature, isEuResident, ...applicationData } = data; + const { profile, signature, isEuResident: _isEuResident, ...applicationData } = data; let regionName: string | null = null; if (isEuResidentYes) {