lbry-desktop/ui/component/viewers/imageViewer.jsx

32 lines
764 B
React
Raw Normal View History

2019-08-06 05:25:33 +02:00
// @flow
import React from 'react';
import Card from 'component/common/card';
import ErrorText from 'component/common/error-text';
2019-08-06 05:25:33 +02:00
type Props = {
source: string,
};
function ImageViewer(props: Props) {
const { source } = props;
const [loadingError, setLoadingError] = React.useState(false);
2019-08-06 05:25:33 +02:00
return (
<React.Fragment>
{loadingError && (
<Card
2020-08-26 22:28:33 +02:00
title={__('Error displaying image')}
actions={<ErrorText>There was an error displaying the image. You may still download it.</ErrorText>}
/>
)}
{!loadingError && (
2020-04-14 01:48:11 +02:00
<div className="file-viewer">
<img src={source} onError={() => setLoadingError(true)} />
</div>
)}
</React.Fragment>
2019-08-06 05:25:33 +02:00
);
}
export default ImageViewer;