mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-10 17:26:38 +08:00
prettier
This commit is contained in:
@@ -1,51 +1,56 @@
|
||||
"use client"
|
||||
'use client';
|
||||
|
||||
import * as React from "react"
|
||||
import {ImageOff} from "lucide-react"
|
||||
import * as React from 'react';
|
||||
import { ImageOff } from 'lucide-react';
|
||||
|
||||
import {cn} from "@/lib/utils"
|
||||
import {getFileUrl, type ImageQuality} from "@/lib/services/upload/utils"
|
||||
import { cn } from '@/lib/utils';
|
||||
import { getFileUrl, type ImageQuality } from '@/lib/services/upload/utils';
|
||||
|
||||
type FileImagePreviewProps = {
|
||||
fileId: string | number
|
||||
alt: string
|
||||
quality?: ImageQuality
|
||||
className?: string
|
||||
fallbackClassName?: string
|
||||
variant?: "compact" | "default"
|
||||
}
|
||||
fileId: string | number;
|
||||
alt: string;
|
||||
quality?: ImageQuality;
|
||||
className?: string;
|
||||
fallbackClassName?: string;
|
||||
variant?: 'compact' | 'default';
|
||||
};
|
||||
|
||||
export function FileImagePreview({
|
||||
fileId,
|
||||
alt,
|
||||
quality = "low",
|
||||
quality = 'low',
|
||||
className,
|
||||
fallbackClassName,
|
||||
variant = "default",
|
||||
variant = 'default',
|
||||
}: FileImagePreviewProps) {
|
||||
const [failed, setFailed] = React.useState(false)
|
||||
const src = getFileUrl(fileId, quality)
|
||||
const [failed, setFailed] = React.useState(false);
|
||||
const src = getFileUrl(fileId, quality);
|
||||
|
||||
React.useEffect(() => {
|
||||
setFailed(false)
|
||||
}, [fileId, quality])
|
||||
setFailed(false);
|
||||
}, [fileId, quality]);
|
||||
|
||||
if (!src || failed) {
|
||||
return (
|
||||
<div
|
||||
role="img"
|
||||
role='img'
|
||||
aria-label={`${alt} 加载失败`}
|
||||
className={cn(
|
||||
"flex size-full flex-col items-center justify-center gap-1 bg-muted/50 text-muted-foreground",
|
||||
'flex size-full flex-col items-center justify-center gap-1 bg-muted/50 text-muted-foreground',
|
||||
fallbackClassName,
|
||||
)}
|
||||
>
|
||||
<ImageOff className={cn("shrink-0 opacity-70", variant === "compact" ? "size-3.5" : "size-5")} />
|
||||
{variant === "default" && (
|
||||
<span className="text-[10px] leading-none">加载失败</span>
|
||||
<ImageOff
|
||||
className={cn(
|
||||
'shrink-0 opacity-70',
|
||||
variant === 'compact' ? 'size-3.5' : 'size-5',
|
||||
)}
|
||||
/>
|
||||
{variant === 'default' && (
|
||||
<span className='text-[10px] leading-none'>加载失败</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -53,10 +58,10 @@ export function FileImagePreview({
|
||||
<img
|
||||
src={src}
|
||||
alt={alt}
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
loading='lazy'
|
||||
decoding='async'
|
||||
className={className}
|
||||
onError={() => setFailed(true)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user