lbry-desktop/ui/component/viewers/imageViewer.jsx
Jeffrey Fisher b786ba82ae First attempt to fix #3993. Show error message
if image is not able to be displayed by browser.
2020-04-21 17:07:56 -04:00

32 lines
796 B
JavaScript

// @flow
import React from 'react';
import Card from 'component/common/card';
import ErrorText from 'component/common/error-text';
type Props = {
source: string,
};
function ImageViewer(props: Props) {
const { source } = props;
const [loadingError, setLoadingError] = React.useState(false);
return (
<React.Fragment>
{loadingError && (
<Card
title={__('Error Displaying Image')}
defaultExpand
actions={<ErrorText>There was an error displaying the image. You may still download it.</ErrorText>}
/>
)}
{!loadingError && (
<div className="file-render__viewer">
<img src={source} onError={() => setLoadingError(true)} />
</div>
)}
</React.Fragment>
);
}
export default ImageViewer;