|
1 | | -import React, { useEffect, useState } from "react" |
| 1 | +import React from "react" |
| 2 | +import Image from "next/image" |
2 | 3 |
|
| 4 | +import { Image as ImageType } from "database" |
3 | 5 | import { TrashIcon } from "lucide-react" |
4 | 6 | import { Button } from "ui" |
5 | 7 |
|
6 | | -interface Image { |
7 | | - id: string |
8 | | - url: string |
| 8 | +type ImageListProps = { |
| 9 | + images: ImageType[] |
9 | 10 | } |
10 | 11 |
|
11 | | -const ImageList: React.FC = () => { |
12 | | - const [images, setImages] = useState<Image[]>([]) |
13 | | - |
14 | | - useEffect(() => { |
15 | | - // Fetch images from API |
16 | | - const fetchImages = async () => { |
17 | | - try { |
18 | | - const response = await fetch("/api/images/list") // Replace with your API endpoint |
19 | | - const data = await response.json() |
20 | | - setImages(data) |
21 | | - } catch (error) { |
22 | | - console.error("Error fetching images:", error) |
23 | | - } |
24 | | - } |
25 | | - |
26 | | - fetchImages() |
27 | | - }, []) |
28 | | - |
29 | | - const handleSelect = (id: string) => { |
30 | | - // Handle image selection |
31 | | - console.log("Selected image:", id) |
32 | | - } |
33 | | - |
34 | | - const handleDelete = async (id: string) => { |
35 | | - try { |
36 | | - await fetch(`/api/images/${id}`, { method: "DELETE" }) |
37 | | - setImages(images.filter((image) => image.id !== id)) |
38 | | - } catch (error) { |
39 | | - console.error("Error deleting image:", error) |
40 | | - } |
41 | | - } |
42 | | - |
| 12 | +const ImageList: React.FC<ImageListProps> = ({ images }) => { |
43 | 13 | return ( |
44 | | - <div className="grid grid-cols-5 gap-2"> |
45 | | - {images.map((image) => ( |
| 14 | + <div className="mt-2 grid grid-cols-5 gap-3"> |
| 15 | + {images?.map((image) => ( |
46 | 16 | <div |
47 | 17 | key={image.id} |
48 | 18 | className="group relative" |
49 | 19 | > |
50 | | - <img |
51 | | - src={image.url} |
| 20 | + <Image |
| 21 | + src={`${process.env.NEXT_PUBLIC_FRONTEND_URL}${image.url}`} |
52 | 22 | alt={`Image ${image.id}`} |
53 | | - className="h-40 w-40 cursor-pointer object-cover" |
54 | | - onClick={() => handleSelect(image.id)} |
| 23 | + width={90} |
| 24 | + height={90} |
| 25 | + className="h-[90px] w-[90px] cursor-pointer object-cover" |
| 26 | + // onClick={() => handleSelect(image.id)} |
55 | 27 | /> |
56 | 28 | <Button |
57 | 29 | variant="destructive" |
58 | 30 | size="icon" |
59 | 31 | className="absolute right-1 top-1 opacity-0 transition-opacity group-hover:opacity-100" |
60 | | - onClick={() => handleDelete(image.id)} |
| 32 | + // onClick={() => handleDelete(image.id)} |
61 | 33 | > |
62 | 34 | <TrashIcon className="h-4 w-4" /> |
63 | 35 | </Button> |
|
0 commit comments