import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { gettext, repoID, serviceUrl, slug, siteRoot } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import { Utils } from '../../utils/utils'; import Repo from '../../models/repo'; import CommonToolbar from '../../components/toolbar/common-toolbar'; import PathToolbar from '../../components/toolbar/path-toolbar'; import MarkdownViewer from '../../components/markdown-viewer'; import DirentListView from '../../components/dirent-list-view/dirent-list-view'; import DirentDetail from '../../components/dirent-detail/dirent-details'; import CreateFolder from '../../components/dialog/create-folder-dialog'; import CreateFile from '../../components/dialog/create-file-dialog'; import FileUploader from '../../components/file-uploader/file-uploader'; const propTypes = { content: PropTypes.string, lastModified: PropTypes.string, latestContributor: PropTypes.string, permission: PropTypes.string, path: PropTypes.string.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, direntList: PropTypes.array.isRequired, updateDirent: PropTypes.func.isRequired, onSideNavMenuClick: PropTypes.func.isRequired, onSearchedClick: PropTypes.func.isRequired, onMainNavBarClick: PropTypes.func.isRequired, onLinkClick: PropTypes.func.isRequired, onItemClick: 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, switchViewMode: PropTypes.func.isRequired, onFileTagChanged: PropTypes.func.isRequired, }; class MainPanel extends Component { constructor(props) { super(props); this.state = { isWikiMode: true, newMenuShow: false, uploadMenuShow: false, showFileDialog: false, showFolderDialog: false, createFileType: '', isDirentDetailShow: false, currentDirent: null, currentFilePath: '', currentRepo: null, isRepoOwner: false, }; } componentDidMount() { seafileAPI.getRepoInfo(repoID).then(res => { let repo = new Repo(res.data); seafileAPI.getAccountInfo().then(res => { let user_email = res.data.email; let isRepoOwner = repo.owner_email === user_email; this.setState({ currentRepo: repo, isRepoOwner: isRepoOwner, }); }); }); document.addEventListener('click', this.hideOperationMenu); } componentWillReceiveProps(nextProps) { // if (nextProps.path !== this.props.path) { // this.setState({isDirentDetailShow: false}); // } } componentWillUnmount() { document.removeEventListener('click', this.hideOperationMenu); } switchViewMode = (e) => { e.preventDefault(); if (e.target.id === 'wiki') { return; } this.setState({isWikiMode: false}); this.props.switchViewMode(e.target.id); } onSideNavMenuClick = () => { this.props.onSideNavMenuClick(); } onMainNavBarClick = (e) => { this.props.onMainNavBarClick(e.target.dataset.path); } onEditClick = (e) => { e.preventDefault(); window.location.href= serviceUrl + '/lib/' + repoID + '/file' + this.props.path + '?mode=edit'; } onUploadClick = (e) => { this.toggleOperationMenu(e); this.setState({ newMenuShow: false, uploadMenuShow: !this.state.uploadMenuShow, }); } onNewClick = (e) => { this.toggleOperationMenu(e); this.setState({ newMenuShow: !this.state.newMenuShow, uploadMenuShow: false, }); } onShareClick = () => { alert('share btn clicked'); } toggleOperationMenu = (e) => { e.nativeEvent.stopImmediatePropagation(); let targetRect = e.target.getClientRects()[0]; let left = targetRect.x; let top = targetRect.y + targetRect.height; let style = {position: 'fixed', display: 'block', left: left, top: top}; this.setState({operationMenuStyle: style}); } hideOperationMenu = () => { this.setState({ uploadMenuShow: false, newMenuShow: false, }); } addFolder = () => { this.setState({showFolderDialog: !this.showFolderDialog}); } addFile = () => { this.setState({ showFileDialog: !this.showFileDialog, createFileType: '', }); } addMarkdownFile = () => { this.setState({ showFileDialog: !this.showFileDialog, createFileType: '.md', }); } addFolderCancel = () => { this.setState({showFolderDialog: !this.state.showFolderDialog}); } addFileCancel = () => { this.setState({showFileDialog: !this.state.showFileDialog}); } onAddFile = (filePath, isDraft) => { this.setState({showFileDialog: !this.state.showFileDialog}); this.props.onAddFile(filePath, isDraft); } onAddFolder = (dirPath) => { this.setState({showFolderDialog: !this.state.showFolderDialog}); this.props.onAddFolder(dirPath); } onItemDetails = (dirent, direntPath) => { this.setState({ currentDirent: dirent, currentFilePath: direntPath, isDirentDetailShow: true, }); } onItemDetailsClose = () => { this.setState({isDirentDetailShow: false}); } onFileTagChanged = (dirent, direntPath) => { //todos; this.props.onFileTagChanged(dirent, direntPath); } uploadFile = (e) => { e.nativeEvent.stopImmediatePropagation(); this.uploader.onFileUpload(); } uploadFolder = (e) => { e.nativeEvent.stopImmediatePropagation(); this.uploader.onFolderUpload(); } onFileSuccess = (file) => { } render() { let path = this.props.path; path = path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path; let pathList = path.split('/'); let nodePath = ''; let pathElem = pathList.map((item, index) => { if (item === '') { return; } if (index === (pathList.length - 1)) { return ( /{item} ); } else { nodePath += '/' + item; return ( / {item} ); } }); return (