@stoker-platform/web-app 0.5.195 → 0.5.196
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/Images.tsx +12 -7
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/Images.tsx
CHANGED
|
@@ -53,31 +53,36 @@ interface RowImageProps {
|
|
|
53
53
|
|
|
54
54
|
const RowImage = memo(
|
|
55
55
|
({ src, alt }: RowImageProps) => {
|
|
56
|
-
const
|
|
56
|
+
const imgRef = useRef<HTMLImageElement | null>(null)
|
|
57
|
+
const [loadedSrc, setLoadedSrc] = useState<string | null>(null)
|
|
57
58
|
const [showSpinner, setShowSpinner] = useState(false)
|
|
59
|
+
const isLoaded = loadedSrc === src
|
|
58
60
|
|
|
59
61
|
useEffect(() => {
|
|
60
|
-
|
|
62
|
+
if (imgRef.current?.complete && imgRef.current.naturalWidth > 0) {
|
|
63
|
+
setLoadedSrc(src)
|
|
64
|
+
setShowSpinner(false)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
61
67
|
setShowSpinner(false)
|
|
62
68
|
const timer = setTimeout(() => {
|
|
63
|
-
|
|
69
|
+
setShowSpinner(true)
|
|
64
70
|
}, 500)
|
|
65
71
|
return () => clearTimeout(timer)
|
|
66
72
|
}, [src])
|
|
67
73
|
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (isLoaded) setShowSpinner(false)
|
|
70
|
-
}, [isLoaded])
|
|
71
74
|
return (
|
|
72
75
|
<>
|
|
73
76
|
<img
|
|
77
|
+
key={src}
|
|
78
|
+
ref={imgRef}
|
|
74
79
|
alt={alt}
|
|
75
80
|
className={cn(
|
|
76
81
|
"max-w-full max-h-full object-contain rounded-md ease-in-out duration-300 transition-opacity-transform hover:scale-95",
|
|
77
82
|
{ "opacity-0": !isLoaded, "opacity-100": isLoaded },
|
|
78
83
|
)}
|
|
79
84
|
src={getSafeUrl(src)}
|
|
80
|
-
onLoad={() =>
|
|
85
|
+
onLoad={() => setLoadedSrc(src)}
|
|
81
86
|
/>
|
|
82
87
|
{!isLoaded && showSpinner && (
|
|
83
88
|
<div className="absolute inset-0 flex items-center justify-center">
|