1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

optimize code (#5467)

* optimize code

* optimize code

* optimize code
This commit is contained in:
杨顺强
2023-05-12 14:12:28 +08:00
committed by GitHub
parent 87dc0289d1
commit 3746fedfb4
3 changed files with 69 additions and 2 deletions

View File

@@ -0,0 +1,52 @@
import React from 'react';
import PropTypes from 'prop-types';
import { EventBus, EXTERNAL_EVENT } from '@seafile/sdoc-editor';
import InternalLinkDialog from '../../components/dialog/internal-link-dialog';
const propTypes = {
repoID: PropTypes.string.isRequired,
docPath: PropTypes.string.isRequired,
};
class ExternalOperations extends React.Component {
constructor(props) {
super(props);
this.state = {
isShowInternalLinkDialog: false,
};
}
componentDidMount() {
const eventBus = EventBus.getInstance();
this.unsubscribeInternalLinkEvent = eventBus.subscribe(EXTERNAL_EVENT.INTERNAL_LINK_CLICK, this.onInternalLinkToggle);
}
componentWillUnmount() {
this.unsubscribeInternalLinkEvent();
}
onInternalLinkToggle = () => {
this.setState({isShowInternalLinkDialog: !this.state.isShowInternalLinkDialog});
}
render() {
const { repoID, docPath } = this.props;
const { isShowInternalLinkDialog } = this.state;
return (
<>
{isShowInternalLinkDialog && (
<InternalLinkDialog
repoID={repoID}
path={docPath}
onInternalLinkDialogToggle={this.onInternalLinkToggle}
/>
)}
</>
);
}
}
ExternalOperations.propTypes = propTypes;
export default ExternalOperations;

View File

@@ -0,0 +1,15 @@
import React, { Fragment } from 'react';
import { SimpleEditor } from '@seafile/sdoc-editor';
import ExternalOperations from './external-operations';
export default class SdocEditor extends React.Component {
render() {
const { repoID, docPath } = window.seafile;
return (
<Fragment>
<SimpleEditor />
<ExternalOperations repoID={repoID} docPath={docPath} />
</Fragment>
);
}
}

View File

@@ -1,10 +1,10 @@
import React, { Suspense } from 'react'; import React, { Suspense } from 'react';
import ReactDom from 'react-dom'; import ReactDom from 'react-dom';
import { SimpleEditor } from '@seafile/sdoc-editor';
import { I18nextProvider } from 'react-i18next'; import { I18nextProvider } from 'react-i18next';
import i18n from './_i18n/i18n-sdoc-editor'; import i18n from './_i18n/i18n-sdoc-editor';
import { Utils } from './utils/utils'; import { Utils } from './utils/utils';
import Loading from './components/loading'; import Loading from './components/loading';
import SdocEditor from './pages/sdoc-editor';
const { serviceURL, avatarURL, siteRoot } = window.app.config; const { serviceURL, avatarURL, siteRoot } = window.app.config;
const { username, name } = window.app.userInfo; const { username, name } = window.app.userInfo;
@@ -34,7 +34,7 @@ window.seafile = {
ReactDom.render( ReactDom.render(
<I18nextProvider i18n={ i18n } > <I18nextProvider i18n={ i18n } >
<Suspense fallback={<Loading />}> <Suspense fallback={<Loading />}>
<SimpleEditor /> <SdocEditor />
</Suspense> </Suspense>
</I18nextProvider>, </I18nextProvider>,
document.getElementById('wrapper') document.getElementById('wrapper')