2019-08-06 05:25:33 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2020-04-18 03:41:15 +02:00
|
|
|
import Card from 'component/common/card';
|
|
|
|
import ErrorText from 'component/common/error-text';
|
2021-02-17 16:02:57 +01:00
|
|
|
import ZoomableImage from 'component/zoomableImage';
|
2019-08-06 05:25:33 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
source: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
function ImageViewer(props: Props) {
|
2021-02-17 15:44:37 +01:00
|
|
|
const { source } = props;
|
2020-04-18 03:41:15 +02:00
|
|
|
const [loadingError, setLoadingError] = React.useState(false);
|
|
|
|
|
2019-08-06 05:25:33 +02:00
|
|
|
return (
|
2020-04-18 03:41:15 +02:00
|
|
|
<React.Fragment>
|
|
|
|
{loadingError && (
|
|
|
|
<Card
|
2020-08-26 22:28:33 +02:00
|
|
|
title={__('Error displaying image')}
|
2020-04-18 03:41:15 +02:00
|
|
|
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">
|
2021-02-17 16:02:57 +01:00
|
|
|
<ZoomableImage src={source} onError={() => setLoadingError(true)} />
|
2020-04-18 03:41:15 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
2019-08-06 05:25:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ImageViewer;
|