1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-08 10:27:33 +00:00
seahub/frontend/src/components/dir-view-mode/markdown-viewer-dialog.js

74 lines
2.6 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalBody } from 'reactstrap';
import { Utils } from '../../utils/utils';
2024-09-10 03:46:50 +00:00
import { siteRoot, mediaUrl } from '../../utils/constants';
import SeafileMarkdownViewer from '../seafile-markdown-viewer';
2024-09-10 03:46:50 +00:00
import './markdown-viewer-dialog.css';
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,
currentDirent: PropTypes.object,
onCloseMarkdownViewDialog: PropTypes.func
};
2024-09-10 03:46:50 +00:00
class MarkdownViewerDialog extends React.Component {
2019-02-27 09:34:39 +00:00
onOpenFile = (e) => {
e.preventDefault();
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');
};
2019-02-27 09:34:39 +00:00
render() {
const { currentDirent } = this.props;
const { name } = currentDirent || {};
return (
<Modal
isOpen={true}
className='seafile-markdown-viewer-modal'
toggle={this.props.onCloseMarkdownViewDialog}
contentClassName='seafile-markdown-viewer-modal-content'
zIndex={1046}
>
<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>
<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>
);
}
}
2024-09-10 03:46:50 +00:00
MarkdownViewerDialog.propTypes = propTypes;
2024-09-10 03:46:50 +00:00
export default MarkdownViewerDialog;