2023-05-12 06:12:28 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { EventBus, EXTERNAL_EVENT } from '@seafile/sdoc-editor';
|
2023-06-30 13:51:27 +00:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
import toaster from '../../components/toast';
|
2023-05-12 06:12:28 +00:00
|
|
|
import InternalLinkDialog from '../../components/dialog/internal-link-dialog';
|
2023-08-10 10:05:01 +00:00
|
|
|
import ShareDialog from '../../components/dialog/share-dialog';
|
2023-05-12 06:12:28 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
repoID: PropTypes.string.isRequired,
|
|
|
|
docPath: PropTypes.string.isRequired,
|
2023-08-10 10:05:01 +00:00
|
|
|
docName: PropTypes.string.isRequired,
|
|
|
|
docPerm: PropTypes.string.isRequired,
|
2023-06-30 13:51:27 +00:00
|
|
|
isStarred: PropTypes.bool.isRequired,
|
2023-07-22 07:54:25 +00:00
|
|
|
toggleStar: PropTypes.func.isRequired,
|
|
|
|
unmarkDraft: PropTypes.func.isRequired
|
2023-05-12 06:12:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ExternalOperations extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isShowInternalLinkDialog: false,
|
2023-08-10 10:05:01 +00:00
|
|
|
isShowShareDialog: false,
|
2023-05-12 06:12:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const eventBus = EventBus.getInstance();
|
|
|
|
this.unsubscribeInternalLinkEvent = eventBus.subscribe(EXTERNAL_EVENT.INTERNAL_LINK_CLICK, this.onInternalLinkToggle);
|
2023-06-30 13:51:27 +00:00
|
|
|
this.unsubscribeStar = eventBus.subscribe(EXTERNAL_EVENT.TOGGLE_STAR, this.toggleStar);
|
2023-07-22 07:54:25 +00:00
|
|
|
this.unsubscribeUnmark = eventBus.subscribe(EXTERNAL_EVENT.UNMARK_AS_DRAFT, this.unmark);
|
2023-08-10 10:05:01 +00:00
|
|
|
this.unsubscribeShare = eventBus.subscribe(EXTERNAL_EVENT.SHARE_SDOC, this.onShareToggle);
|
2023-05-12 06:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.unsubscribeInternalLinkEvent();
|
2023-06-30 13:51:27 +00:00
|
|
|
this.unsubscribeStar();
|
2023-07-22 07:54:25 +00:00
|
|
|
this.unsubscribeUnmark();
|
2023-08-10 10:05:01 +00:00
|
|
|
this.unsubscribeShare();
|
2023-05-12 06:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onInternalLinkToggle = () => {
|
|
|
|
this.setState({isShowInternalLinkDialog: !this.state.isShowInternalLinkDialog});
|
|
|
|
}
|
|
|
|
|
2023-07-22 07:54:25 +00:00
|
|
|
unmark = () => {
|
|
|
|
const { repoID, docPath } = this.props;
|
|
|
|
seafileAPI.sdocUnmarkAsDraft(repoID, docPath).then((res) => {
|
|
|
|
this.props.unmarkDraft();
|
|
|
|
}).catch(error => {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-30 13:51:27 +00:00
|
|
|
toggleStar = () => {
|
|
|
|
const { isStarred, repoID, docPath } = this.props;
|
|
|
|
if (isStarred) {
|
|
|
|
seafileAPI.unstarItem(repoID, docPath).then((res) => {
|
|
|
|
this.props.toggleStar(false);
|
|
|
|
}).catch((error) => {
|
|
|
|
const errorMsg = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
seafileAPI.starItem(repoID, docPath).then((res) => {
|
|
|
|
this.props.toggleStar(true);
|
|
|
|
}).catch((error) => {
|
|
|
|
const errorMsg = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-10 10:05:01 +00:00
|
|
|
onShareToggle = () => {
|
|
|
|
this.setState({isShowShareDialog: !this.state.isShowShareDialog});
|
|
|
|
}
|
|
|
|
|
2023-05-12 06:12:28 +00:00
|
|
|
render() {
|
2023-08-10 10:05:01 +00:00
|
|
|
const { repoID, docPath, docName, docPerm } = this.props;
|
|
|
|
const { isShowInternalLinkDialog, isShowShareDialog } = this.state;
|
2023-05-12 06:12:28 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{isShowInternalLinkDialog && (
|
|
|
|
<InternalLinkDialog
|
|
|
|
repoID={repoID}
|
|
|
|
path={docPath}
|
|
|
|
onInternalLinkDialogToggle={this.onInternalLinkToggle}
|
|
|
|
/>
|
|
|
|
)}
|
2023-08-10 10:05:01 +00:00
|
|
|
{isShowShareDialog && (
|
|
|
|
<ShareDialog
|
|
|
|
itemType={'file'}
|
|
|
|
itemPath={docPath}
|
|
|
|
itemName={docName}
|
|
|
|
repoID={repoID}
|
|
|
|
userPerm={docPerm}
|
|
|
|
toggleDialog={this.onShareToggle}
|
|
|
|
/>
|
|
|
|
)}
|
2023-05-12 06:12:28 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExternalOperations.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default ExternalOperations;
|