mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-23 04:18:21 +00:00
update sdoc module (#5437)
This commit is contained in:
@@ -1,61 +1,26 @@
|
||||
import React from 'react';
|
||||
import ReactDom from 'react-dom';
|
||||
import { SDocViewer } from '@seafile/sdoc-editor';
|
||||
import { seafileAPI } from './utils/seafile-api';
|
||||
import { Utils } from './utils/utils';
|
||||
import { defaultContentForSDoc } from './utils/constants';
|
||||
import SharedFileView from './components/shared-file-view/shared-file-view';
|
||||
import SharedFileViewTip from './components/shared-file-view/shared-file-view-tip';
|
||||
import Loading from './components/loading';
|
||||
import toaster from './components/toast';
|
||||
import { SimpleViewer } from '@seafile/sdoc-editor';
|
||||
|
||||
import './css/sdoc-file-view.css';
|
||||
const { serviceURL } = window.app.config;
|
||||
const { repoID, filePath, fileName } = window.shared.pageOptions;
|
||||
|
||||
const { rawPath, err } = window.shared.pageOptions;
|
||||
const { rawPath } = window.shared.pageOptions;
|
||||
|
||||
window.seafile = {
|
||||
repoID,
|
||||
rawPath: rawPath,
|
||||
docName: fileName, // required
|
||||
docPath: filePath,
|
||||
serviceUrl: serviceURL,
|
||||
};
|
||||
|
||||
class ViewFileSdoc extends React.Component {
|
||||
|
||||
class SharedFileViewSdoc extends React.Component {
|
||||
render() {
|
||||
return <SharedFileView content={<FileContent />} />;
|
||||
return <SimpleViewer />;
|
||||
}
|
||||
}
|
||||
|
||||
class FileContent extends React.Component {
|
||||
ReactDom.render(<ViewFileSdoc />, document.getElementById('wrapper'));
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
loading: !err
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
seafileAPI.getFileContent(rawPath).then((res) => {
|
||||
this.setState({
|
||||
content: res.data || defaultContentForSDoc,
|
||||
loading: false
|
||||
});
|
||||
}).catch(error => {
|
||||
let errMessage = Utils.getErrorMsg(error);
|
||||
toaster.danger(errMessage);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { loading, content } = this.state;
|
||||
if (err) {
|
||||
return <SharedFileViewTip />;
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="shared-file-view-body d-flex flex-column sdoc-file-view p-0">
|
||||
{content && <SDocViewer document={content} config={{}} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ReactDom.render(<SharedFileViewSdoc />, document.getElementById('wrapper'));
|
||||
|
Reference in New Issue
Block a user