1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-17 15:53:28 +00:00
Files
seahub/frontend/src/pages/wiki2/main-panel.js

91 lines
2.9 KiB
JavaScript
Raw Normal View History

2024-05-29 15:19:42 +08:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { SdocWikiViewer } from '@seafile/sdoc-editor';
2024-05-29 15:19:42 +08:00
import { gettext, username } from '../../utils/constants';
import Loading from '../../components/loading';
import { Utils } from '../../utils/utils';
import Account from '../../components/common/account';
import WikiTopNav from './top-nav';
const propTypes = {
path: PropTypes.string.isRequired,
pathExist: PropTypes.bool.isRequired,
isViewFile: PropTypes.bool.isRequired,
isDataLoading: PropTypes.bool.isRequired,
editorContent: PropTypes.object,
permission: PropTypes.string,
2024-05-17 15:09:41 +08:00
seadoc_access_token: PropTypes.string,
2024-05-17 16:46:12 +08:00
assets_url: PropTypes.string,
config: PropTypes.object,
currentPageId: PropTypes.string,
};
class MainPanel extends Component {
2024-05-17 15:09:41 +08:00
constructor(props) {
super(props);
this.state = {
docUuid: '',
};
}
static getDerivedStateFromProps(props, state) {
const { seadoc_access_token } = props;
const config = window.app.config;
2024-05-17 15:09:41 +08:00
const pageOptions = window.app.pageOptions;
const { assetsUrl, seadocServerUrl: sdocServer, } = window.wiki.config;
window.seafile = {
...window.seafile, // need docUuid
...config,
2024-05-17 15:09:41 +08:00
...pageOptions,
sdocServer,
2024-05-17 16:46:12 +08:00
assetsUrl: assetsUrl || props.assets_url,
2024-05-17 15:09:41 +08:00
accessToken: seadoc_access_token,
serviceUrl: config.serviceURL,
assets_url: config.assetsUrl,
2024-05-17 15:09:41 +08:00
};
return { ...props, docUuid: window.seafile.docUuid };
2024-05-17 15:09:41 +08:00
}
render() {
const { permission, pathExist, isDataLoading, isViewFile } = this.props;
2024-05-22 15:53:30 +08:00
const isViewingFile = pathExist && !isDataLoading && isViewFile;
2024-05-23 17:16:44 +08:00
const isReadOnly = !(permission === 'rw');
return (
<div className="wiki2-main-panel">
<div className='wiki2-main-panel-north'>
<WikiTopNav
config={this.props.config}
currentPageId={this.props.currentPageId}
/>
{username &&
<Account />
}
</div>
<div className="main-panel-center">
<div className={`cur-view-content ${isViewingFile ? 'o-hidden' : ''}`}>
2024-05-29 15:19:42 +08:00
{!this.props.pathExist &&
<div className="message err-tip">{gettext('Folder does not exist.')}</div>
}
{this.props.pathExist && this.props.isDataLoading && <Loading />}
2024-05-17 16:46:12 +08:00
{isViewingFile && Utils.isSdocFile(this.props.path) && (
2024-06-11 18:14:14 +08:00
<div>
<SdocWikiViewer
document={this.props.editorContent}
docUuid={this.state.docUuid}
isWikiReadOnly={isReadOnly}
topSlot={<Input className='sf-wiki-title' bsSize="lg" onChange={this.handleRenameDocument} defaultValue={currentPageConfig.name} />}
/>
</div>
)}
</div>
</div>
</div>
);
}
}
MainPanel.propTypes = propTypes;
export default MainPanel;