Files
hats-app/components/ViewAvatar.tsx
T
Ichsan Kurniawan 5e439ea9f7 remove next image
2026-01-28 21:10:07 +07:00

106 lines
4.6 KiB
TypeScript

'use client'
import { FC } from 'react';
import { LazyLoadImage } from 'react-lazy-load-image-component';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from './ui/dialog';
import { cn } from '@/lib/utils';
type Props = {
avatar: string | null; // Allow null to handle fallback logic safely
className?: string;
isPresence?: boolean;
// sizes and quality are removed as they are specific to Next/Image server processing
};
const ViewAvatar: FC<Props> = ({ avatar, className, isPresence }) => {
return (
<>
{avatar ? (
<Dialog>
<DialogTrigger asChild>
{/* 1. TRIGGER IMAGE
Removed the wrapper div. Applied classes directly to LazyLoadImage.
Added `block` to wrapperClassName to prevent extra inline spacing.
*/}
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt="avatar"
src={`${process.env.BASE_URL_IMG}${avatar}`}
effect="blur"
wrapperClassName="w-full h-full"
className="w-full h-full rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</span>
</DialogTrigger>
<DialogContent className={cn(
"overflow-hidden p-0 rounded-2xl",
isPresence ? "w-full max-w-screen-3xl h-auto" : "w-full h-[400px] sm:w-[500px] sm:h-[500px]"
)}>
<DialogHeader className='sr-only'>
<DialogTitle>Profile</DialogTitle>
<DialogDescription>Description of profile avatar</DialogDescription>
</DialogHeader>
{/* 2. DIALOG CONTENT IMAGE
Logic for Presence vs Standard is much simpler now.
Standard CSS handles the width/height.
*/}
<LazyLoadImage
src={`${process.env.BASE_URL_IMG}${avatar}`}
alt="avatar"
effect="blur"
wrapperClassName="w-full h-full block" // Ensures the wrapper fills the dialog
className={cn(
"w-full", // Always full width of container
isPresence ? "h-auto object-contain" : "h-full object-cover shadow-sm border border-border"
)}
/>
</DialogContent>
</Dialog>
) : (
// 3. FALLBACK IMAGE
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt='avatar'
src='/assets/no-avatar.jpg'
effect="blur"
wrapperClassName="w-full h-full"
className='w-full h-full shadow-sm rounded-full object-cover border border-border'
/>
</span>
)}
</>
);
}
export const Avatar: FC<Props> = ({ avatar, className }) => {
return (
<>
{avatar ? (
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
src={`${process.env.BASE_URL_IMG}${avatar}`}
alt="avatar"
effect="blur"
wrapperClassName="w-full h-full"
className="w-full h-full rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</span>
) : (
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt='avatar'
src='/assets/no-avatar.jpg'
effect="blur"
wrapperClassName="w-full h-full"
className='w-full h-full shadow-sm rounded-full object-cover border border-border'
/>
</span>
)}
</>
);
}
export default ViewAvatar;