import React from 'react'; import PropTypes from 'prop-types'; import { Link } from '@gatsbyjs/reach-router'; import { gettext, siteRoot, canAddGroup, canAddRepo, canShareRepo, canGenerateShareLink, canGenerateUploadLink, canInvitePeople, enableTC, sideNavFooterCustomHtml, additionalAppBottomLinks, canViewOrg, isDocs, isPro, isDBSqlite3, customNavItems } from '../utils/constants'; import { seafileAPI } from '../utils/seafile-api'; import { Utils } from '../utils/utils'; import Group from '../models/group'; import toaster from './toast'; import CreateGroupDialog from '../components/dialog/create-group-dialog'; const propTypes = { currentTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, tabItemClick: PropTypes.func.isRequired, }; const SUB_NAV_ITEM_HEIGHT = 28; class MainSideNav extends React.Component { constructor(props) { super(props); this.state = { filesNavUnfolded: false, sharedExtended: false, closeSideBar:false, groupItems: [], isCreateGroupDialogOpen: false }; this.adminHeight = 0; this.filesNavHeight = 0; } 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.filesNavHeight = (groupList.length + (canAddGroup ? 1 : 0) + (canAddRepo ? 1 : 0) + (canViewOrg ? 1 : 0) + 1) * SUB_NAV_ITEM_HEIGHT; _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' : ''; }; onCreateGroup = (groupData) => { const newGroup = new Group(groupData); const { groupItems: newList } = this.state; newList.push(newGroup); this.filesNavHeight += SUB_NAV_ITEM_HEIGHT; this.setState({ groupItems: newList }); }; toggleCreateGroupDialog = () => { this.setState({ isCreateGroupDialogOpen: !this.state.isCreateGroupDialogOpen }); }; renderSharedGroups() { return ( <> {this.state.groupItems.map(item => { return (