Skip to content

Commit

Permalink
feat: optimize eventBus
Browse files Browse the repository at this point in the history
  • Loading branch information
stephensu66 authored and 杨国璇 committed Oct 11, 2024
1 parent f67adaf commit 2b40f59
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions frontend/src/pages/markdown-editor/header-toolbar/header-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class HeaderToolbar extends React.Component {
filePath: filePath,
dirPath: dirPath,
currentDirent: null,
isArticeleInfoOpen: false
};
}

Expand All @@ -68,11 +69,18 @@ class HeaderToolbar extends React.Component {

componentDidMount() {
this.getDirentList();

const eventBus = EventBus.getInstance();
eventBus.subscribe(EXTERNAL_EVENTS.ON_HELP_INFO_TOGGLE, this.handleHelpClick);
}

onArticleInfoToggle = () => {
componentWillUnmount() {
const eventBus = EventBus.getInstance();
eventBus.dispatch(EXTERNAL_EVENTS.ON_ARTICLE_INFO_TOGGLE);
eventBus.unsubscribe(EXTERNAL_EVENTS.ON_HELP_INFO_TOGGLE, this.handleHelpClick);
}

handleHelpClick = () => {
this.setState({ isArticeleInfoOpen: false });
};

getDirentList = () => {
Expand All @@ -89,27 +97,33 @@ class HeaderToolbar extends React.Component {
});
};

onArticleInfoDetailToggle = () => {
const { repoID, filePath, currentDirent } = this.state;
const repoInfo = { permission: 'rw' };
onArticleInfoToggle = () => {
const { repoID, filePath, currentDirent, isArticeleInfoOpen } = this.state;
const repoInfo = { permission: currentDirent.permission };

const eventBus = EventBus.getInstance();
eventBus.dispatch(EXTERNAL_EVENTS.ON_ARTICLE_INFO_DETAIL_TOGGLE, {
component: EmbeddedFileDetails,
props: {
repoID: repoID,
repoInfo: repoInfo,
dirent: currentDirent,
path: filePath,
onClose: this.onArticleInfoToggle,
width: 300,
component: {
headerComponent: {
closeIcon: (<i className="iconfont icon-x"></i>)
if (isArticeleInfoOpen) {
eventBus.dispatch(EXTERNAL_EVENTS.ON_ARTICLE_INFO_TOGGLE, { component: null, props: null });
this.setState({ isArticeleInfoOpen: false });
} else {
eventBus.dispatch(EXTERNAL_EVENTS.ON_ARTICLE_INFO_TOGGLE, {
component: EmbeddedFileDetails,
props: {
repoID: repoID,
repoInfo: repoInfo,
dirent: currentDirent,
path: filePath,
onClose: this.onArticleInfoToggle,
width: 300,
component: {
headerComponent: {
closeIcon: (<i className="iconfont icon-x"></i>)
}
}
}
}
});
});
this.setState({ isArticeleInfoOpen: true });
}
};

render() {
Expand Down Expand Up @@ -157,10 +171,7 @@ class HeaderToolbar extends React.Component {
id='file-info'
text={gettext('Info')}
icon='info'
onMouseDown={() => {
this.onArticleInfoDetailToggle();
this.onArticleInfoToggle();
}}
onMouseDown={this.onArticleInfoToggle}
/>
{canGenerateShareLink && (
<ButtonItem
Expand Down

0 comments on commit 2b40f59

Please sign in to comment.