import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { Utils } from '../utils/utils'; import { gettext, siteRoot } from '../utils/constants'; import { seafileAPI } from '../utils/seafile-api'; import CommonToolbar from './toolbar/common-toolbar'; import CurDirPath from './cur-dir-path'; import WikiMarkdownViewer from './wiki-markdown-viewer'; const propTypes = { pathPrefix: PropTypes.array.isRequired, currentMode: PropTypes.string.isRequired, path: PropTypes.string.isRequired, hash: PropTypes.string, onTabNavClick: PropTypes.func.isRequired, onSideNavMenuClick: PropTypes.func.isRequired, onSearchedClick: PropTypes.func.isRequired, onMainNavBarClick: PropTypes.func.isRequired, repoID: PropTypes.string.isRequired, currentRepoInfo: PropTypes.object, repoPermission: PropTypes.bool, isDraft: PropTypes.bool, hasDraft: PropTypes.bool, goDraftPage: PropTypes.func.isRequired, isFileLoading: PropTypes.bool.isRequired, filePermission: PropTypes.bool, content: PropTypes.string, lastModified: PropTypes.string, latestContributor: PropTypes.string, onLinkClick: PropTypes.func.isRequired, }; class FileContentView extends React.Component { componentDidMount() { if (this.props.hash) { let hash = this.props.hash; setTimeout(function() { window.location.hash = hash; }, 500); } } onEditClick = (e) => { e.preventDefault(); let { path, repoID } = this.props; let url = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path) + '?mode=edit'; window.open(url); } onNewDraft = (e) => { e.preventDefault(); let { path, repoID } = this.props; seafileAPI.createDraft(repoID, path).then(res => { window.location.href = siteRoot + 'lib/' + res.data.origin_repo_id + '/file' + res.data.draft_file_path + '?mode=edit'; }); } goDraftPage = (e) => { e.preventDefault(); this.props.goDraftPage(); } render() { let repoID = this.props.repoID; return (
{(this.props.filePermission && !this.props.hasDraft ) && ( )} {/* default have read priv */} {(!this.props.isDraft && !this.props.hasDraft) && ( )}
{this.props.currentRepoInfo && ( )}
{(!this.props.isDraft && this.props.hasDraft) &&
{gettext('This file is in draft stage.')} {gettext('Edit Draft')}
}
) } } FileContentView.propTypes = propTypes; export default FileContentView;