import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import cookie from 'react-cookies'; import { gettext, repoID, siteRoot, permission } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import { Utils } from '../../utils/utils'; import RepoInfo from '../../models/repo-info'; import CommonToolbar from '../../components/toolbar/common-toolbar'; import ViewModeToolbar from '../../components/toolbar/view-mode-toolbar'; import DirOperationToolBar from '../../components/toolbar/dir-operation-toolbar'; import MutipleDirOperationToolbar from '../../components/toolbar/mutilple-dir-operation-toolbar'; import CurDirPath from '../../components/cur-dir-path'; import WikiMarkdownViewer from '../../components/wiki-markdown-viewer'; import DirentListView from '../../components/dirent-list-view/dirent-list-view'; import DirentDetail from '../../components/dirent-detail/dirent-details'; import FileUploader from '../../components/file-uploader/file-uploader'; import RepoInfoBar from '../../components/repo-info-bar'; const propTypes = { content: PropTypes.string, lastModified: PropTypes.string, latestContributor: PropTypes.string, permission: PropTypes.string, hash: PropTypes.string, path: PropTypes.string.isRequired, repoName: PropTypes.string.isRequired, repoEncrypted: PropTypes.bool.isRequired, showShareBtn: PropTypes.bool.isRequired, enableDirPrivateShare: PropTypes.bool.isRequired, userPerm: PropTypes.string.isRequired, isAdmin: PropTypes.bool.isRequired, isGroupOwnedRepo: PropTypes.bool.isRequired, // whether the file or dir corresponding to the path exist pathExist: PropTypes.bool.isRequired, isFileLoading: PropTypes.bool.isRequired, isViewFile: PropTypes.bool.isRequired, isDirentListLoading: PropTypes.bool.isRequired, isDirentSelected: PropTypes.bool.isRequired, isAllDirentSelected: PropTypes.bool.isRequired, direntList: PropTypes.array.isRequired, sortBy: PropTypes.string.isRequired, sortOrder: PropTypes.string.isRequired, sortItems: PropTypes.func.isRequired, selectedDirentList: PropTypes.array.isRequired, updateDirent: PropTypes.func.isRequired, onSideNavMenuClick: PropTypes.func.isRequired, onSearchedClick: PropTypes.func.isRequired, onMainNavBarClick: PropTypes.func.isRequired, onItemClick: PropTypes.func.isRequired, onAllDirentSelected: PropTypes.func.isRequired, onItemSelected: PropTypes.func.isRequired, onItemDelete: PropTypes.func.isRequired, onItemRename: PropTypes.func.isRequired, onItemMove: PropTypes.func.isRequired, onItemCopy: PropTypes.func.isRequired, onAddFile: PropTypes.func.isRequired, onAddFolder: PropTypes.func.isRequired, onFileTagChanged: PropTypes.func.isRequired, onItemsMove: PropTypes.func.isRequired, onItemsCopy: PropTypes.func.isRequired, onItemsDelete: PropTypes.func.isRequired, onLinkClick: PropTypes.func.isRequired, onFileUploadSuccess: PropTypes.func.isRequired, isDraft: PropTypes.bool, hasDraft: PropTypes.bool, goDraftPage: PropTypes.func, usedRepoTags: PropTypes.array.isRequired, readmeMarkdown: PropTypes.object, draftCounts: PropTypes.number, updateUsedRepoTags: PropTypes.func.isRequired, }; class MainPanel extends Component { constructor(props) { super(props); this.state = { currentMode: 'wiki', isDirentDetailShow: false, currentDirent: null, direntPath: '', currentRepoInfo: null, }; } componentDidMount() { seafileAPI.getRepoInfo(repoID).then(res => { let repoInfo = new RepoInfo(res.data); this.setState({ currentRepoInfo: repoInfo, }); }); if (this.props.hash) { let hash = this.props.hash; setTimeout(function() { window.location.hash = hash; }, 500); } } switchViewMode = (mode) => { cookie.save('view_mode', mode, { path: '/' }); let repoName = this.state.currentRepoInfo.repo_name; let dirPath = this.props.isViewFile ? Utils.getDirName(this.props.path) : this.props.path; window.location.href = siteRoot + 'library/' + repoID + '/' + repoName + dirPath; } onSideNavMenuClick = () => { this.props.onSideNavMenuClick(); } onItemClick = (dirent) => { this.setState({isDirentDetailShow: false}); this.props.onItemClick(dirent); } onMainNavBarClick = (path) => { this.setState({isDirentDetailShow: false}); this.props.onMainNavBarClick(path); } // on '' onDirentClick = (dirent) => { if (this.state.isDirentDetailShow) { this.onItemDetails(dirent); } } onItemDetails = (dirent) => { this.setState({ currentDirent: dirent, isDirentDetailShow: true, }); } onItemDetailsClose = () => { this.setState({isDirentDetailShow: false}); } onFileTagChanged = (dirent, direntPath) => { this.props.onFileTagChanged(dirent, direntPath); } onUploadFile = (e) => { e.nativeEvent.stopImmediatePropagation(); this.uploader.onFileUpload(); } onUploadFolder = (e) => { e.nativeEvent.stopImmediatePropagation(); this.uploader.onFolderUpload(); } onFileUploadSuccess = (direntObject) => { this.props.onFileUploadSuccess(direntObject); } render() { const ErrMessage = (
{gettext('Folder does not exist.')}
); const showRepoInfoBar = this.props.path === '/' && ( this.props.usedRepoTags.length != 0 || this.props.readmeMarkdown != null || this.props.draftCounts != 0); return (
{this.props.isDirentSelected ? : }
{this.state.currentRepoInfo && ( )}
{!this.props.pathExist && ErrMessage } {(this.props.pathExist && this.props.isViewFile) && ( {(!this.props.isDraft && this.props.hasDraft) &&
{gettext('This file is in draft stage.')} {gettext('View Draft')}
}
)} {(this.props.pathExist && !this.props.isViewFile) && ( {showRepoInfoBar && ( )} this.uploader = uploader} dragAndDrop={true} path={this.props.path} repoID={repoID} direntList={this.props.direntList} onFileUploadSuccess={this.onFileUploadSuccess} /> )}
{this.state.isDirentDetailShow && (
)}
); } } MainPanel.propTypes = propTypes; export default MainPanel;