|
1 | | -import React from "react" |
| 1 | +import React, { useState } from "react" |
2 | 2 | import Image from "next/image" |
3 | 3 |
|
4 | 4 | import { Image as ImageType } from "database" |
5 | | -import { TrashIcon } from "lucide-react" |
| 5 | +import { Check, Circle, TrashIcon } from "lucide-react" |
6 | 6 | import { Button } from "ui" |
7 | 7 |
|
8 | 8 | type ImageListProps = { |
9 | 9 | images: ImageType[] |
10 | 10 | } |
11 | 11 |
|
12 | 12 | const ImageList: React.FC<ImageListProps> = ({ images }) => { |
| 13 | + const [selectedImage, setSelectedImage] = useState<ImageType | null>(null) |
| 14 | + |
13 | 15 | return ( |
14 | | - <div className="mt-2 grid grid-cols-5 gap-3"> |
| 16 | + <div className="mt-2 flex flex-wrap gap-3"> |
15 | 17 | {images?.map((image) => ( |
16 | 18 | <div |
17 | 19 | key={image.id} |
18 | | - className="group relative" |
| 20 | + className="group relative border" |
19 | 21 | > |
20 | 22 | <Image |
21 | 23 | src={`${process.env.NEXT_PUBLIC_FRONTEND_URL}${image.url}`} |
22 | | - alt={`Image ${image.id}`} |
23 | | - width={90} |
24 | | - height={90} |
25 | | - className="h-[90px] w-[90px] cursor-pointer object-cover" |
26 | | - // onClick={() => handleSelect(image.id)} |
| 24 | + alt={`Image ${image.name}`} |
| 25 | + width={160} |
| 26 | + height={160} |
| 27 | + className="cursor-pointe h-[160px] w-[160px] bg-gray-300 object-cover" |
27 | 28 | /> |
28 | 29 | <Button |
29 | 30 | variant="destructive" |
30 | 31 | size="icon" |
31 | | - className="absolute right-1 top-1 opacity-0 transition-opacity group-hover:opacity-100" |
32 | | - // onClick={() => handleDelete(image.id)} |
| 32 | + className="absolute bottom-1 right-1 h-7 w-7 rounded-full opacity-0 transition-opacity group-hover:opacity-100" |
| 33 | + onClick={() => console.log("delete")} |
33 | 34 | > |
34 | 35 | <TrashIcon className="h-4 w-4" /> |
35 | 36 | </Button> |
| 37 | + <Button |
| 38 | + variant="outline" |
| 39 | + className="absolute right-1 top-1 h-7 w-7 rounded-full p-0" |
| 40 | + onClick={() => { |
| 41 | + console.log(image) |
| 42 | + |
| 43 | + setSelectedImage(image) |
| 44 | + }} |
| 45 | + > |
| 46 | + {selectedImage?.id === image.id ? ( |
| 47 | + <Check |
| 48 | + strokeWidth={1.5} |
| 49 | + className="h-6 w-6 text-blue-500" |
| 50 | + /> |
| 51 | + ) : ( |
| 52 | + <Circle className="h-6 w-6" /> |
| 53 | + )} |
| 54 | + </Button> |
36 | 55 | </div> |
37 | 56 | ))} |
38 | 57 | </div> |
|
0 commit comments