diff --git a/frontend/src/components/main-side-nav-folded.js b/frontend/src/components/main-side-nav-folded.js index a6892a4a16..908983ae30 100644 --- a/frontend/src/components/main-side-nav-folded.js +++ b/frontend/src/components/main-side-nav-folded.js @@ -41,24 +41,33 @@ class MainSideNavFolded extends React.Component { handleOutsideClick = (e) => { const { isFilesSubNavShown } = this.state; if (isFilesSubNavShown && !this.filesSubNav.contains(e.target)) { - this.toggleSubNav(); + this.closeSubNav(); } }; - toggleSubNav = () => { - this.setState({ - isFilesSubNavShown: !this.state.isFilesSubNavShown - }, () => { - if (this.state.isFilesSubNavShown) { - this.loadGroups(); - } + 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); }); }; - filesOnMouseOver = () => { - if (!this.state.isFilesSubNavShown) { - this.toggleSubNav(); - } + closeSubNav = () => { + if (!this.state.isFilesSubNavShown || !this.canCloseNav) return; + this.setState({ + isFilesSubNavShown: false + }); }; tabItemClick = (e, param, id) => { @@ -72,17 +81,6 @@ class MainSideNavFolded extends React.Component { 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 - }); - } - */ this.setState({ isFilesSubNavShown: false }); @@ -92,24 +90,6 @@ class MainSideNavFolded extends React.Component { 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; @@ -123,20 +103,20 @@ class MainSideNavFolded extends React.Component { to={ siteRoot + 'libraries/' } className={`nav-link ellipsis ${this.getActiveClass('libraries')}`} onClick={(e) => this.tabItemClick(e, 'libraries')} - onMouseOver={this.filesOnMouseOver} + onMouseOver={this.openSubNav} > - - + - {isFilesSubNavShown && - } -
  • +
  • this.tabItemClick(e, 'starred')}> @@ -156,7 +135,7 @@ class MainSideNavFolded extends React.Component { {showActivity && <> -
  • +
  • this.tabItemClick(e, 'dashboard')}> @@ -165,7 +144,7 @@ class MainSideNavFolded extends React.Component { } -
  • +
  • this.tabItemClick(e, 'published')}> @@ -173,7 +152,7 @@ class MainSideNavFolded extends React.Component {
  • {canInvitePeople && -
  • +
  • this.tabItemClick(e, 'invitations')}> diff --git a/frontend/src/css/main-side-nav-folded.css b/frontend/src/css/main-side-nav-folded.css index a67d5214c4..17c2898ca2 100644 --- a/frontend/src/css/main-side-nav-folded.css +++ b/frontend/src/css/main-side-nav-folded.css @@ -18,4 +18,5 @@ width: 240px; background: #fff; z-index: 2; + transition: all 250ms cubic-bezier(0.25, 0.1, 0.25, 0.1); }