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