1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 16:31:13 +00:00

feat: seperate document and title components

This commit is contained in:
liuhongbo
2024-06-05 11:45:30 +08:00
parent 458a2b53c9
commit c01d03321d
5 changed files with 71 additions and 34 deletions

View File

@@ -5,7 +5,7 @@ import { Modal } from 'reactstrap';
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
import wikiAPI from '../../utils/wiki-api'; import wikiAPI from '../../utils/wiki-api';
import SDocServerApi from '../../utils/sdoc-server-api'; import SDocServerApi from '../../utils/sdoc-server-api';
import { wikiId, siteRoot, lang, isWiki2, seadocServerUrl } from '../../utils/constants'; import { wikiId, siteRoot, lang, isWiki2, seadocServerUrl, gettext } from '../../utils/constants';
import WikiConfig from './models/wiki-config'; import WikiConfig from './models/wiki-config';
import toaster from '../../components/toast'; import toaster from '../../components/toast';
import SidePanel from './side-panel'; import SidePanel from './side-panel';
@@ -172,6 +172,19 @@ class Wiki extends Component {
}); });
}; };
onUpdatePage = (pageId, newPage) => {
if (newPage.name === '') {
toaster.danger(gettext('Page name cannot be empty'));
return;
}
const { config } = this.state
let pages = config.pages;
let currentPage = pages.find(page => page.id === pageId);
Object.assign(currentPage, newPage);
config.pages = pages;
this.saveWikiConfig(config);
};
render() { render() {
return ( return (
<div id="main" className="wiki-main"> <div id="main" className="wiki-main">
@@ -183,6 +196,7 @@ class Wiki extends Component {
saveWikiConfig={this.saveWikiConfig} saveWikiConfig={this.saveWikiConfig}
setCurrentPage={this.setCurrentPage} setCurrentPage={this.setCurrentPage}
currentPageId={this.state.currentPageId} currentPageId={this.state.currentPageId}
onUpdatePage={this.onUpdatePage}
/> />
<MainPanel <MainPanel
path={this.state.path} path={this.state.path}
@@ -195,6 +209,7 @@ class Wiki extends Component {
permission={this.state.permission} permission={this.state.permission}
seadoc_access_token={this.state.seadoc_access_token} seadoc_access_token={this.state.seadoc_access_token}
assets_url={this.state.assets_url} assets_url={this.state.assets_url}
onUpdatePage={this.onUpdatePage}
/> />
<MediaQuery query="(max-width: 767.8px)"> <MediaQuery query="(max-width: 767.8px)">
<Modal isOpen={!this.state.closeSideBar} toggle={this.onCloseSide} contentClassName="d-none"></Modal> <Modal isOpen={!this.state.closeSideBar} toggle={this.onCloseSide} contentClassName="d-none"></Modal>

View File

@@ -1,11 +1,13 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { SdocWikiViewer } from '@seafile/sdoc-editor'; import { SdocWikiViewer } from '@seafile/sdoc-editor';
import { Input } from 'reactstrap';
import { gettext, username } from '../../utils/constants'; import { gettext, username } from '../../utils/constants';
import Loading from '../../components/loading'; import Loading from '../../components/loading';
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
import Account from '../../components/common/account'; import Account from '../../components/common/account';
import WikiTopNav from './top-nav'; import WikiTopNav from './top-nav';
import { getCurrentPageConfig } from './utils';
const propTypes = { const propTypes = {
path: PropTypes.string.isRequired, path: PropTypes.string.isRequired,
@@ -18,6 +20,7 @@ const propTypes = {
assets_url: PropTypes.string, assets_url: PropTypes.string,
config: PropTypes.object, config: PropTypes.object,
currentPageId: PropTypes.string, currentPageId: PropTypes.string,
onUpdatePage: PropTypes.func,
}; };
class MainPanel extends Component { class MainPanel extends Component {
@@ -26,36 +29,51 @@ class MainPanel extends Component {
super(props); super(props);
this.state = { this.state = {
docUuid: '', docUuid: '',
currentPageConfig: {},
}; };
} }
static getDerivedStateFromProps(props, state) { static getDerivedStateFromProps(props, state) {
const { seadoc_access_token } = props; const { seadoc_access_token, currentPageId, config } = props;
const config = window.app.config; const appConfig = window.app.config;
const pageOptions = window.app.pageOptions; const pageOptions = window.app.pageOptions;
const { assetsUrl, seadocServerUrl: sdocServer, } = window.wiki.config; const { assetsUrl, seadocServerUrl: sdocServer, } = window.wiki.config;
window.seafile = { window.seafile = {
...window.seafile, // need docUuid ...window.seafile, // need docUuid
...config, ...appConfig,
...pageOptions, ...pageOptions,
sdocServer, sdocServer,
assetsUrl: assetsUrl || props.assets_url, assetsUrl: assetsUrl || props.assets_url,
accessToken: seadoc_access_token, accessToken: seadoc_access_token,
serviceUrl: config.serviceURL, serviceUrl: appConfig.serviceURL,
assets_url: config.assetsUrl, assets_url: appConfig.assetsUrl,
}; };
return { ...props, docUuid: window.seafile.docUuid }; const currentPageConfig = getCurrentPageConfig(config.pages, currentPageId)
return { ...props, docUuid: window.seafile.docUuid, currentPageConfig };
}
handleRenameDocument = (e) => {
const newName = e.target.value.trim()
const { currentPageConfig } = this.state
const { id, name, icon } = currentPageConfig
if (newName === name) return;
const pageConfig = { name: newName, icon }
this.props.onUpdatePage(id, pageConfig)
// Reset title if name is empty
if (!newName) e.target.value = name;
} }
render() { render() {
const { permission, pathExist, isDataLoading, isViewFile } = this.props; const { permission, pathExist, isDataLoading, isViewFile, config } = this.props;
const { currentPageConfig } = this.state
const isViewingFile = pathExist && !isDataLoading && isViewFile; const isViewingFile = pathExist && !isDataLoading && isViewFile;
const isReadOnly = !(permission === 'rw'); const isReadOnly = !(permission === 'rw');
return ( return (
<div className="wiki2-main-panel"> <div className="wiki2-main-panel">
<div className='wiki2-main-panel-north'> <div className='wiki2-main-panel-north'>
<WikiTopNav <WikiTopNav
config={this.props.config} config={config}
currentPageId={this.props.currentPageId} currentPageId={this.props.currentPageId}
/> />
{username && {username &&
@@ -69,13 +87,14 @@ class MainPanel extends Component {
} }
{this.props.pathExist && this.props.isDataLoading && <Loading />} {this.props.pathExist && this.props.isDataLoading && <Loading />}
{isViewingFile && Utils.isSdocFile(this.props.path) && ( {isViewingFile && Utils.isSdocFile(this.props.path) && (
<SdocWikiViewer <div>
document={this.props.editorContent} <SdocWikiViewer
showOutline={false} document={this.props.editorContent}
showToolbar={false} docUuid={this.state.docUuid}
docUuid={this.state.docUuid} isWikiReadOnly={isReadOnly}
isWikiReadOnly={isReadOnly} topSlot={<Input className='sf-wiki-title' bsSize="lg" onBlur={this.handleRenameDocument} defaultValue={currentPageConfig.name} />}
/> />
</div>
)} )}
</div> </div>
</div> </div>

View File

@@ -28,6 +28,7 @@ const propTypes = {
saveWikiConfig: PropTypes.func.isRequired, saveWikiConfig: PropTypes.func.isRequired,
setCurrentPage: PropTypes.func.isRequired, setCurrentPage: PropTypes.func.isRequired,
currentPageId: PropTypes.string, currentPageId: PropTypes.string,
onUpdatePage: PropTypes.func.isRequired,
}; };
class SidePanel extends Component { class SidePanel extends Component {
@@ -101,19 +102,6 @@ class SidePanel extends Component {
this.props.saveWikiConfig(config, onSuccess, errorCallback); this.props.saveWikiConfig(config, onSuccess, errorCallback);
}; };
onUpdatePage = (pageId, newPage) => {
if (newPage.name === '') {
toaster.danger(gettext('Page name cannot be empty'));
return;
}
const { config } = this.props;
let pages = config.pages;
let currentPage = pages.find(page => page.id === pageId);
Object.assign(currentPage, newPage);
config.pages = pages;
this.props.saveWikiConfig(config);
};
movePage = ({ moved_view_id, target_view_id, source_view_folder_id, target_view_folder_id, move_position }) => { movePage = ({ moved_view_id, target_view_id, source_view_folder_id, target_view_folder_id, move_position }) => {
let config = deepCopy(this.props.config); let config = deepCopy(this.props.config);
let { navigation } = config; let { navigation } = config;
@@ -286,7 +274,7 @@ class SidePanel extends Component {
}; };
renderFolderView = () => { renderFolderView = () => {
const { config } = this.props; const { config, onUpdatePage } = this.props;
const { pages, navigation } = config; const { pages, navigation } = config;
return ( return (
<div className="wiki2-pages-container"> <div className="wiki2-pages-container">
@@ -296,7 +284,7 @@ class SidePanel extends Component {
views={pages} views={pages}
onToggleAddView={this.openAddPageDialog} onToggleAddView={this.openAddPageDialog}
onDeleteView={this.confirmDeletePage} onDeleteView={this.confirmDeletePage}
onUpdatePage={this.onUpdatePage} onUpdatePage={onUpdatePage}
onSelectView={this.props.setCurrentPage} onSelectView={this.props.setCurrentPage}
onMoveView={this.movePage} onMoveView={this.movePage}
movePageOut={this.movePageOut} movePageOut={this.movePageOut}

View File

@@ -43,4 +43,8 @@ const getIconURL = (repoId, fileName) => {
return serviceURL + '/lib/' + repoId + '/file/_Internal/Wiki/Icon/' + fileName + '?raw=1'; return serviceURL + '/lib/' + repoId + '/file/_Internal/Wiki/Icon/' + fileName + '?raw=1';
}; };
export { generatorBase64Code, generateUniqueId, isObjectNotEmpty, getIconURL }; const getCurrentPageConfig = (pages,pageId) => {
return pages.filter(page => page.id === pageId)[0]
}
export { generatorBase64Code, generateUniqueId, isObjectNotEmpty, getIconURL,getCurrentPageConfig };

View File

@@ -61,6 +61,13 @@ img[src=""] {
} }
} }
.main-panel-center .cur-view-content .sf-wiki-title {
border: none;
padding: 0 50px;
padding-left: 142px;
font-weight: bold;
font-size: 26pt;
}
/* reset article h1 */ /* reset article h1 */
.wiki2-main-panel .article h1 { .wiki2-main-panel .article h1 {
@@ -219,13 +226,17 @@ img[src=""] {
width: 100%; width: 100%;
} }
.sdoc-editor-container .sdoc-editor-content {
flex-direction: column;
}
.sdoc-editor-container .sdoc-editor-content .article { .sdoc-editor-container .sdoc-editor-content .article {
padding: 15px 142px 0px 142px;
width: 100%; width: 100%;
box-shadow: none; box-shadow: none;
border: none; border: none;
padding: 52px 142px 0;
} }
.sdoc-editor-container .sdoc-editor-content .sdoc-side-toolbar-container { .sdoc-editor-container .sdoc-editor-content .sdoc-side-toolbar-container {
left: 100px !important; left: 100px !important;
} }