1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-12 21:30:39 +00:00

[group] added 'load more repos' (#4649)

This commit is contained in:
llj
2020-08-17 11:53:33 +08:00
committed by GitHub
parent e9c2e5c76e
commit 483c6fc5c3
2 changed files with 53 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ import { Utils } from '../../utils/utils';
import SharedRepoListItem from './shared-repo-list-item'; import SharedRepoListItem from './shared-repo-list-item';
import toaster from '../toast'; import toaster from '../toast';
import LibsMobileThead from '../libs-mobile-thead'; import LibsMobileThead from '../libs-mobile-thead';
import Loading from '../loading';
const propTypes = { const propTypes = {
libraryType: PropTypes.string, libraryType: PropTypes.string,
@@ -18,6 +19,7 @@ const propTypes = {
onItemDelete: PropTypes.func, onItemDelete: PropTypes.func,
onItemDetails: PropTypes.func, onItemDetails: PropTypes.func,
onItemRename: PropTypes.func, onItemRename: PropTypes.func,
hasNextPage: PropTypes.bool
}; };
class SharedRepoListView extends React.Component { class SharedRepoListView extends React.Component {
@@ -141,10 +143,16 @@ class SharedRepoListView extends React.Component {
} }
render() { render() {
if (Utils.isDesktop()) { const table = Utils.isDesktop() ? this.renderPCUI() : this.renderMobileUI();
return this.renderPCUI(); if (this.props.hasNextPage) {
return (
<Fragment>
{table}
<Loading />
</Fragment>
);
} else { } else {
return this.renderMobileUI(); return table;
} }
} }
} }

View File

@@ -40,7 +40,8 @@ class GroupView extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
isLoading: true, isLoading: true, // first loading
isLoadingMore: false,
errMessage: '', errMessage: '',
emptyTip: null, emptyTip: null,
currentGroup: null, currentGroup: null,
@@ -51,6 +52,9 @@ class GroupView extends React.Component {
sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc' sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
isSortOptionsDialogOpen: false, isSortOptionsDialogOpen: false,
repoList: [], repoList: [],
currentPage: 1,
perPage: 50,
hasNextPage: false,
libraryType: 'group', libraryType: 'group',
isCreateRepoDialogShow: false, isCreateRepoDialogShow: false,
isDepartmentGroup: false, isDepartmentGroup: false,
@@ -91,8 +95,9 @@ class GroupView extends React.Component {
isStaff: isStaff, isStaff: isStaff,
isDepartmentGroup: isDepartmentGroup, isDepartmentGroup: isDepartmentGroup,
isOwner: isOwner, isOwner: isOwner,
repoList: [] // empty it for the current group
}); });
this.loadRepos(groupID); this.loadRepos(this.state.currentPage);
}).catch((error) => { }).catch((error) => {
this.setState({ this.setState({
isLoading: false, isLoading: false,
@@ -101,20 +106,32 @@ class GroupView extends React.Component {
}); });
} }
loadRepos = (groupID) => { loadRepos = (page) => {
this.setState({isLoading: true}); const { perPage } = this.state;
seafileAPI.listGroupRepos(groupID).then((res) => { seafileAPI.listGroupRepos(this.props.groupID, page, perPage).then((res) => {
let repoList = res.data.map(item => { let hasNextPage = true;
if (res.data.length < perPage) {
hasNextPage = false;
}
let repoList = this.state.repoList;
let newRepoList = res.data.map(item => {
let repo = new Repo(item); let repo = new Repo(item);
return repo; return repo;
}); });
if (newRepoList.length) {
repoList = repoList.concat(newRepoList);
}
this.setState({ this.setState({
isLoading: false, isLoading: false,
isLoadingMore: false,
currentPage: page,
hasNextPage: hasNextPage,
repoList: Utils.sortRepos(repoList, this.state.sortBy, this.state.sortOrder) repoList: Utils.sortRepos(repoList, this.state.sortBy, this.state.sortOrder)
}); });
}).catch((error) => { }).catch((error) => {
this.setState({ this.setState({
isLoading: false, isLoading: false,
isLoadingMore: false,
errMessage: Utils.getErrorMsg(error, true) // true: show login tip if 403 errMessage: Utils.getErrorMsg(error, true) // true: show login tip if 403
}); });
}); });
@@ -347,6 +364,22 @@ class GroupView extends React.Component {
}); });
} }
handleScroll = (event) => {
// isLoadingMore: to avoid repeated request
const { currentPage, hasNextPage, isLoadingMore } = this.state;
if (hasNextPage && !isLoadingMore) {
const clientHeight = event.target.clientHeight;
const scrollHeight = event.target.scrollHeight;
const scrollTop = event.target.scrollTop;
const isBottom = (clientHeight + scrollTop + 1 >= scrollHeight);
if (isBottom) { // scroll to the bottom
this.setState({isLoadingMore: true}, () => {
this.loadRepos(currentPage + 1);
});
}
}
}
render() { render() {
let { errMessage, emptyTip, currentGroup, isDepartmentGroup, isStaff } = this.state; let { errMessage, emptyTip, currentGroup, isDepartmentGroup, isStaff } = this.state;
let isShowSettingIcon = false; let isShowSettingIcon = false;
@@ -492,13 +525,14 @@ class GroupView extends React.Component {
</Fragment> </Fragment>
)} )}
</div> </div>
<div className="cur-view-content"> <div className="cur-view-content d-block" onScroll={this.handleScroll}>
{this.state.isLoading && <Loading />} {this.state.isLoading && <Loading />}
{(!this.state.isLoading && errMessage) && <div className="error text-center mt-2">{errMessage}</div>} {(!this.state.isLoading && errMessage) && <div className="error text-center mt-2">{errMessage}</div>}
{(!this.state.isLoading && this.state.repoList.length === 0) && emptyTip} {(!this.state.isLoading && this.state.repoList.length === 0) && emptyTip}
{(!this.state.isLoading && this.state.repoList.length > 0) && {(!this.state.isLoading && this.state.repoList.length > 0) &&
<SharedRepoListView <SharedRepoListView
repoList={this.state.repoList} repoList={this.state.repoList}
hasNextPage={this.state.hasNextPage}
currentGroup={this.state.currentGroup} currentGroup={this.state.currentGroup}
sortBy={this.state.sortBy} sortBy={this.state.sortBy}
sortOrder={this.state.sortOrder} sortOrder={this.state.sortOrder}