Skip to content

Commit

Permalink
fix(FileIconShortcut): Manage not-found error
Browse files Browse the repository at this point in the history
This change displays the fallback when the image is not found. This can happen because useFetchShorcut can return images from the registry
  • Loading branch information
cballevre committed Nov 16, 2023
1 parent 374b77e commit c6839d4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/drive/web/modules/filelist/FileIconShortcut.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState } from 'react'

import { useClient, useFetchShortcut } from 'cozy-client'
import Icon from 'cozy-ui/transpiled/react/Icon'
Expand All @@ -8,14 +8,23 @@ import GlobeIcon from 'cozy-ui/transpiled/react/Icons/Globe'
const FileIconShortcut = ({ file, size = 32 }) => {
const client = useClient()
const { shortcutImg } = useFetchShortcut(client, file.id)
const [isBroken, setBroken] = useState(null)

return (
<>
<div style={{ display: shortcutImg ? 'block' : 'none' }}>
<img src={shortcutImg} width={size} height={size} />
<div style={{ display: shortcutImg && !isBroken ? 'block' : 'none' }}>
<img
src={shortcutImg}
width={size}
height={size}
onError={() => {
setBroken(true)
}}
/>
</div>
<div
style={{
display: !shortcutImg ? 'block' : 'none'
display: !shortcutImg || isBroken ? 'block' : 'none'
}}
>
<Icon icon={GlobeIcon} size={size} color={palette.coolGrey} />
Expand Down

0 comments on commit c6839d4

Please sign in to comment.