From a1ac0e6c1f04f7fea5a69167ee00a69a88f656f5 Mon Sep 17 00:00:00 2001 From: precious-macaulay Date: Wed, 15 Jan 2025 21:23:53 +0100 Subject: [PATCH] Add skeleton loading state to GalleryItem for improved image loading experience --- src/components/GalleryItem.tsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/components/GalleryItem.tsx b/src/components/GalleryItem.tsx index 3049041..457bd51 100644 --- a/src/components/GalleryItem.tsx +++ b/src/components/GalleryItem.tsx @@ -5,6 +5,7 @@ import { useNavigate } from "react-router-dom"; import { useLike } from "@/hooks/useLike"; import { useCopy } from "@/hooks/useCopy"; import { Prompt } from "@/types"; +import { Skeleton } from "./ui/skeleton"; interface GalleryItemProps { prompt: Prompt; @@ -15,6 +16,7 @@ const GalleryItem: React.FC = ({ prompt, index }) => { const navigate = useNavigate(); const { isLiked: initialIsLiked, handleLike } = useLike(prompt.liked); const { isCopied, handleCopy } = useCopy(); + const [imageLoaded, setImageLoaded] = useState(false); // Local state to track like status and like count const [isLiked, setIsLiked] = useState(initialIsLiked); @@ -40,19 +42,12 @@ const GalleryItem: React.FC = ({ prompt, index }) => { } >
+ {!imageLoaded && } {`Image { - e.currentTarget.onerror = null; - e.currentTarget.src = - "https://www.astria.ai/assets/logo-b4e21f646fb5879eb91113a70eae015a7413de8920960799acb72c60ad4eaa99.png"; - }} + onLoad={() => setImageLoaded(true)} />
@@ -62,8 +57,8 @@ const GalleryItem: React.FC = ({ prompt, index }) => {