import React from 'react'; import PropTypes from 'prop-types'; import { Button, Modal, ModalBody, ModalFooter } from 'reactstrap'; import { gettext } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import FileChooser from '../file-chooser'; import SeahubModalHeader from '@/components/common/seahub-modal-header'; import '../../css/insert-repo-image-dialog.css'; const { siteRoot, serviceUrl } = window.app.config; const propTypes = { repoID: PropTypes.string.isRequired, filePath: PropTypes.string.isRequired, toggleCancel: PropTypes.func.isRequired, }; class InsertRepoImageDialog extends React.Component { constructor(props) { super(props); this.state = { repo: null, selectedPath: '', }; } insertImage = () => { const url = serviceUrl + '/lib/' + this.state.repo.repo_id + '/file' + Utils.encodePath(this.state.selectedPath) + '?raw=1'; window.richMarkdownEditor.onInsertImage(url); this.props.toggleCancel(); }; onDirentItemClick = (repo, selectedPath, dirent) => { if (dirent.type === 'file' && Utils.imageCheck(dirent.name)) { this.setState({ repo: repo, selectedPath: selectedPath, }); } else { this.setState({ repo: null, selectedPath: '' }); } }; onRepoItemClick = () => { this.setState({ repo: null, selectedPath: '' }); }; render() { const toggle = this.props.toggleCancel; const fileSuffixes = ['jpg', 'png', 'jpeg', 'gif', 'bmp']; let imageUrl; if (this.state.repo) { imageUrl = siteRoot + 'thumbnail/' + this.state.repo.repo_id + '/1024' + this.state.selectedPath; } return ( {gettext('Select Image')}
{imageUrl ? : {gettext('No preview')} }
{this.state.selectedPath ? : }
); } } InsertRepoImageDialog.propTypes = propTypes; export default InsertRepoImageDialog;