import React, { useCallback } from 'react'; import useImageUpload from '../../lib/hooks/useImageUpload'; import { useAtom, useAtomValue } from 'jotai'; import { datasetAtom } from '../../state'; import Image from 'next/image'; import { produce } from 'immer'; export interface ImageListProps {} const ImageList: React.FC = () => { const { getRootProps, getInputProps, isDragActive } = useImageUpload({ noClick: true, }); const [dataset, setDataset] = useAtom(datasetAtom); return (
{dataset.length < 10 ? (
You can upload up to 10 images max by dragging image.
) : (
You have reached the maximum limit of 10 images.
)}
{dataset.map(entity => { const { url: imageSrc, name, selected } = entity; return (
setDataset(prev => produce(prev, draft => { const index = draft.findIndex(d => d.name === name); draft[index].selected = !selected; }), ) } className={`relative rounded-xl overflow-hidden shadow-md cursor-pointer transition-transform hover:scale-105 box-content ${selected ? 'border-4 border-blue-500' : ''}`} > dataset images

{name}

); })}
{isDragActive && (

Drop the files here ...

)}
); }; export default ImageList;