From db5a7481de741069fac60e5b4a564fd63180215e Mon Sep 17 00:00:00 2001
From: Michael An <37589122+Michael18811380328@users.noreply.github.com>
Date: Sat, 19 Jan 2019 16:20:40 +0800
Subject: [PATCH] [add] preview-readme.md (#2857)
---
.../src/components/dialog/readme-dialog.js | 59 +++++++++++++++++++
frontend/src/components/repo-info-bar.js | 31 ++++++++--
frontend/src/css/repo-info-bar.css | 7 +++
3 files changed, 93 insertions(+), 4 deletions(-)
create mode 100644 frontend/src/components/dialog/readme-dialog.js
diff --git a/frontend/src/components/dialog/readme-dialog.js b/frontend/src/components/dialog/readme-dialog.js
new file mode 100644
index 0000000000..9a274530e7
--- /dev/null
+++ b/frontend/src/components/dialog/readme-dialog.js
@@ -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 (
+
+ {gettext('Readme.md')}
+
+
+
+ {this.state.isLoading ?
+ :
+
+ }
+
+
+
+
+
+ );
+ }
+}
+
+ReadmeDialog.propTypes = propTypes;
+
+export default ReadmeDialog;
diff --git a/frontend/src/components/repo-info-bar.js b/frontend/src/components/repo-info-bar.js
index 0d37771945..6770ecad71 100644
--- a/frontend/src/components/repo-info-bar.js
+++ b/frontend/src/components/repo-info-bar.js
@@ -1,10 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import ModalPortal from './modal-portal';
-import { Modal } from 'reactstrap';
import ListTaggedFilesDialog from './dialog/list-taggedfiles-dialog';
import ListRepoDraftsDialog from './dialog/list-repo-drafts-dialog';
import ListRepoReviewsDialog from './dialog/list-repo-reviews-dialog';
+import ReadmeDialog from './dialog/readme-dialog';
import { siteRoot, gettext } from '../utils/constants';
import { Utils } from '../utils/utils';
@@ -28,6 +28,7 @@ class RepoInfoBar extends React.Component {
isListTaggedFileShow: false,
showRepoDrafts: false,
showRepoReviews: false,
+ showReadmeDialog: false,
};
}
@@ -56,10 +57,16 @@ class RepoInfoBar extends React.Component {
});
}
+ toggleReadme = () => {
+ this.setState({
+ showReadmeDialog: !this.state.showReadmeDialog
+ });
+ }
+
render() {
let {repoID, currentPath, usedRepoTags, readmeMarkdown} = this.props;
let href = readmeMarkdown !== null ? siteRoot + 'lib/' + repoID + '/file' + Utils.joinPath(currentPath, readmeMarkdown.name) : '';
-
+ let filePath = currentPath + 'readme.md';
return (
{usedRepoTags.length > 0 && (
@@ -78,12 +85,18 @@ class RepoInfoBar extends React.Component {
)}
- {readmeMarkdown !== null && (
+ {(readmeMarkdown !== null && readmeMarkdown.size > 1) &&
+
+
+ {readmeMarkdown.name}
+
+ }
+ {(readmeMarkdown !== null && readmeMarkdown.size < 2) &&
{readmeMarkdown.name}
- )}
+ }
{this.props.draftCounts > 0 &&
@@ -132,6 +145,16 @@ class RepoInfoBar extends React.Component {
)}
+ {this.state.showReadmeDialog && (
+
+
+
+ )}
);
}
diff --git a/frontend/src/css/repo-info-bar.css b/frontend/src/css/repo-info-bar.css
index 2f1945ad42..875aa2d809 100644
--- a/frontend/src/css/repo-info-bar.css
+++ b/frontend/src/css/repo-info-bar.css
@@ -19,6 +19,7 @@
width: 12px;
height: 12px;
border-radius: 50%;
+ cursor: pointer;
}
.used-tag-name {
@@ -42,6 +43,7 @@
.readme-file {
margin: 0 15px;
display: inline-block;
+ cursor: pointer;
}
.readme-file a {
@@ -57,3 +59,8 @@
margin: 0 0.25rem;
font-size: 14px;
}
+
+.readme-dialog-edit {
+ position: absolute;
+ right: 16px;
+}
\ No newline at end of file