mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 19:08:21 +00:00
['share dialog' - 'Share Link', 'Share Admin' - 'Links'] share links: get limited links per request, scroll down to get more (#5840)
This commit is contained in:
@@ -18,6 +18,8 @@ const propTypes = {
|
||||
itemType: PropTypes.string
|
||||
};
|
||||
|
||||
const PER_PAGE = 25;
|
||||
|
||||
class ShareLinkPanel extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
@@ -28,6 +30,9 @@ class ShareLinkPanel extends React.Component {
|
||||
|
||||
this.state = {
|
||||
isLoading: true,
|
||||
hasMore: false,
|
||||
isLoadingMore: false,
|
||||
page: 1,
|
||||
mode: 'listLinks',
|
||||
sharedLinkInfo: null,
|
||||
shareLinks: [],
|
||||
@@ -37,11 +42,12 @@ class ShareLinkPanel extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
let path = this.props.itemPath;
|
||||
let repoID = this.props.repoID;
|
||||
seafileAPI.getShareLink(repoID, path).then((res) => {
|
||||
const { page } = this.state;
|
||||
const { repoID, itemPath: path } = this.props;
|
||||
seafileAPI.listShareLinks({repoID, path, page}).then((res) => {
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
hasMore: res.data.length == PER_PAGE,
|
||||
shareLinks: res.data.map(item => new ShareLink(item))
|
||||
});
|
||||
}).catch(error => {
|
||||
@@ -184,13 +190,46 @@ class ShareLinkPanel extends React.Component {
|
||||
});
|
||||
};
|
||||
|
||||
handleScroll = (event) => {
|
||||
if (!this.state.isLoadingMore && this.state.hasMore) {
|
||||
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.getMore();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
getMore = () => {
|
||||
const { page, shareLinks } = this.state;
|
||||
const { repoID, itemPath: path } = this.props;
|
||||
seafileAPI.listShareLinks({repoID, path, page: page + 1}).then((res) => {
|
||||
this.setState({
|
||||
isLoadingMore: false,
|
||||
hasMore: res.data.length == PER_PAGE,
|
||||
page: page + 1,
|
||||
shareLinks: shareLinks.concat(res.data.map(item => new ShareLink(item)))
|
||||
});
|
||||
}).catch(error => {
|
||||
this.setState({
|
||||
isLoadingMore: false
|
||||
});
|
||||
let errMessage = Utils.getErrorMsg(error);
|
||||
toaster.danger(errMessage);
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
if (this.state.isLoading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
const { repoID, itemPath, userPerm } = this.props;
|
||||
const { mode, shareLinks, sharedLinkInfo, permissionOptions, currentPermission } = this.state;
|
||||
const { mode, shareLinks, sharedLinkInfo, permissionOptions, currentPermission, isLoadingMore } = this.state;
|
||||
|
||||
switch (mode) {
|
||||
case 'displayLinkDetails':
|
||||
@@ -242,6 +281,8 @@ class ShareLinkPanel extends React.Component {
|
||||
toggleSelectLink={this.toggleSelectLink}
|
||||
deleteShareLinks={this.deleteShareLinks}
|
||||
deleteLink={this.deleteLink}
|
||||
handleScroll={this.handleScroll}
|
||||
isLoadingMore={isLoadingMore}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user