mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
fallback component for broken thumbnails
This commit is contained in:
@@ -9,6 +9,7 @@ import { getFileIcon } from '../utils/getFileIcon'
|
|||||||
import { getBaseUrl } from '../utils/getBaseUrl'
|
import { getBaseUrl } from '../utils/getBaseUrl'
|
||||||
import { formatModifiedDateTime } from '../utils/fileDetails'
|
import { formatModifiedDateTime } from '../utils/fileDetails'
|
||||||
import { Checkbox, Downloading } from './FileListing'
|
import { Checkbox, Downloading } from './FileListing'
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
type OdFolderChildren = OdFolderObject['value'][number]
|
type OdFolderChildren = OdFolderObject['value'][number]
|
||||||
|
|
||||||
@@ -26,12 +27,20 @@ const GridItem = ({ c }: { c: OdFolderChildren }) => {
|
|||||||
// We use the generated medium thumbnail for rendering preview images
|
// We use the generated medium thumbnail for rendering preview images
|
||||||
const thumbnail = c.thumbnails && c.thumbnails.length > 0 ? c.thumbnails[0].medium : null
|
const thumbnail = c.thumbnails && c.thumbnails.length > 0 ? c.thumbnails[0].medium : null
|
||||||
|
|
||||||
|
// Some thumbnails are broken, so we check for onerror event in the image component
|
||||||
|
const [brokenThumbnail, setBrokenThumbnail] = useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="h-32 overflow-hidden rounded border border-gray-900/10 dark:border-gray-500/30">
|
<div className="h-32 overflow-hidden rounded border border-gray-900/10 dark:border-gray-500/30">
|
||||||
{thumbnail ? (
|
{thumbnail && !brokenThumbnail ? (
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
<img className="h-full w-full object-cover object-top" src={thumbnail.url} alt={c.name} />
|
<img
|
||||||
|
className="h-full w-full object-cover object-top"
|
||||||
|
src={thumbnail.url}
|
||||||
|
alt={c.name}
|
||||||
|
onError={() => setBrokenThumbnail(true)}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="relative flex h-full w-full items-center justify-center rounded-lg">
|
<div className="relative flex h-full w-full items-center justify-center rounded-lg">
|
||||||
<ChildIcon />
|
<ChildIcon />
|
||||||
|
|||||||
Reference in New Issue
Block a user