diff --git a/frontend/src/pages/libraries/index.js b/frontend/src/pages/libraries/index.js index 067bf06e16..0b3851694f 100644 --- a/frontend/src/pages/libraries/index.js +++ b/frontend/src/pages/libraries/index.js @@ -36,61 +36,41 @@ class Libraries extends Component { isSortOptionsDialogOpen: false, sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time' or 'size' sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc' - isGuideForNewDialogOpen: window.app.pageOptions.guideEnabled, - - // for 'groups' - isGroupsLoading: true, - groupsErrorMsg: '', groupList: [], - - // for 'shared' sharedRepoList:[], - isSharedLoading: true, - - // for 'public' publicRepoList: [], - isPublicLoading: true, }; } componentDidMount() { - this.listMyLibs(); - this.listGroups(); - } - - listMyLibs = () => { - seafileAPI.listRepos({'type':['mine', 'shared', 'public']}).then((res) => { - let allRepoList = res.data.repos.map((item) => { - return new Repo(item); - }); - let myRepoList = allRepoList.filter(item => { - return item.type === 'mine'; - }); - let sharedRepoList = allRepoList.filter(item => { - return item.type === 'shared'; - }); - let publicRepoList = allRepoList.filter(item => { - return item.type === 'public'; - }); + const promiseListRepos = seafileAPI.listRepos({ 'type': ['mine', 'shared', 'public'] }); + const promiseListGroups = seafileAPI.listGroups(true); + Promise.all([promiseListRepos, promiseListGroups]).then(res => { + const [resListRepos, resListGroups] = res; + const allRepoList = resListRepos.data.repos.map((item) => new Repo(item)); + const myRepoList = allRepoList.filter(item => item.type === 'mine'); + const sharedRepoList = allRepoList.filter(item => item.type === 'shared'); + const publicRepoList = allRepoList.filter(item => item.type === 'public'); + const groupList = resListGroups.data.map(item => { + let group = new Group(item); + group.repos = item.repos.map(item => new Repo(item)); + return group; + }).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1 ); this.setState({ isLoading: false, - sharedRepoList: sharedRepoList, - publicRepoList: publicRepoList, + groupList, + sharedRepoList, + publicRepoList, repoList: Utils.sortRepos(myRepoList, this.state.sortBy, this.state.sortOrder), - },() => { - this.setState({ - isSharedLoading: false, - isPublicLoading: false - }); }); }).catch((error) => { this.setState({ isLoading: false, - errorMsg: Utils.getErrorMsg(error, true), // true: show login tip if 403 + errorMsg: Utils.getErrorMsg(error, true), }); }); - }; + } toggleSortOptionsDialog = () => { this.setState({ @@ -170,30 +150,6 @@ class Libraries extends Component { }; // the following are for 'groups' - listGroups = () => { - seafileAPI.listGroups(true).then((res) => { - // `{'with_repos': 1}`: list repos of every group - let groupList = res.data.map(item => { - let group = new Group(item); - group.repos = item.repos.map(item => { - return new Repo(item); - }); - return group; - }); - this.setState({ - isGroupsLoading: false, - groupList: groupList.sort((a, b) => { - return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; - }) - }); - }).catch((error) => { - this.setState({ - isGroupsLoading: false, - groupsErrorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403 - }); - }); - }; - onCreateGroup = (groupData) => { const newGroup = new Group(groupData); const { groupList: newList } = this.state; @@ -216,7 +172,7 @@ class Libraries extends Component { }; render() { - + const { isLoading } = this.state; return (

{gettext('Files')}

-
+ {isLoading ? + : +
- - - - - - - - - - - - -
{gettext('Library Type')}{gettext('Name')}{gettext('Actions')}{gettext('Size')}{gettext('Last Update')}{gettext('Owner')}
+ + + + + + + + + + + + +
{gettext('Library Type')}{gettext('Name')}{gettext('Actions')}{gettext('Size')}{gettext('Last Update')}{gettext('Owner')}
- {canAddRepo && ( -
-
-

- - {gettext('My Libraries')} -

- {(!Utils.isDesktop() && this.state.repoList.length > 0) && } -
- {this.state.isLoading ? : ( - this.state.errorMsg ?

{this.state.errorMsg}

: ( + {canAddRepo && ( +
+
+

+ + {gettext('My Libraries')} +

+ {(!Utils.isDesktop() && this.state.repoList.length > 0) && + + } +
+ {this.state.errorMsg ?

{this.state.errorMsg}

: ( this.state.repoList.length === 0 ? (

{gettext('No libraries')}

) : ( @@ -275,46 +234,35 @@ class Libraries extends Component { sortRepoList={this.sortRepoList} inAllLibs={true} /> - )))} -
- )} - -
- {!this.state.isSharedLoading && - - } -
- - {canViewOrg && !this.state.isPublicLoading && ( + )) + } +
+ )}
- + +
+ {canViewOrg && +
+ +
+ } +
+ {this.state.groupList.length > 0 && ( + this.state.groupList.map((group, index) => { + return ( + + ); + }) + )}
- )} - -
- {this.state.isGroupsLoading? : ( - this.state.groupsErrorMsg ?

{this.state.groupsErrorMsg}

: ( - this.state.groupList.length > 0 && ( - this.state.groupList.map((group, index) => { - return ( - - ); - }) - )))}
- -
+ }
- {!this.state.isLoading && !this.state.errorMsg && this.state.isGuideForNewDialogOpen && + {!isLoading && !this.state.errorMsg && this.state.isGuideForNewDialogOpen &&