Files
hats-app/components/ui/lazy-image.tsx
T
Ichsan Kurniawan ffcf3c6e58 Refactor task views with layout toggles
This commit reorganizes client and project-assignment screens into dedicated grid/list components, adds a shared layout toggle via the URL query string, and updates task pages to render the selected view consistently. It also moves shared client form logic into a client folder, improves status badge formatting, extends LazyImage with custom image classes, and updates the illustration assets and Lucide dependency used in the task UI.
2026-10-01 18:32:56 +07:00

44 lines
1.2 KiB
TypeScript

"use client"
import { cn } from "@/lib/utils";
import { useState, useRef, useEffect } from "react";
export function LazyImage({
src,
alt,
className,
imgClassName,
}: {
src: string;
alt: string;
className?: string;
imgClassName?: string;
}) {
const [isLoaded, setIsLoaded] = useState(false);
const imgRef = useRef<HTMLImageElement>(null);
// Check if the image is already loaded from the cache
useEffect(() => {
if (imgRef.current?.complete) {
setIsLoaded(true);
}
}, [src]); // Re-run this check if the src prop changes
return (
<div className={cn("relative overflow-hidden bg-secondary/50", className)}>
<img
ref={imgRef}
src={src}
alt={alt}
loading="lazy"
referrerPolicy="no-referrer"
onLoad={() => setIsLoaded(true)}
className={cn(
"w-full h-full object-cover transition-all duration-700 ease-in-out",
imgClassName,
isLoaded ? "blur-0 scale-100 opacity-100" : "blur-xl scale-110 opacity-0"
)}
/>
</div>
);
}