import React from 'react'; import PropTypes from 'prop-types'; import DirColumnNav from './dir-column-nav'; import MarkdownViewerDialog from './markdown-viewer-dialog'; import DirListView from './dir-list-view'; import DirGridView from './dir-grid-view'; import { SIDE_PANEL_FOLDED_WIDTH } from '../../constants'; import ResizeBar from '../resize-bar'; import { DRAG_HANDLER_HEIGHT, MAX_SIDE_PANEL_RATE, MIN_SIDE_PANEL_RATE } from '../resize-bar/constants'; import { SeafileMetadata } from '../../metadata'; import { mediaUrl } from '../../utils/constants'; import { GRID_MODE, LIST_MODE, METADATA_MODE } from './constants'; const propTypes = { isSidePanelFolded: PropTypes.bool, isTreePanelShown: PropTypes.bool.isRequired, currentMode: PropTypes.string.isRequired, path: PropTypes.string.isRequired, repoID: PropTypes.string.isRequired, // repoinfo currentRepoInfo: PropTypes.object.isRequired, enableDirPrivateShare: PropTypes.bool.isRequired, userPerm: PropTypes.string, isGroupOwnedRepo: PropTypes.bool.isRequired, // tree isTreeDataLoading: PropTypes.bool.isRequired, treeData: PropTypes.object.isRequired, currentNode: PropTypes.object, onNodeClick: PropTypes.func.isRequired, onNodeCollapse: PropTypes.func.isRequired, onNodeExpanded: PropTypes.func.isRequired, onRenameNode: PropTypes.func.isRequired, onDeleteNode: PropTypes.func.isRequired, onAddFileNode: PropTypes.func.isRequired, onAddFolderNode: PropTypes.func.isRequired, // file isViewFile: PropTypes.bool.isRequired, isFileLoading: PropTypes.bool.isRequired, filePermission: PropTypes.string, content: PropTypes.string, viewId: PropTypes.string, lastModified: PropTypes.string, latestContributor: PropTypes.string, onLinkClick: PropTypes.func.isRequired, onCloseMarkdownViewDialog: PropTypes.func, // repo content isRepoInfoBarShow: PropTypes.bool.isRequired, usedRepoTags: PropTypes.array.isRequired, updateUsedRepoTags: PropTypes.func.isRequired, // list isDirentListLoading: PropTypes.bool.isRequired, direntList: PropTypes.array.isRequired, sortBy: PropTypes.string.isRequired, sortOrder: PropTypes.string.isRequired, sortItems: PropTypes.func.isRequired, onAddFolder: PropTypes.func.isRequired, onAddFile: PropTypes.func.isRequired, updateDirent: PropTypes.func.isRequired, onItemClick: PropTypes.func.isRequired, onItemSelected: PropTypes.func.isRequired, onItemDelete: PropTypes.func.isRequired, onItemRename: PropTypes.func.isRequired, deleteFilesCallback: PropTypes.func, renameFileCallback: PropTypes.func, onItemMove: PropTypes.func.isRequired, onItemCopy: PropTypes.func.isRequired, onItemConvert: PropTypes.func.isRequired, onDirentClick: PropTypes.func.isRequired, isAllItemSelected: PropTypes.bool.isRequired, onAllItemSelected: PropTypes.func.isRequired, selectedDirentList: PropTypes.array.isRequired, onSelectedDirentListUpdate: PropTypes.func.isRequired, onItemsMove: PropTypes.func.isRequired, onItemsCopy: PropTypes.func.isRequired, onItemsDelete: PropTypes.func.isRequired, repoTags: PropTypes.array.isRequired, onFileTagChanged: PropTypes.func, showDirentDetail: PropTypes.func.isRequired, fullDirentList: PropTypes.array, onItemsScroll: PropTypes.func.isRequired, eventBus: PropTypes.object, updateCurrentDirent: PropTypes.func.isRequired, closeDirentDetail: PropTypes.func.isRequired, }; class DirColumnView extends React.Component { constructor(props) { super(props); this.state = { inResizing: false, navRate: parseFloat(localStorage.getItem('sf_dir_content_nav_rate') || 0.25), }; this.containerWidth = null; this.resizeBarRef = React.createRef(); this.dragHandlerRef = React.createRef(); this.viewModeContainer = React.createRef(); this.dirContentMain = React.createRef(); } onResizeMouseUp = () => { if (this.state.inResizing) { this.setState({ inResizing: false }); } localStorage.setItem('sf_dir_content_nav_rate', this.state.navRate); }; onResizeMouseDown = () => { this.containerWidth = this.viewModeContainer.current.clientWidth; this.setState({ inResizing: true }); }; onResizeMouseMove = (e) => { const { isSidePanelFolded } = this.props; let sizeNavWidth = isSidePanelFolded ? SIDE_PANEL_FOLDED_WIDTH + 3 : window.innerWidth - this.containerWidth; let rate = (e.nativeEvent.clientX - sizeNavWidth) / this.containerWidth; this.setState({ navRate: Math.max(Math.min(rate, MAX_SIDE_PANEL_RATE), MIN_SIDE_PANEL_RATE), }); }; onResizeMouseOver = (event) => { if (!this.dragHandlerRef.current) return; const { top } = this.resizeBarRef.current.getBoundingClientRect(); const dragHandlerRefTop = event.pageY - top - DRAG_HANDLER_HEIGHT / 2; this.setDragHandlerTop(dragHandlerRefTop); }; setDragHandlerTop = (top) => { this.dragHandlerRef.current.style.top = top + 'px'; }; getMenuContainerSize = () => { const { innerWidth, innerHeight } = window; return { width: innerWidth, height: innerHeight }; }; render() { const { currentMode, isTreePanelShown } = this.props; const { navRate, inResizing } = this.state; const dirContentMainStyle = { userSelect: inResizing ? 'none' : '', flex: '1 0 ' + (1 - navRate) * 100 + '%', }; return (
{isTreePanelShown && ( <> )}
{} : this.props.onItemsScroll} ref={this.dirContentMain} > {currentMode === METADATA_MODE && ( )} {currentMode === LIST_MODE && } {currentMode === GRID_MODE && } {this.props.isViewFile && }
); } } DirColumnView.propTypes = propTypes; export default DirColumnView;