2024-06-28 00:39:44 +00:00
|
|
|
import React from 'react';
|
2019-02-21 09:37:04 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2024-09-07 08:29:45 +00:00
|
|
|
import { Modal, ModalBody } from 'reactstrap';
|
2019-02-21 09:37:04 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
2024-09-10 03:46:50 +00:00
|
|
|
import { siteRoot, mediaUrl } from '../../utils/constants';
|
2023-12-26 06:35:44 +00:00
|
|
|
import SeafileMarkdownViewer from '../seafile-markdown-viewer';
|
2019-02-21 09:37:04 +00:00
|
|
|
|
2024-09-10 03:46:50 +00:00
|
|
|
import './markdown-viewer-dialog.css';
|
2024-09-07 08:29:45 +00:00
|
|
|
|
2019-02-21 09:37:04 +00:00
|
|
|
const propTypes = {
|
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
repoID: PropTypes.string.isRequired,
|
|
|
|
isFileLoading: PropTypes.bool.isRequired,
|
|
|
|
content: PropTypes.string,
|
|
|
|
lastModified: PropTypes.string,
|
|
|
|
latestContributor: PropTypes.string,
|
|
|
|
onLinkClick: PropTypes.func.isRequired,
|
2024-09-07 08:29:45 +00:00
|
|
|
currentDirent: PropTypes.object,
|
|
|
|
onCloseMarkdownViewDialog: PropTypes.func
|
2019-02-21 09:37:04 +00:00
|
|
|
};
|
|
|
|
|
2024-09-10 03:46:50 +00:00
|
|
|
class MarkdownViewerDialog extends React.Component {
|
2019-02-21 09:37:04 +00:00
|
|
|
|
2019-02-27 09:34:39 +00:00
|
|
|
onOpenFile = (e) => {
|
|
|
|
e.preventDefault();
|
2024-09-09 08:47:55 +00:00
|
|
|
let { path, repoID, currentDirent } = this.props;
|
|
|
|
let { name } = currentDirent || {};
|
2024-09-10 03:46:50 +00:00
|
|
|
let newUrl = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path) + (path.endsWith('/') ? '' : '/') + name;
|
2019-02-27 09:34:39 +00:00
|
|
|
window.open(newUrl, '_blank');
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-02-27 09:34:39 +00:00
|
|
|
|
2019-02-21 09:37:04 +00:00
|
|
|
render() {
|
2024-09-07 08:29:45 +00:00
|
|
|
const { currentDirent } = this.props;
|
2024-09-08 00:17:47 +00:00
|
|
|
const { name } = currentDirent || {};
|
2019-02-21 09:37:04 +00:00
|
|
|
return (
|
2024-09-07 08:29:45 +00:00
|
|
|
<Modal
|
|
|
|
isOpen={true}
|
|
|
|
className='seafile-markdown-viewer-modal'
|
|
|
|
toggle={this.props.onCloseMarkdownViewDialog}
|
|
|
|
contentClassName='seafile-markdown-viewer-modal-content'
|
|
|
|
zIndex={1046}
|
2019-02-22 07:35:31 +00:00
|
|
|
>
|
2024-09-07 08:29:45 +00:00
|
|
|
<div className='seafile-markdown-viewer-modal-header'>
|
|
|
|
<div className='seafile-markdown-viewer-modal-header-left-name'>
|
2024-09-10 03:46:50 +00:00
|
|
|
<span><img src={`${mediaUrl}img/file/256/md.png`} width='24' alt='' /></span>
|
2024-09-07 08:29:45 +00:00
|
|
|
<span>{name}</span>
|
|
|
|
</div>
|
|
|
|
<div className='seafile-markdown-viewer-modal-header-right-tool'>
|
|
|
|
<span className='sf3-font sf3-font-open' onClick={this.onOpenFile}></span>
|
|
|
|
<span className='sf3-font sf3-font-x-01' onClick={this.props.onCloseMarkdownViewDialog}></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ModalBody className='seafile-markdown-viewer-modal-body'>
|
|
|
|
<SeafileMarkdownViewer
|
|
|
|
isTOCShow={false}
|
|
|
|
isFileLoading={this.props.isFileLoading}
|
|
|
|
markdownContent={this.props.content}
|
|
|
|
lastModified = {this.props.lastModified}
|
|
|
|
latestContributor={this.props.latestContributor}
|
|
|
|
onLinkClick={this.props.onLinkClick}
|
|
|
|
repoID={this.props.repoID}
|
|
|
|
path={this.props.path}
|
|
|
|
>
|
|
|
|
</SeafileMarkdownViewer>
|
|
|
|
</ModalBody>
|
|
|
|
</Modal>
|
2019-02-21 09:37:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-10 03:46:50 +00:00
|
|
|
MarkdownViewerDialog.propTypes = propTypes;
|
2019-02-21 09:37:04 +00:00
|
|
|
|
2024-09-10 03:46:50 +00:00
|
|
|
export default MarkdownViewerDialog;
|