import React from 'react'; import PropTypes from 'prop-types'; import { Link } from '@gatsbyjs/reach-router'; import { gettext, siteRoot, canInvitePeople, enableTC, sideNavFooterCustomHtml, additionalAppBottomLinks, isDocs, isPro, isDBSqlite3, customNavItems, mediaUrl } from '../utils/constants'; import { SIDE_PANEL_FOLDED_WIDTH, SUB_NAV_ITEM_HEIGHT } from '../constants'; import Tip from './side-nav-icon-tip'; import FilesSubNav from '../components/files-sub-nav'; import { seafileAPI } from '../utils/seafile-api'; import { Utils } from '../utils/utils'; import Group from '../models/group'; import toaster from './toast'; import { FOLDED_SIDE_NAV_FILES, FOLDED_SIDE_NAV } from '../constants/zIndexes'; import '../css/main-side-nav-folded.css'; const propTypes = { currentTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, tabItemClick: PropTypes.func.isRequired, toggleFoldSideNav: PropTypes.func }; class MainSideNavFolded extends React.Component { constructor(props) { super(props); this.state = { groupItems: [], isFilesSubNavShown: false }; } componentDidMount() { document.addEventListener('click', this.handleOutsideClick); } componentWillUnmount() { document.removeEventListener('click', this.handleOutsideClick); } handleOutsideClick = (e) => { const { isFilesSubNavShown } = this.state; if (isFilesSubNavShown && !this.filesSubNav.contains(e.target)) { this.closeSubNav(); } }; openSubNav = () => { if (this.state.isFilesSubNavShown) return; seafileAPI.listGroups().then(res => { this.canCloseNav = false; this.setState({ groupItems: res.data.map(item => new Group(item)).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1), isFilesSubNavShown: true }, () => { setTimeout(() => { this.canCloseNav = true; }, 500); }); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); }; closeSubNav = () => { if (!this.state.isFilesSubNavShown || !this.canCloseNav) return; this.setState({ isFilesSubNavShown: false }); }; tabItemClick = (e, param, id) => { if (window.uploader && window.uploader.isUploadProgressDialogShow && window.uploader.totalProgress !== 100) { if (!window.confirm(gettext('A file is being uploaded. Are you sure you want to leave this page?'))) { e.preventDefault(); return false; } window.uploader.isUploadProgressDialogShow = false; } this.props.tabItemClick(param, id); this.setState({ isFilesSubNavShown: false }); }; getActiveClass = (tab) => { return this.props.currentTab === tab ? 'active' : ''; }; render() { let showActivity = isDocs || isPro || !isDBSqlite3; const { groupItems, isFilesSubNavShown } = this.state; return (