"use client"; import { APIs } from "@/app/lib"; import { pathAssetImage } from "@/app/lib/path_asset_image"; import { RouterImagePreview } from "@/app/lib/router_hipmi/router_image_preview"; import { Center, Image, Skeleton } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { useRouter } from "next/navigation"; import { useState } from "react"; type IRadius = "xs" | "sm" | "md" | "lg" | "xl"; export function ComponentGlobal_LoadImage({ fileId, maw, h, radius, }: { fileId: string; maw?: number | string; h?: number; radius?: IRadius; }) { const router = useRouter(); const [isImage, setIsImage] = useState(null); const [isLoading, setIsLoading] = useState(false); const url = APIs.GET({ fileId: fileId, size: "500" }); useShallowEffect(() => { onLoadImage(); }, []); async function onLoadImage() { try { const res = await fetch(url); if (res.ok) { return setIsImage(true); } setIsImage(false); } catch (error) { console.log(error); } } if (isImage === null) return (
); if (!isImage) return ( <>
No Image
); return ( <>
{ setIsLoading(true); router.push(RouterImagePreview.main({ id: fileId }), { scroll: false, }); }} opacity={isLoading ? 0.5 : 1} radius={radius ? radius : 0} alt="Image" height={h ? h : 250} maw={maw ? maw : 200} miw={200} src={url} /> {isLoading ? ( Loader ) : ( "" )}
); }