import React from 'react'; import PropTypes from 'prop-types'; import { Link } from '@gatsbyjs/reach-router'; import { gettext, siteRoot, canAddRepo, canShareRepo, canGenerateShareLink, canGenerateUploadLink, canInvitePeople, enableOCM, enableOCMViaWebdav } from '../utils/constants'; import { seafileAPI } from '../utils/seafile-api'; import { Utils } from '../utils/utils'; import toaster from './toast'; import Group from '../models/group'; import { canViewOrg, isDocs, isPro, isDBSqlite3, customNavItems } from '../utils/constants'; const propTypes = { currentTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, tabItemClick: PropTypes.func.isRequired, }; class MainSideNav extends React.Component { constructor(props) { super(props); this.state = { groupsExtended: false, sharedExtended: false, closeSideBar:false, groupItems: [], }; this.listHeight = 24; //for caculate tabheight this.groupsHeight = 0; this.adminHeight = 0; } grpsExtend = () => { this.setState({ groupsExtended: !this.state.groupsExtended, }); this.loadGroups(); }; shExtend = () => { this.setState({ sharedExtended: !this.state.sharedExtended, }); }; loadGroups = () => { let _this = this; seafileAPI.listGroups().then(res =>{ let groupList = res.data.map(item => { let group = new Group(item); return group; }); this.groupsHeight = (groupList.length + 1) * _this.listHeight; _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); }); }; 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); }; getActiveClass = (tab) => { return this.props.currentTab === tab ? 'active' : ''; }; renderSharedGroups() { let style = {height: 0}; if (this.state.groupsExtended) { style = {height: this.groupsHeight}; } return ( ); } renderSharedAdmin() { let height = 0; if (this.state.sharedExtended) { if (!this.adminHeight) { this.adminHeight = 3 * this.listHeight; } height = this.adminHeight; } let style = {height: height}; let linksNavItem = null; if (canGenerateShareLink) { linksNavItem = (
  • this.tabItemClick(e, 'share-admin-share-links')}> {gettext('Links')}
  • ); } else if (canGenerateUploadLink) { linksNavItem = (
  • this.tabItemClick(e, 'share-admin-upload-links')}> {gettext('Links')}
  • ); } return ( ); } renderCustomNavItems() { return ( customNavItems.map((item, idx) => { return (
  • {item.desc}
  • ); }) ); } render() { let showActivity = isDocs || isPro || !isDBSqlite3; return (

    {gettext('Files')}

    {gettext('Tools')}

    ); } } MainSideNav.propTypes = propTypes; export default MainSideNav;