mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-13 05:39:59 +00:00
[add] preview-readme.md (#2857)
This commit is contained in:
59
frontend/src/components/dialog/readme-dialog.js
Normal file
59
frontend/src/components/dialog/readme-dialog.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||||
|
import MarkdownViewer from '@seafile/seafile-editor/dist/viewer/markdown-viewer';
|
||||||
|
import Loading from '../../components/loading';
|
||||||
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
|
import { gettext } from '../../utils/constants';
|
||||||
|
|
||||||
|
const propTypes = {
|
||||||
|
repoID: PropTypes.string.isRequired,
|
||||||
|
filePath: PropTypes.string.isRequired,
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Modal isOpen={true} className="readme-dialog" size="lg">
|
||||||
|
<ModalHeader>{gettext('Readme.md')}
|
||||||
|
<a className="readme-dialog-edit" href={this.props.href} target='_blank'><i className="fa fa-pencil"></i></a>
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
{this.state.isLoading ?
|
||||||
|
<Loading />:
|
||||||
|
<MarkdownViewer markdownContent={this.state.readmeContent} showTOC={false}/>
|
||||||
|
}
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button color="secondary" onClick={this.props.toggleCancel}>{gettext('Close')}</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReadmeDialog.propTypes = propTypes;
|
||||||
|
|
||||||
|
export default ReadmeDialog;
|
@@ -1,10 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import ModalPortal from './modal-portal';
|
import ModalPortal from './modal-portal';
|
||||||
import { Modal } from 'reactstrap';
|
|
||||||
import ListTaggedFilesDialog from './dialog/list-taggedfiles-dialog';
|
import ListTaggedFilesDialog from './dialog/list-taggedfiles-dialog';
|
||||||
import ListRepoDraftsDialog from './dialog/list-repo-drafts-dialog';
|
import ListRepoDraftsDialog from './dialog/list-repo-drafts-dialog';
|
||||||
import ListRepoReviewsDialog from './dialog/list-repo-reviews-dialog';
|
import ListRepoReviewsDialog from './dialog/list-repo-reviews-dialog';
|
||||||
|
import ReadmeDialog from './dialog/readme-dialog';
|
||||||
import { siteRoot, gettext } from '../utils/constants';
|
import { siteRoot, gettext } from '../utils/constants';
|
||||||
import { Utils } from '../utils/utils';
|
import { Utils } from '../utils/utils';
|
||||||
|
|
||||||
@@ -28,6 +28,7 @@ class RepoInfoBar extends React.Component {
|
|||||||
isListTaggedFileShow: false,
|
isListTaggedFileShow: false,
|
||||||
showRepoDrafts: false,
|
showRepoDrafts: false,
|
||||||
showRepoReviews: false,
|
showRepoReviews: false,
|
||||||
|
showReadmeDialog: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,10 +57,16 @@ class RepoInfoBar extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleReadme = () => {
|
||||||
|
this.setState({
|
||||||
|
showReadmeDialog: !this.state.showReadmeDialog
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let {repoID, currentPath, usedRepoTags, readmeMarkdown} = this.props;
|
let {repoID, currentPath, usedRepoTags, readmeMarkdown} = this.props;
|
||||||
let href = readmeMarkdown !== null ? siteRoot + 'lib/' + repoID + '/file' + Utils.joinPath(currentPath, readmeMarkdown.name) : '';
|
let href = readmeMarkdown !== null ? siteRoot + 'lib/' + repoID + '/file' + Utils.joinPath(currentPath, readmeMarkdown.name) : '';
|
||||||
|
let filePath = currentPath + 'readme.md';
|
||||||
return (
|
return (
|
||||||
<div className="repo-info-bar">
|
<div className="repo-info-bar">
|
||||||
{usedRepoTags.length > 0 && (
|
{usedRepoTags.length > 0 && (
|
||||||
@@ -78,12 +85,18 @@ class RepoInfoBar extends React.Component {
|
|||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
<div className="readme-files">
|
<div className="readme-files">
|
||||||
{readmeMarkdown !== null && (
|
{(readmeMarkdown !== null && readmeMarkdown.size > 1) &&
|
||||||
|
<span className="readme-file" onClick={this.toggleReadme}>
|
||||||
|
<i className="readme-flag fa fa-flag"></i>
|
||||||
|
<span className="readme-name">{readmeMarkdown.name}</span>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
{(readmeMarkdown !== null && readmeMarkdown.size < 2) &&
|
||||||
<span className="readme-file">
|
<span className="readme-file">
|
||||||
<i className="readme-flag fa fa-flag"></i>
|
<i className="readme-flag fa fa-flag"></i>
|
||||||
<a className="readme-name" href={href} target='_blank'>{readmeMarkdown.name}</a>
|
<a className="readme-name" href={href} target='_blank'>{readmeMarkdown.name}</a>
|
||||||
</span>
|
</span>
|
||||||
)}
|
}
|
||||||
{this.props.draftCounts > 0 &&
|
{this.props.draftCounts > 0 &&
|
||||||
<span className="readme-file">
|
<span className="readme-file">
|
||||||
<i className="readme-flag fa fa-pen"></i>
|
<i className="readme-flag fa fa-pen"></i>
|
||||||
@@ -132,6 +145,16 @@ class RepoInfoBar extends React.Component {
|
|||||||
</ModalPortal>
|
</ModalPortal>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{this.state.showReadmeDialog && (
|
||||||
|
<ModalPortal>
|
||||||
|
<ReadmeDialog
|
||||||
|
toggleCancel={this.toggleReadme}
|
||||||
|
repoID={repoID}
|
||||||
|
filePath={filePath}
|
||||||
|
href={href}
|
||||||
|
/>
|
||||||
|
</ModalPortal>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
width: 12px;
|
width: 12px;
|
||||||
height: 12px;
|
height: 12px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.used-tag-name {
|
.used-tag-name {
|
||||||
@@ -42,6 +43,7 @@
|
|||||||
.readme-file {
|
.readme-file {
|
||||||
margin: 0 15px;
|
margin: 0 15px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.readme-file a {
|
.readme-file a {
|
||||||
@@ -57,3 +59,8 @@
|
|||||||
margin: 0 0.25rem;
|
margin: 0 0.25rem;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.readme-dialog-edit {
|
||||||
|
position: absolute;
|
||||||
|
right: 16px;
|
||||||
|
}
|
Reference in New Issue
Block a user