import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import ModalPortal from './modal-portal'; import { Link } from '@gatsbyjs/reach-router'; import { gettext, siteRoot, canAddGroup, canAddRepo, canShareRepo, canGenerateShareLink, canGenerateUploadLink, canInvitePeople, enableTC, sideNavFooterCustomHtml, enableShowAbout, showWechatSupportGroup, canViewOrg, isDocs, isPro, isDBSqlite3, customNavItems, mediaUrl } 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'; import AboutDialog from './dialog/about-dialog'; import FilesSubNav from '../components/files-sub-nav'; import { SUB_NAV_ITEM_HEIGHT } from '../constants'; import { isWorkWeixin } from './wechat/weixin-utils'; import WechatDialog from './wechat/wechat-dialog'; const propTypes = { currentTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, tabItemClick: PropTypes.func.isRequired, toggleFoldSideNav: PropTypes.func }; class MainSideNav extends React.Component { constructor(props) { super(props); this.state = { filesNavUnfolded: false, isAboutDialogShow: false, sharedExtended: false, groupItems: [], isCreateGroupDialogOpen: false, isShowWechatDialog: false, }; this.adminHeight = 0; this.filesNavHeight = 0; this.isWorkWeixin = isWorkWeixin(window.navigator.userAgent.toLowerCase()); } toggleWechatDialog = () => { this.setState({ isShowWechatDialog: !this.state.isShowWechatDialog }); }; shExtend = () => { this.setState({ sharedExtended: !this.state.sharedExtended, }); }; loadGroups = () => { 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 }); }; renderAddGroup() { return ( <> {canAddGroup && ( <>
  • {gettext('New Group')}
  • {this.state.isCreateGroupDialogOpen && } )} ); } renderSharedAdmin() { let height = 0; if (this.state.sharedExtended) { if (!this.adminHeight) { this.adminHeight = 3 * SUB_NAV_ITEM_HEIGHT; } height = this.adminHeight; } let style = { height, opacity: height === 0 ? 0 : 1 }; 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}
  • ); }) ); } toggleFilesNav = (e) => { e.preventDefault(); e.stopPropagation(); this.setState({ filesNavUnfolded: !this.state.filesNavUnfolded }, () => { if (this.state.filesNavUnfolded) { this.loadGroups(); } }); }; toggleAboutDialog = (e) => { e.preventDefault(); this.setState({ isAboutDialogShow: !this.state.isAboutDialogShow }); }; render() { let showActivity = isDocs || isPro || !isDBSqlite3; const { filesNavUnfolded, groupItems } = this.state; return (

    {gettext('Workspace')}

    • this.tabItemClick(e, 'libraries')}> {gettext('Files')}
        {this.renderAddGroup()}
    • this.tabItemClick(e, 'starred')}> {gettext('Favorites')}
    • {showActivity &&
    • this.tabItemClick(e, 'dashboard')}> {gettext('Activities')}
    • }
    • this.tabItemClick(e, 'published')}> {gettext('Wikis')}
    • {canInvitePeople &&
    • this.tabItemClick(e, 'invitations')}> {gettext('Invite Guest')}
    • }
    • {gettext('Share Admin')} {this.renderSharedAdmin()}
    • {customNavItems && this.renderCustomNavItems()}

    {gettext('Help and resources')}

    {sideNavFooterCustomHtml ? (
    ) : ( ) }
    {gettext('Fold the sidebar')}
    {this.state.isAboutDialogShow && ( )} {this.state.isShowWechatDialog && }
    ); } } MainSideNav.propTypes = propTypes; export default MainSideNav;