2023-09-13 00:40:50 +00:00
|
|
|
import React from 'react';
|
2019-04-09 04:32:25 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { gettext } from '../../utils/constants';
|
2020-01-14 05:40:59 +00:00
|
|
|
import Lightbox from '@seafile/react-image-lightbox';
|
|
|
|
import '@seafile/react-image-lightbox/style.css';
|
2019-04-09 04:32:25 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
imageItems: PropTypes.array.isRequired,
|
|
|
|
imageIndex: PropTypes.number.isRequired,
|
|
|
|
closeImagePopup: PropTypes.func.isRequired,
|
|
|
|
moveToPrevImage: PropTypes.func.isRequired,
|
2024-09-03 02:31:42 +00:00
|
|
|
moveToNextImage: PropTypes.func.isRequired,
|
|
|
|
onDeleteImage: PropTypes.func,
|
|
|
|
onRotateImage: PropTypes.func,
|
2019-04-09 04:32:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ImageDialog extends React.Component {
|
|
|
|
|
2024-09-03 02:31:42 +00:00
|
|
|
downloadImage = (imageSrc) => {
|
2024-09-19 03:12:10 +00:00
|
|
|
let downloadUrl = imageSrc;
|
2024-09-03 02:31:42 +00:00
|
|
|
|
|
|
|
if (document.getElementById('downloadFrame')) {
|
|
|
|
document.body.removeChild(document.getElementById('downloadFrame'));
|
|
|
|
}
|
|
|
|
|
|
|
|
let iframe = document.createElement('iframe');
|
|
|
|
iframe.setAttribute('id', 'downloadFrame');
|
|
|
|
iframe.style.display = 'none';
|
|
|
|
iframe.src = downloadUrl;
|
|
|
|
document.body.appendChild(iframe);
|
|
|
|
};
|
|
|
|
|
|
|
|
onViewOriginal = () => {
|
|
|
|
const imageSrc = this.props.imageItems[this.props.imageIndex].url;
|
|
|
|
window.open(imageSrc, '_blank');
|
|
|
|
};
|
|
|
|
|
|
|
|
onRotateImage = (angle) => {
|
|
|
|
if (this.props.onRotateImage) {
|
|
|
|
this.props.onRotateImage(this.props.imageIndex, angle);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-09 04:32:25 +00:00
|
|
|
render() {
|
|
|
|
const imageItems = this.props.imageItems;
|
|
|
|
const imageIndex = this.props.imageIndex;
|
|
|
|
const imageItemsLength = imageItems.length;
|
2022-12-31 11:38:51 +00:00
|
|
|
const name = imageItems[imageIndex].name;
|
|
|
|
const imageTitle = `${name} (${imageIndex + 1}/${imageItemsLength})`;
|
2024-09-05 06:56:52 +00:00
|
|
|
const mainImg = imageItems[imageIndex];
|
|
|
|
const nextImg = imageItems[(imageIndex + 1) % imageItemsLength];
|
|
|
|
const prevImg = imageItems[(imageIndex + imageItemsLength - 1) % imageItemsLength];
|
|
|
|
const mainSrc = mainImg.thumbnail || mainImg.src;
|
|
|
|
const nextSrc = nextImg.thumbnail || nextImg.src;
|
|
|
|
const prevSrc = prevImg.thumbnail || prevImg.src;
|
2019-04-09 04:32:25 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Lightbox
|
2024-09-03 02:31:42 +00:00
|
|
|
wrapperClassName='custom-image-previewer'
|
2022-12-31 11:38:51 +00:00
|
|
|
imageTitle={imageTitle}
|
2024-09-05 06:56:52 +00:00
|
|
|
mainSrc={mainSrc}
|
|
|
|
nextSrc={nextSrc}
|
|
|
|
prevSrc={prevSrc}
|
2019-04-09 04:32:25 +00:00
|
|
|
onCloseRequest={this.props.closeImagePopup}
|
|
|
|
onMovePrevRequest={this.props.moveToPrevImage}
|
|
|
|
onMoveNextRequest={this.props.moveToNextImage}
|
|
|
|
imagePadding={70}
|
|
|
|
imageLoadErrorMessage={gettext('The image could not be loaded.')}
|
|
|
|
prevLabel={gettext('Previous (Left arrow key)')}
|
|
|
|
nextLabel={gettext('Next (Right arrow key)')}
|
|
|
|
closeLabel={gettext('Close (Esc)')}
|
|
|
|
zoomInLabel={gettext('Zoom in')}
|
|
|
|
zoomOutLabel={gettext('Zoom out')}
|
2024-09-03 02:31:42 +00:00
|
|
|
enableRotate={true}
|
2024-09-19 03:12:10 +00:00
|
|
|
onClickDownload={() => this.downloadImage(imageItems[imageIndex].downloadURL)}
|
2024-09-03 02:31:42 +00:00
|
|
|
onClickDelete={this.props.onDeleteImage ? () => this.props.onDeleteImage(imageItems[imageIndex].name) : null}
|
|
|
|
onViewOriginal={this.onViewOriginal}
|
|
|
|
viewOriginalImageLabel={gettext('View original image')}
|
|
|
|
onRotateImage={this.onRotateImage}
|
2019-04-09 04:32:25 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageDialog.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default ImageDialog;
|