Skip to content

Commit

Permalink
fix: enhance image rendering with responsive grid and error handling …
Browse files Browse the repository at this point in the history
…improvements
  • Loading branch information
blinko-space committed Dec 7, 2024
1 parent 87be1ce commit 3bf4ad5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/Common/AttachmentRender/imageRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,50 @@ const ImageThumbnailRender = ({ file, className }: { file: FileType, className?:
}, [isOriginalError])
return <Image
src={currentSrc}
classNames={{
wrapper: '!max-w-full',
}}
onError={() => {
if (file.preview == currentSrc) {
return setIsOriginalError(true)
}
setCurrentSrc(file.preview)
}}
className={className}
className={`object-cover w-full ${className} `} // 修改这里
/>
}

const ImageRender = observer((props: IProps) => {
const { files, preview = false, columns = 3 } = props
const { files, preview = false, columns } = props
const isPc = useMediaQuery('(min-width: 768px)')
const images = files?.filter(i => i.previewType == 'image')

const imageRenderClassName = useMemo(() => {
const imageLength = files?.filter(i => i.previewType == 'image')?.length
if (columns) {
return `grid grid-cols-${columns} gap-2`
}
if (!preview && !isPc) {
return `flex items-center overflow-x-scroll gap-2`
}
if (imageLength == 1) {
return `grid grid-cols-2 gap-2`
}
if (imageLength > 1 && imageLength <= 5) {
return `grid grid-cols-2 gap-2`
return `grid grid-cols-2 gap-3`
}
if (imageLength > 5) {
return `grid grid-cols-3 gap-2`
return `grid grid-cols-3 gap-3`
}
return ''
}, [images])

const imageHeight = useMemo(() => {
const imageLength = files?.filter(i => i.previewType == 'image')?.length
if (!preview&& !isPc) {
if (columns) {
return `max-h-[100px] w-auto`
}
if (!preview && !isPc) {
return `h-[80px] w-[80px] min-w-[80px]`
}
if (imageLength == 1) {
Expand Down

0 comments on commit 3bf4ad5

Please sign in to comment.