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 '../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.toggleSubNav(); } }; toggleSubNav = () => { this.setState({ isFilesSubNavShown: !this.state.isFilesSubNavShown }, () => { if (this.state.isFilesSubNavShown) { this.loadGroups(); } }); }; 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); if (this.props.currentTab == 'libraries' && param == 'libraries') { e.stopPropagation(); this.toggleSubNav(); } else { this.setState({ isFilesSubNavShown: false }); } }; getActiveClass = (tab) => { return this.props.currentTab === tab ? 'active' : ''; }; loadGroups = () => { seafileAPI.listGroups().then(res => { let groupList = res.data.map(item => { let group = new Group(item); return group; }); this.setState({ groupItems: groupList.sort((a, b) => { return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; }) }); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); }; render() { let showActivity = isDocs || isPro || !isDBSqlite3; const { groupItems, isFilesSubNavShown } = this.state; return (