From d6142e043275a2097780a06bae2f7075653a8a99 Mon Sep 17 00:00:00 2001 From: liuhongbo <916196375@qq.com> Date: Fri, 1 Mar 2024 18:15:01 +0800 Subject: [PATCH] fix: optimize code --- .../sdoc/sdoc-editor/external-operations.js | 20 +++++++++---------- frontend/src/pages/sdoc/sdoc-editor/index.js | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/frontend/src/pages/sdoc/sdoc-editor/external-operations.js b/frontend/src/pages/sdoc/sdoc-editor/external-operations.js index 880eaba672..9e54256614 100644 --- a/frontend/src/pages/sdoc/sdoc-editor/external-operations.js +++ b/frontend/src/pages/sdoc/sdoc-editor/external-operations.js @@ -19,7 +19,7 @@ const propTypes = { toggleStar: PropTypes.func.isRequired, unmarkDraft: PropTypes.func.isRequired, onNewNotification: PropTypes.func.isRequired, - onNotificationCleared: PropTypes.func.isRequired + onClearNotification: PropTypes.func.isRequired }; 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.unsubscribeUnfreeze = eventBus.subscribe(EXTERNAL_EVENT.UNFREEZE, this.unFreeze); 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); } @@ -62,9 +62,9 @@ class ExternalOperations extends React.Component { onInternalLinkToggle = (options) => { 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 = () => { @@ -78,7 +78,7 @@ class ExternalOperations extends React.Component { }; toggleStar = () => { - const { isStarred, repoID, docPath } = this.props; + const { isStarred, repoID, docPath } = this.props; if (isStarred) { seafileAPI.unstarItem(repoID, docPath).then((res) => { this.props.toggleStar(false); @@ -97,7 +97,7 @@ class ExternalOperations extends React.Component { }; onShareToggle = () => { - this.setState({isShowShareDialog: !this.state.isShowShareDialog}); + this.setState({ isShowShareDialog: !this.state.isShowShareDialog }); }; onFreezeDocument = () => { @@ -126,13 +126,13 @@ class ExternalOperations extends React.Component { this.props.onNewNotification(); }; - onNotificationCleared = () => { - this.props.onNotificationCleared(); + onClearNotification = () => { + this.props.onClearNotification(); }; onCreateSdocFile = (params) => { if (params?.newFileName) { - this.setState({fileType: `${params.newFileName}.sdoc`}); + this.setState({ fileType: `${params.newFileName}.sdoc` }); } this.setState({ isShowCreateFileDialog: !this.state.isShowCreateFileDialog @@ -151,7 +151,7 @@ class ExternalOperations extends React.Component { let repoID = this.props.repoID; seafileAPI.createFile(repoID, filePath, isMarkdownDraft).then((res) => { const eventBus = EventBus.getInstance(); - eventBus.dispatch(EXTERNAL_EVENT.INSERT_LINK, {data: res.data}); + eventBus.dispatch(EXTERNAL_EVENT.INSERT_LINK, { data: res.data }); }).catch((error) => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); diff --git a/frontend/src/pages/sdoc/sdoc-editor/index.js b/frontend/src/pages/sdoc/sdoc-editor/index.js index 20b423d585..aadb0546bb 100644 --- a/frontend/src/pages/sdoc/sdoc-editor/index.js +++ b/frontend/src/pages/sdoc/sdoc-editor/index.js @@ -23,11 +23,11 @@ export default class SdocEditor extends React.Component { } toggleStar = (isStarred) => { - this.setState({isStarred: isStarred}); + this.setState({ isStarred: isStarred }); }; unmarkDraft = () => { - this.setState({isDraft: false}); + this.setState({ isDraft: false }); }; onSetFavicon = (suffix) => { @@ -43,7 +43,7 @@ export default class SdocEditor extends React.Component { this.onSetFavicon('_notification'); }; - onNotificationCleared = () => { + onClearNotification = () => { this.onSetFavicon(); }; @@ -59,7 +59,7 @@ export default class SdocEditor extends React.Component { getDirentList = () => { const { repoID } = window.seafile; const path = this.getDirPath(); - seafileAPI.listDir(repoID, path, {'with_thumbnail': true}).then(res => { + seafileAPI.listDir(repoID, path, { 'with_thumbnail': true }).then(res => { let direntList = []; res.data.dirent_list.forEach(item => { let dirent = new Dirent(item); @@ -91,7 +91,7 @@ export default class SdocEditor extends React.Component { toggleStar={this.toggleStar} unmarkDraft={this.unmarkDraft} onNewNotification={this.onNewNotification} - onNotificationCleared={this.onNotificationCleared} + onClearNotification={this.onClearNotification} /> );