|
1 | 1 | import React from "react" |
2 | | -import Image from "next/image" |
3 | 2 |
|
4 | 3 | import { Image as ImageType } from "database" |
5 | | -import { Check, CheckCircle, Circle, CircleDot, TrashIcon } from "lucide-react" |
6 | | -import { Button } from "ui" |
7 | 4 |
|
8 | | -import { useFileManager } from "./FileManagerContainer" |
| 5 | +import NoItemFounded from "../no-item-founded" |
| 6 | +import ImageItem from "./ImageItem" |
| 7 | +import Loading from "./Loading" |
9 | 8 |
|
10 | 9 | type ImageListProps = { |
11 | 10 | images: ImageType[] |
12 | 11 | isLoading: boolean |
13 | 12 | } |
14 | 13 |
|
15 | 14 | const ImageList: React.FC<ImageListProps> = ({ images, isLoading }) => { |
16 | | - const { selectedFiles, setSelectedFiles } = useFileManager() |
| 15 | + if (isLoading) { |
| 16 | + return <Loading /> |
| 17 | + } |
17 | 18 |
|
18 | | - const handleSelect = (image: ImageType) => { |
19 | | - setSelectedFiles([image]) |
| 19 | + if (images?.length === 0) { |
| 20 | + return <NoItemFounded /> |
20 | 21 | } |
21 | 22 |
|
22 | 23 | return ( |
23 | 24 | <div className="mt-2 flex flex-wrap gap-3 p-1"> |
24 | | - {isLoading ? ( |
25 | | - <div>loading...</div> |
26 | | - ) : ( |
27 | | - images?.map((image) => ( |
28 | | - <div |
29 | | - key={image.id} |
30 | | - className="group relative border" |
31 | | - > |
32 | | - <Image |
33 | | - src={`${process.env.NEXT_PUBLIC_FRONTEND_URL}${image.url}`} |
34 | | - alt={`Image ${image.name}`} |
35 | | - width={160} |
36 | | - height={160} |
37 | | - className="cursor-pointe h-[160px] w-[160px] bg-gray-300 object-cover" |
38 | | - /> |
39 | | - <Button |
40 | | - variant="destructive" |
41 | | - size="icon" |
42 | | - className="absolute bottom-1 right-1 h-7 w-7 rounded-full opacity-0 transition-opacity group-hover:opacity-100" |
43 | | - onClick={() => console.log("delete")} |
44 | | - > |
45 | | - <TrashIcon className="h-4 w-4" /> |
46 | | - </Button> |
47 | | - <Button |
48 | | - variant="outline" |
49 | | - className="absolute right-1 top-1 h-7 w-7 rounded-full p-0" |
50 | | - onClick={() => { |
51 | | - if (selectedFiles?.at(0)?.id === image.id) { |
52 | | - setSelectedFiles([]) |
53 | | - } else { |
54 | | - handleSelect(image) |
55 | | - } |
56 | | - }} |
57 | | - > |
58 | | - {selectedFiles?.at(0)?.id === image.id ? ( |
59 | | - <CheckCircle className="h-6 w-6 text-blue-500" /> |
60 | | - ) : ( |
61 | | - <Circle className="h-6 w-6" /> |
62 | | - )} |
63 | | - </Button> |
64 | | - </div> |
65 | | - )) |
66 | | - )} |
| 25 | + {images?.map((image) => ( |
| 26 | + <ImageItem |
| 27 | + key={image.id} |
| 28 | + image={image} |
| 29 | + /> |
| 30 | + ))} |
67 | 31 | </div> |
68 | 32 | ) |
69 | 33 | } |
|
0 commit comments