mirror of
https://github.com/urbit/shrub.git
synced 2025-01-02 17:43:32 +03:00
docket-image: handle broken images
This commit is contained in:
parent
2ccfcd9d7f
commit
f72da65014
@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { Docket } from '@urbit/api/docket';
|
||||
import cn from 'classnames';
|
||||
import { useTileColor } from '../tiles/useTileColor';
|
||||
@ -19,13 +19,20 @@ const sizeMap: Record<DocketImageSizes, string> = {
|
||||
|
||||
export function DocketImage({ color, image, className = '', size = 'full' }: DocketImageProps) {
|
||||
const { tileColor } = useTileColor(color);
|
||||
const [imageError, setImageError] = useState(false);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn('flex-none relative bg-gray-200 overflow-hidden', sizeMap[size], className)}
|
||||
style={{ backgroundColor: tileColor }}
|
||||
>
|
||||
{image && (
|
||||
<img className="absolute top-0 left-0 h-full w-full object-cover" src={image} alt="" />
|
||||
{image && !imageError && (
|
||||
<img
|
||||
className="absolute top-0 left-0 h-full w-full object-cover"
|
||||
src={image}
|
||||
alt=""
|
||||
onError={() => setImageError(true)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
@ -199,6 +199,8 @@ const ClampedText = styled(Text)`
|
||||
type AppTileProps = Treaty & BoxProps;
|
||||
|
||||
export function AppTile({ color, image, ...props }: AppTileProps) {
|
||||
const [imageError, setImageError] = useState(false);
|
||||
|
||||
return (
|
||||
<Box
|
||||
position="relative"
|
||||
@ -210,7 +212,7 @@ export function AppTile({ color, image, ...props }: AppTileProps) {
|
||||
bg={color || 'washedGray'}
|
||||
{...props}
|
||||
>
|
||||
{image && (
|
||||
{image && !imageError && (
|
||||
<Image
|
||||
src={image}
|
||||
position="absolute"
|
||||
@ -218,6 +220,7 @@ export function AppTile({ color, image, ...props }: AppTileProps) {
|
||||
left="0"
|
||||
width="100%"
|
||||
height="100%"
|
||||
onError={() => setImageError(true)}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
|
Loading…
Reference in New Issue
Block a user