import {XMarkIcon} from '@heroicons/react/24/solid' import clsx from 'clsx' import Image from 'next/image' import {useState} from 'react' import {Button} from '../buttons/button' import {Col} from '../layout/col' import {Modal} from '../layout/modal' import {Row} from '../layout/row' export function EditablePhotoGrid(props: { photos: string[] onReorder: (newOrder: string[]) => void onDelete: (url: string) => void onSetProfilePic: (url: string) => void }) { const {photos, onReorder, onDelete, onSetProfilePic} = props const [draggedIndex, setDraggedIndex] = useState(null) const [fullscreenPhoto, setFullscreenPhoto] = useState(null) const handleDragStart = (index: number) => { setDraggedIndex(index) } const handleDragOver = (e: React.DragEvent, index: number) => { e.preventDefault() if (draggedIndex === null || draggedIndex === index) return const newPhotos = [...photos] const draggedPhoto = newPhotos[draggedIndex] newPhotos.splice(draggedIndex, 1) newPhotos.splice(index, 0, draggedPhoto) onReorder(newPhotos) setDraggedIndex(index) } const handleDragEnd = () => { setDraggedIndex(null) } return ( <> {/* Thumbnail strip */} {photos.map((url, i) => ( ))} {/* Main grid */} {photos.map((url, i) => ( setFullscreenPhoto(url)} onDelete={onDelete} /> ))} {/* Fullscreen view modal */} setFullscreenPhoto(null)} size="xl"> ) } const PhotoItem = ({ url, index, isThumbnail = false, isDragging, handleDragEnd, handleDragOver, handleDragStart, onClick, onDelete, }: { url: string index: number isThumbnail?: boolean isDragging?: boolean handleDragEnd: () => void handleDragOver: (e: React.DragEvent, index: number) => void handleDragStart: (index: number) => void onClick?: () => void onDelete?: (url: string) => void }) => (
handleDragStart(index)} onDragOver={(e) => handleDragOver(e, index)} onDragEnd={handleDragEnd} onClick={onClick} > {onDelete && ( )}
)