1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-15 07:52:14 +00:00
seahub/frontend/src/components/dialog/readme-dialog.js

70 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-01-19 08:20:40 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
2022-05-25 07:22:43 +00:00
import { MarkdownViewer } from '@seafile/seafile-editor';
2019-01-19 08:20:40 +00:00
import Loading from '../../components/loading';
import { seafileAPI } from '../../utils/seafile-api';
import { gettext, mediaUrl } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import toaster from '../toast';
2019-01-19 08:20:40 +00:00
const propTypes = {
repoID: PropTypes.string.isRequired,
filePath: PropTypes.string.isRequired,
2019-01-19 09:45:28 +00:00
fileName: PropTypes.string.isRequired,
2019-01-19 08:20:40 +00:00
href: PropTypes.string,
toggleCancel: PropTypes.func.isRequired,
};
class ReadmeDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
readmeContent: null,
isLoading: true,
};
}
componentDidMount() {
seafileAPI.getFileDownloadLink(this.props.repoID, this.props.filePath).then(res => {
seafileAPI.getFileContent(res.data).then(res => {
this.setState({
readmeContent: res.data,
isLoading: false,
});
2019-01-19 08:20:40 +00:00
});
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
2019-01-19 08:20:40 +00:00
});
}
render() {
return (
2019-01-25 07:48:30 +00:00
<Modal isOpen={true} toggle={this.props.toggleCancel} className="readme-dialog" size="lg">
<ModalHeader>{this.props.fileName}
<a className="readme-dialog-edit" href={this.props.href} target='_blank'><i className="fa fa-pencil-alt"></i></a>
2019-01-19 08:20:40 +00:00
</ModalHeader>
<ModalBody>
{this.state.isLoading ?
2019-01-19 08:20:40 +00:00
<Loading />:
<MarkdownViewer
markdownContent={this.state.readmeContent}
showTOC={false}
scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'}
/>
2019-01-19 08:20:40 +00:00
}
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggleCancel}>{gettext('Close')}</Button>
</ModalFooter>
</Modal>
);
}
}
ReadmeDialog.propTypes = propTypes;
export default ReadmeDialog;