Skip to content

Commit 7fa4270

Browse files
committed
image not fond des cadexu quand image arrive pas a charger
1 parent 9c30d1b commit 7fa4270

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

compose.dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
build: ./frontend
66
volumes:
77
- ./frontend/src/:/app/src/
8+
- ./frontend/public/:/app/public/
89
healthcheck:
910
test: [ "CMD-SHELL", "curl --fail --request GET --url 'http://localhost:${FRONTEND_PORT}' || exit 1" ]
1011
interval: 10s
138 KB
Loading

frontend/src/components/wishlist/GiftCard.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Gift } from "../../types/Gift";
33
import Icon from "../utils/Icon";
44
import "./giftcard.css";
55
import "./Wishlist.css";
6+
import { useEffect, useState } from "react";
67

78
type GiftCardProps = {
89
gift: Gift;
@@ -14,6 +15,16 @@ type GiftCardProps = {
1415

1516
export default function GiftCard({ gift, className, onEdit, onDelete }: GiftCardProps) {
1617
const { name, description, imageUrl, url } = gift;
18+
const [errorImageUrl, setErrorImageUrl] = useState(false);
19+
20+
useEffect(() => {
21+
if (imageUrl) {
22+
const img = new Image();
23+
img.src = imageUrl;
24+
img.onerror = () => setErrorImageUrl(true);
25+
img.onload = () => setErrorImageUrl(false);
26+
}
27+
}, [imageUrl]);
1728

1829
return (
1930
<div
@@ -26,7 +37,11 @@ export default function GiftCard({ gift, className, onEdit, onDelete }: GiftCard
2637
{url ? (
2738
<a href={url} target="_blank" rel="noopener noreferrer" className="block">
2839
{imageUrl ? (
29-
<img src={imageUrl} alt={name} className="w-full h-40 object-cover" />
40+
<img
41+
src={errorImageUrl ? "/images/gift-not-find.png" : imageUrl}
42+
alt={name}
43+
className={`w-full h-40 ${errorImageUrl ? "object-contain" : "object-cover"}`}
44+
/>
3045
) : (
3146
<div className="flex items-center justify-center w-full h-40 bg-[#FDFBF6]">
3247
<Icon icon="gift" className="text-9xl text-[#EA4B09] opacity-70" />
@@ -40,7 +55,11 @@ export default function GiftCard({ gift, className, onEdit, onDelete }: GiftCard
4055
) : (
4156
<div>
4257
{imageUrl ? (
43-
<img src={imageUrl} alt={name} className="w-full h-40 object-cover" />
58+
<img
59+
src={errorImageUrl ? "/images/gift-not-find.png" : imageUrl}
60+
alt={name}
61+
className={`w-full h-40 ${errorImageUrl ? "object-contain" : "object-cover"}`}
62+
/>
4463
) : (
4564
<div className="flex items-center justify-center w-full h-40 bg-[#FDFBF6]">
4665
<Icon icon="gift" className="text-9xl text-[#EA4B09] opacity-70" />

0 commit comments

Comments
 (0)