1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-28 19:25:03 +00:00
seahub/frontend/src/components/dialog/insert-repo-image-dialog.js
Michael An 08abceb14b
custom modal header close icon (#7240)
* seahub custom modal header

* add custom modal header

* special modal use custom close
2024-12-24 11:20:40 +08:00

95 lines
2.9 KiB
JavaScript

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 (
<Modal isOpen={true} toggle={toggle} size='lg'>
<SeahubModalHeader toggle={toggle}>{gettext('Select Image')}</SeahubModalHeader>
<ModalBody>
<div className="d-flex">
<div className="col-6">
<FileChooser
isShowFile={true}
repoID={this.props.repoID}
onDirentItemClick={this.onDirentItemClick}
onRepoItemClick={this.onRepoItemClick}
mode="current_repo_and_other_repos"
fileSuffixes={fileSuffixes}
/>
</div>
<div className="insert-image-container col-6">
{imageUrl ?
<img src={imageUrl} className='d-inline-block mh-100 mw-100' alt=''/> :
<span>{gettext('No preview')}</span>
}
</div>
</div>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={toggle}>{gettext('Cancel')}</Button>
{this.state.selectedPath ?
<Button color="primary" onClick={this.insertImage}>{gettext('Submit')}</Button>
: <Button color="primary" disabled>{gettext('Submit')}</Button>
}
</ModalFooter>
</Modal>
);
}
}
InsertRepoImageDialog.propTypes = propTypes;
export default InsertRepoImageDialog;