Skip to content

Commit 0ff2ec7

Browse files
committed
feat: allow to select/de-select image
1 parent 883c23b commit 0ff2ec7

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

apps/web/@/molecules/upload/ImageList.tsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,57 @@
1-
import React from "react"
1+
import React, { useState } from "react"
22
import Image from "next/image"
33

44
import { Image as ImageType } from "database"
5-
import { TrashIcon } from "lucide-react"
5+
import { Check, Circle, TrashIcon } from "lucide-react"
66
import { Button } from "ui"
77

88
type ImageListProps = {
99
images: ImageType[]
1010
}
1111

1212
const ImageList: React.FC<ImageListProps> = ({ images }) => {
13+
const [selectedImage, setSelectedImage] = useState<ImageType | null>(null)
14+
1315
return (
14-
<div className="mt-2 grid grid-cols-5 gap-3">
16+
<div className="mt-2 flex flex-wrap gap-3">
1517
{images?.map((image) => (
1618
<div
1719
key={image.id}
18-
className="group relative"
20+
className="group relative border"
1921
>
2022
<Image
2123
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"
2728
/>
2829
<Button
2930
variant="destructive"
3031
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")}
3334
>
3435
<TrashIcon className="h-4 w-4" />
3536
</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>
3655
</div>
3756
))}
3857
</div>

apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"html-react-parser": "^5.0.11",
4141
"isomorphic-dompurify": "^2.14.0",
4242
"lowlight": "^3.1.0",
43-
"lucide-react": "^0.270.0",
43+
"lucide-react": "^0.427.0",
4444
"negotiator": "^0.6.3",
4545
"next": "14.2.0-canary.50",
4646
"next-auth": "^4.24.5",

pnpm-lock.yaml

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)