Skip to content

Commit

Permalink
Broken images are not ideal
Browse files Browse the repository at this point in the history
Fixes #225
  • Loading branch information
andrew-codes committed Feb 19, 2024
1 parent 45fbe9f commit 36980a4
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions apps/playnite-web/src/components/GameFigure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Image = styled('img', {
height: `${width}`,
objectFit: 'cover',
width,
display: 'block',
}))

const GameFigure: FC<
Expand All @@ -39,6 +40,8 @@ const GameFigure: FC<
}, [])
const { ref } = useInView({ onChange: handleChange })

const [imageHasError, setImageHasError] = useState(false)

return (
<Figure style={style} ref={ref} width={width}>
{hasBeenInViewBefore || noDefer
Expand All @@ -47,13 +50,24 @@ const GameFigure: FC<
sx={{ position: 'relative' }}
key={`${game.oid.asString}-image`}
>
<Image
src={game.cover}
alt={game.name}
width={width}
loading="eager"
onError={(e) => {}}
/>
{!imageHasError ? (
<Image
src={game.cover}
alt={game.name}
width={width}
loading="eager"
onError={(e) => {
setImageHasError(true)
}}
/>
) : (
<Box
sx={{
height: `${width}`,
width: `${width}`,
}}
></Box>
)}
<Box
sx={(theme) => ({
position: 'absolute',
Expand Down

0 comments on commit 36980a4

Please sign in to comment.