1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-25 10:11:24 +00:00

fix: optimize code

This commit is contained in:
liuhongbo 2024-03-01 18:15:01 +08:00
parent fb17628cc8
commit d6142e0432
2 changed files with 15 additions and 15 deletions

View File

@ -19,7 +19,7 @@ const propTypes = {
toggleStar: PropTypes.func.isRequired, toggleStar: PropTypes.func.isRequired,
unmarkDraft: PropTypes.func.isRequired, unmarkDraft: PropTypes.func.isRequired,
onNewNotification: PropTypes.func.isRequired, onNewNotification: PropTypes.func.isRequired,
onNotificationCleared: PropTypes.func.isRequired onClearNotification: PropTypes.func.isRequired
}; };
class ExternalOperations extends React.Component { class ExternalOperations extends React.Component {
@ -44,7 +44,7 @@ class ExternalOperations extends React.Component {
this.unsubscribeFreezeDocument = eventBus.subscribe(EXTERNAL_EVENT.FREEZE_DOCUMENT, this.onFreezeDocument); this.unsubscribeFreezeDocument = eventBus.subscribe(EXTERNAL_EVENT.FREEZE_DOCUMENT, this.onFreezeDocument);
this.unsubscribeUnfreeze = eventBus.subscribe(EXTERNAL_EVENT.UNFREEZE, this.unFreeze); this.unsubscribeUnfreeze = eventBus.subscribe(EXTERNAL_EVENT.UNFREEZE, this.unFreeze);
this.unsubscribeNewNotification = eventBus.subscribe(EXTERNAL_EVENT.NEW_NOTIFICATION, this.onNewNotification); this.unsubscribeNewNotification = eventBus.subscribe(EXTERNAL_EVENT.NEW_NOTIFICATION, this.onNewNotification);
this.unsubscribeClearNotification = eventBus.subscribe(EXTERNAL_EVENT.CLEAR_NOTIFICATION, this.onNotificationCleared); this.unsubscribeClearNotification = eventBus.subscribe(EXTERNAL_EVENT.CLEAR_NOTIFICATION, this.onClearNotification);
this.unsubscribeCreateSdocFile = eventBus.subscribe(EXTERNAL_EVENT.CREATE_SDOC_FILE, this.onCreateSdocFile); this.unsubscribeCreateSdocFile = eventBus.subscribe(EXTERNAL_EVENT.CREATE_SDOC_FILE, this.onCreateSdocFile);
} }
@ -62,9 +62,9 @@ class ExternalOperations extends React.Component {
onInternalLinkToggle = (options) => { onInternalLinkToggle = (options) => {
if (options && options.internalLink) { if (options && options.internalLink) {
this.setState({internalLink: options.internalLink}); this.setState({ internalLink: options.internalLink });
} }
this.setState({isShowInternalLinkDialog: !this.state.isShowInternalLinkDialog}); this.setState({ isShowInternalLinkDialog: !this.state.isShowInternalLinkDialog });
}; };
unmark = () => { unmark = () => {
@ -78,7 +78,7 @@ class ExternalOperations extends React.Component {
}; };
toggleStar = () => { toggleStar = () => {
const { isStarred, repoID, docPath } = this.props; const { isStarred, repoID, docPath } = this.props;
if (isStarred) { if (isStarred) {
seafileAPI.unstarItem(repoID, docPath).then((res) => { seafileAPI.unstarItem(repoID, docPath).then((res) => {
this.props.toggleStar(false); this.props.toggleStar(false);
@ -97,7 +97,7 @@ class ExternalOperations extends React.Component {
}; };
onShareToggle = () => { onShareToggle = () => {
this.setState({isShowShareDialog: !this.state.isShowShareDialog}); this.setState({ isShowShareDialog: !this.state.isShowShareDialog });
}; };
onFreezeDocument = () => { onFreezeDocument = () => {
@ -126,13 +126,13 @@ class ExternalOperations extends React.Component {
this.props.onNewNotification(); this.props.onNewNotification();
}; };
onNotificationCleared = () => { onClearNotification = () => {
this.props.onNotificationCleared(); this.props.onClearNotification();
}; };
onCreateSdocFile = (params) => { onCreateSdocFile = (params) => {
if (params?.newFileName) { if (params?.newFileName) {
this.setState({fileType: `${params.newFileName}.sdoc`}); this.setState({ fileType: `${params.newFileName}.sdoc` });
} }
this.setState({ this.setState({
isShowCreateFileDialog: !this.state.isShowCreateFileDialog isShowCreateFileDialog: !this.state.isShowCreateFileDialog
@ -151,7 +151,7 @@ class ExternalOperations extends React.Component {
let repoID = this.props.repoID; let repoID = this.props.repoID;
seafileAPI.createFile(repoID, filePath, isMarkdownDraft).then((res) => { seafileAPI.createFile(repoID, filePath, isMarkdownDraft).then((res) => {
const eventBus = EventBus.getInstance(); const eventBus = EventBus.getInstance();
eventBus.dispatch(EXTERNAL_EVENT.INSERT_LINK, {data: res.data}); eventBus.dispatch(EXTERNAL_EVENT.INSERT_LINK, { data: res.data });
}).catch((error) => { }).catch((error) => {
let errMessage = Utils.getErrorMsg(error); let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage); toaster.danger(errMessage);

View File

@ -23,11 +23,11 @@ export default class SdocEditor extends React.Component {
} }
toggleStar = (isStarred) => { toggleStar = (isStarred) => {
this.setState({isStarred: isStarred}); this.setState({ isStarred: isStarred });
}; };
unmarkDraft = () => { unmarkDraft = () => {
this.setState({isDraft: false}); this.setState({ isDraft: false });
}; };
onSetFavicon = (suffix) => { onSetFavicon = (suffix) => {
@ -43,7 +43,7 @@ export default class SdocEditor extends React.Component {
this.onSetFavicon('_notification'); this.onSetFavicon('_notification');
}; };
onNotificationCleared = () => { onClearNotification = () => {
this.onSetFavicon(); this.onSetFavicon();
}; };
@ -59,7 +59,7 @@ export default class SdocEditor extends React.Component {
getDirentList = () => { getDirentList = () => {
const { repoID } = window.seafile; const { repoID } = window.seafile;
const path = this.getDirPath(); const path = this.getDirPath();
seafileAPI.listDir(repoID, path, {'with_thumbnail': true}).then(res => { seafileAPI.listDir(repoID, path, { 'with_thumbnail': true }).then(res => {
let direntList = []; let direntList = [];
res.data.dirent_list.forEach(item => { res.data.dirent_list.forEach(item => {
let dirent = new Dirent(item); let dirent = new Dirent(item);
@ -91,7 +91,7 @@ export default class SdocEditor extends React.Component {
toggleStar={this.toggleStar} toggleStar={this.toggleStar}
unmarkDraft={this.unmarkDraft} unmarkDraft={this.unmarkDraft}
onNewNotification={this.onNewNotification} onNewNotification={this.onNewNotification}
onNotificationCleared={this.onNotificationCleared} onClearNotification={this.onClearNotification}
/> />
</Fragment> </Fragment>
); );