mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 02:48:51 +00:00
Change wiki nav scroll when change page (#7006)
* 01 fix wiki nav scroll bar position * 02 fix search Wiki input height when too much pages * 03 fix nav scroll when click another page * 04 fix scroll when too much pages
This commit is contained in:
@@ -25,4 +25,8 @@ class EventBus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const eventBus = new EventBus();
|
||||||
|
|
||||||
export default EventBus;
|
export default EventBus;
|
||||||
|
|
||||||
|
export { eventBus };
|
||||||
|
@@ -7,8 +7,9 @@ import { gettext } from '../../utils/constants';
|
|||||||
|
|
||||||
import './wiki2-search-result.css';
|
import './wiki2-search-result.css';
|
||||||
|
|
||||||
function Wiki2SearchResult({ result, currentPageId, setCurrentPage, resetToDefault, setRef, isHighlight }) {
|
function Wiki2SearchResult({ result, getCurrentPageId, setCurrentPage, resetToDefault, setRef, isHighlight }) {
|
||||||
const { content, page } = result;
|
const { content, page } = result;
|
||||||
|
const currentPageId = getCurrentPageId();
|
||||||
const isCurrentPage = currentPageId === page.id;
|
const isCurrentPage = currentPageId === page.id;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -19,7 +20,7 @@ function Wiki2SearchResult({ result, currentPageId, setCurrentPage, resetToDefau
|
|||||||
<div className='wiki2-search-result-top d-flex align-items-center'>
|
<div className='wiki2-search-result-top d-flex align-items-center'>
|
||||||
{page.icon ? <CustomIcon icon={page.icon} /> : <NavItemIcon symbol={'file'} disable={true} />}
|
{page.icon ? <CustomIcon icon={page.icon} /> : <NavItemIcon symbol={'file'} disable={true} />}
|
||||||
<span className='wiki2-search-result-page-name text-truncate' title={page.name} style={isCurrentPage ? { width: 'auto' } : { width: 700 }}>{page.name}</span>
|
<span className='wiki2-search-result-page-name text-truncate' title={page.name} style={isCurrentPage ? { width: 'auto' } : { width: 700 }}>{page.name}</span>
|
||||||
{currentPageId === page.id ?
|
{isCurrentPage ?
|
||||||
<span className='wiki2-search-result-current'>{gettext('Current page')}</span> :
|
<span className='wiki2-search-result-current'>{gettext('Current page')}</span> :
|
||||||
<span className='wiki2-search-result-enter sf3-font sf3-font-enter' style={isHighlight ? { opacity: 1 } : {}}></span>
|
<span className='wiki2-search-result-enter sf3-font sf3-font-enter' style={isHighlight ? { opacity: 1 } : {}}></span>
|
||||||
}
|
}
|
||||||
@@ -37,7 +38,7 @@ function Wiki2SearchResult({ result, currentPageId, setCurrentPage, resetToDefau
|
|||||||
|
|
||||||
Wiki2SearchResult.propTypes = {
|
Wiki2SearchResult.propTypes = {
|
||||||
result: PropTypes.object.isRequired,
|
result: PropTypes.object.isRequired,
|
||||||
currentPageId: PropTypes.string.isRequired,
|
getCurrentPageId: PropTypes.func.isRequired,
|
||||||
setCurrentPage: PropTypes.func.isRequired,
|
setCurrentPage: PropTypes.func.isRequired,
|
||||||
resetToDefault: PropTypes.func.isRequired,
|
resetToDefault: PropTypes.func.isRequired,
|
||||||
setRef: PropTypes.func.isRequired,
|
setRef: PropTypes.func.isRequired,
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
.wiki2-search {
|
.wiki2-search {
|
||||||
margin: 10px 8px 10px;
|
margin: 10px 8px 0px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
flex-shrink: 0;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,10 +17,6 @@
|
|||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wiki2-search-input {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wiki2-search-input .sf3-font-search {
|
.wiki2-search-input .sf3-font-search {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@@ -16,7 +16,7 @@ const isEnter = isHotkey('enter');
|
|||||||
const isUp = isHotkey('up');
|
const isUp = isHotkey('up');
|
||||||
const isDown = isHotkey('down');
|
const isDown = isHotkey('down');
|
||||||
|
|
||||||
function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) {
|
function Wiki2Search({ setCurrentPage, config, getCurrentPageId, wikiId }) {
|
||||||
|
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [value, setValue] = useState('');
|
const [value, setValue] = useState('');
|
||||||
@@ -60,7 +60,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) {
|
|||||||
if (isResultGetted) {
|
if (isResultGetted) {
|
||||||
if (isEnter(e)) {
|
if (isEnter(e)) {
|
||||||
const hightlightResult = results[highlightIndex];
|
const hightlightResult = results[highlightIndex];
|
||||||
if (hightlightResult && hightlightResult.page.id !== currentPageId) {
|
if (hightlightResult && hightlightResult.page.id !== getCurrentPageId()) {
|
||||||
setCurrentPage(hightlightResult.page.id);
|
setCurrentPage(hightlightResult.page.id);
|
||||||
resetToDefault();
|
resetToDefault();
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [isResultGetted, value, results, highlightIndex, currentPageId]);
|
}, [isResultGetted, value, results, highlightIndex]);
|
||||||
|
|
||||||
const onUp = useCallback((e, highlightIndex) => {
|
const onUp = useCallback((e, highlightIndex) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -153,7 +153,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) {
|
|||||||
{isModalOpen &&
|
{isModalOpen &&
|
||||||
<Modal className="wiki2-search-modal" isOpen={isModalOpen} toggle={resetToDefault} autoFocus={false} size='lg'>
|
<Modal className="wiki2-search-modal" isOpen={isModalOpen} toggle={resetToDefault} autoFocus={false} size='lg'>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<div className="wiki2-search-input mb-4">
|
<div className="wiki2-search-input mb-4 position-relative">
|
||||||
<i className="sf3-font sf3-font-search"></i>
|
<i className="sf3-font sf3-font-search"></i>
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -179,7 +179,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) {
|
|||||||
<Wiki2SearchResult
|
<Wiki2SearchResult
|
||||||
result={result}
|
result={result}
|
||||||
key={result._id}
|
key={result._id}
|
||||||
currentPageId={currentPageId}
|
getCurrentPageId={this.props.getCurrentPageId}
|
||||||
setCurrentPage={setCurrentPage}
|
setCurrentPage={setCurrentPage}
|
||||||
resetToDefault={resetToDefault}
|
resetToDefault={resetToDefault}
|
||||||
isHighlight={highlightIndex === index}
|
isHighlight={highlightIndex === index}
|
||||||
@@ -199,7 +199,7 @@ Wiki2Search.propTypes = {
|
|||||||
wikiId: PropTypes.string.isRequired,
|
wikiId: PropTypes.string.isRequired,
|
||||||
setCurrentPage: PropTypes.func.isRequired,
|
setCurrentPage: PropTypes.func.isRequired,
|
||||||
config: PropTypes.object.isRequired,
|
config: PropTypes.object.isRequired,
|
||||||
currentPageId: PropTypes.string.isRequired,
|
getCurrentPageId: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Wiki2Search;
|
export default Wiki2Search;
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
|
margin-right: -8px;
|
||||||
|
padding-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wiki-nav .can-drop::after,
|
.wiki-nav .can-drop::after,
|
||||||
|
@@ -13,6 +13,7 @@ import MainPanel from './main-panel';
|
|||||||
import PageUtils from './wiki-nav/page-utils';
|
import PageUtils from './wiki-nav/page-utils';
|
||||||
import LocalStorage from '../../utils/local-storage-utils';
|
import LocalStorage from '../../utils/local-storage-utils';
|
||||||
import { DEFAULT_PAGE_NAME } from './constant';
|
import { DEFAULT_PAGE_NAME } from './constant';
|
||||||
|
import { eventBus } from '../../components/common/event-bus';
|
||||||
|
|
||||||
import '../../css/layout.css';
|
import '../../css/layout.css';
|
||||||
import '../../css/side-panel.css';
|
import '../../css/side-panel.css';
|
||||||
@@ -28,7 +29,7 @@ class Wiki extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
path: '',
|
path: '',
|
||||||
pathExist: true,
|
pathExist: true,
|
||||||
closeSideBar: false,
|
isSidePanelOpen: false,
|
||||||
isDataLoading: false,
|
isDataLoading: false,
|
||||||
editorContent: {},
|
editorContent: {},
|
||||||
permission: '',
|
permission: '',
|
||||||
@@ -45,7 +46,7 @@ class Wiki extends Component {
|
|||||||
|
|
||||||
UNSAFE_componentWillMount() {
|
UNSAFE_componentWillMount() {
|
||||||
if (!Utils.isDesktop()) {
|
if (!Utils.isDesktop()) {
|
||||||
this.setState({ closeSideBar: true });
|
this.setState({ isSidePanelOpen: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,11 +143,19 @@ class Wiki extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onCloseSide = () => {
|
mobileCloseSidePanel = () => {
|
||||||
this.setState({ closeSideBar: !this.state.closeSideBar });
|
this.setState({ isSidePanelOpen: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
showPage = (pageId, filePath) => {
|
mobileOpenSidePanel = () => {
|
||||||
|
this.setState({ isSidePanelOpen: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
getCurrentPageId = () => {
|
||||||
|
return this.state.currentPageId;
|
||||||
|
};
|
||||||
|
|
||||||
|
updateSdocPage = (pageId, filePath) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isDataLoading: true,
|
isDataLoading: true,
|
||||||
});
|
});
|
||||||
@@ -204,11 +213,11 @@ class Wiki extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
setCurrentPage = (pageId, callback) => {
|
setCurrentPage = (pageId, callback) => {
|
||||||
const { currentPageId, config } = this.state;
|
if (pageId === this.state.currentPageId) {
|
||||||
if (pageId === currentPageId) {
|
|
||||||
callback && callback();
|
callback && callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const { config } = this.state;
|
||||||
const { pages } = config;
|
const { pages } = config;
|
||||||
const currentPage = PageUtils.getPageById(pages, pageId);
|
const currentPage = PageUtils.getPageById(pages, pageId);
|
||||||
if (!currentPage) {
|
if (!currentPage) {
|
||||||
@@ -216,13 +225,18 @@ class Wiki extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { path, id, name, docUuid } = currentPage;
|
const { path, id, name, docUuid } = currentPage;
|
||||||
if (path !== this.state.path) this.showPage(pageId, path);
|
if (path !== this.state.path) {
|
||||||
this.onCloseSide();
|
this.updateSdocPage(pageId, path);
|
||||||
|
}
|
||||||
|
if (!Utils.isDesktop()) {
|
||||||
|
this.mobileCloseSidePanel();
|
||||||
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
currentPageId: pageId,
|
currentPageId: pageId,
|
||||||
path: path,
|
path: path,
|
||||||
}, () => {
|
}, () => {
|
||||||
callback && callback();
|
callback && callback();
|
||||||
|
eventBus.dispatch('update-wiki-current-page');
|
||||||
});
|
});
|
||||||
this.cacheHistoryFiles(docUuid, name, id);
|
this.cacheHistoryFiles(docUuid, name, id);
|
||||||
this.updateDocumentTitle(name);
|
this.updateDocumentTitle(name);
|
||||||
@@ -256,16 +270,16 @@ class Wiki extends Component {
|
|||||||
<div id="main" className="wiki-main">
|
<div id="main" className="wiki-main">
|
||||||
<SidePanel
|
<SidePanel
|
||||||
isLoading={this.state.isConfigLoading}
|
isLoading={this.state.isConfigLoading}
|
||||||
closeSideBar={this.state.closeSideBar}
|
isSidePanelOpen={this.state.isSidePanelOpen}
|
||||||
config={this.state.config}
|
config={this.state.config}
|
||||||
updateWikiConfig={this.updateWikiConfig}
|
updateWikiConfig={this.updateWikiConfig}
|
||||||
getWikiConfig={this.getWikiConfig}
|
getWikiConfig={this.getWikiConfig}
|
||||||
setCurrentPage={this.setCurrentPage}
|
setCurrentPage={this.setCurrentPage}
|
||||||
currentPageId={this.state.currentPageId}
|
getCurrentPageId={this.getCurrentPageId}
|
||||||
onUpdatePage={this.onUpdatePage}
|
onUpdatePage={this.onUpdatePage}
|
||||||
/>
|
/>
|
||||||
<MainPanel
|
<MainPanel
|
||||||
onCloseSide={this.onCloseSide}
|
mobileOpenSidePanel={this.mobileOpenSidePanel}
|
||||||
path={this.state.path}
|
path={this.state.path}
|
||||||
config={this.state.config}
|
config={this.state.config}
|
||||||
currentPageId={this.state.currentPageId}
|
currentPageId={this.state.currentPageId}
|
||||||
@@ -280,7 +294,13 @@ class Wiki extends Component {
|
|||||||
isUpdateBySide={this.state.isUpdateBySide}
|
isUpdateBySide={this.state.isUpdateBySide}
|
||||||
/>
|
/>
|
||||||
<MediaQuery query="(max-width: 767.8px)">
|
<MediaQuery query="(max-width: 767.8px)">
|
||||||
<Modal zIndex="1030" isOpen={!this.state.closeSideBar} toggle={this.onCloseSide} contentClassName="d-none"></Modal>
|
<Modal
|
||||||
|
zIndex="1030"
|
||||||
|
isOpen={!this.state.isSidePanelOpen}
|
||||||
|
toggle={this.mobileCloseSidePanel}
|
||||||
|
contentClassName="d-none"
|
||||||
|
>
|
||||||
|
</Modal>
|
||||||
</MediaQuery>
|
</MediaQuery>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@@ -23,7 +23,7 @@ const propTypes = {
|
|||||||
isUpdateBySide: PropTypes.bool,
|
isUpdateBySide: PropTypes.bool,
|
||||||
onUpdatePage: PropTypes.func,
|
onUpdatePage: PropTypes.func,
|
||||||
onAddWikiPage: PropTypes.func,
|
onAddWikiPage: PropTypes.func,
|
||||||
onCloseSide: PropTypes.func.isRequired
|
mobileOpenSidePanel: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainPanel extends Component {
|
class MainPanel extends Component {
|
||||||
@@ -67,7 +67,13 @@ class MainPanel extends Component {
|
|||||||
<div className='wiki2-main-panel-north'>
|
<div className='wiki2-main-panel-north'>
|
||||||
<div className="d-flex align-items-center flex-fill o-hidden">
|
<div className="d-flex align-items-center flex-fill o-hidden">
|
||||||
<div className='wiki2-main-panel-north-content'>
|
<div className='wiki2-main-panel-north-content'>
|
||||||
<i role="button" aria-label={gettext('Side Nav Menu')} onClick={this.props.onCloseSide} className="sf2-icon-menu side-nav-toggle d-md-none"></i>
|
<i
|
||||||
|
role="button"
|
||||||
|
aria-label={gettext('Side Nav Menu')}
|
||||||
|
onClick={this.props.mobileOpenSidePanel}
|
||||||
|
className="sf2-icon-menu side-nav-toggle d-md-none"
|
||||||
|
>
|
||||||
|
</i>
|
||||||
<WikiTopNav
|
<WikiTopNav
|
||||||
config={config}
|
config={config}
|
||||||
currentPageId={this.props.currentPageId}
|
currentPageId={this.props.currentPageId}
|
||||||
|
@@ -55,7 +55,7 @@
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
padding-top: 10px;
|
padding-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wiki2-side-panel .wiki2-side-nav .wiki2-pages-container:hover {
|
.wiki2-side-panel .wiki2-side-nav .wiki2-pages-container:hover {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import deepCopy from 'deep-copy';
|
import deepCopy from 'deep-copy';
|
||||||
|
import classNames from 'classnames';
|
||||||
import { UncontrolledTooltip } from 'reactstrap';
|
import { UncontrolledTooltip } from 'reactstrap';
|
||||||
import { gettext, isWiki2, wikiId, wikiPermission } from '../../utils/constants';
|
import { gettext, isWiki2, wikiId, wikiPermission } from '../../utils/constants';
|
||||||
import toaster from '../../components/toast';
|
import toaster from '../../components/toast';
|
||||||
@@ -21,17 +22,18 @@ import './side-panel.css';
|
|||||||
const { repoName } = window.wiki.config;
|
const { repoName } = window.wiki.config;
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
closeSideBar: PropTypes.bool.isRequired,
|
isSidePanelOpen: PropTypes.bool.isRequired,
|
||||||
isLoading: PropTypes.bool.isRequired,
|
isLoading: PropTypes.bool.isRequired,
|
||||||
config: PropTypes.object.isRequired,
|
config: PropTypes.object.isRequired,
|
||||||
updateWikiConfig: PropTypes.func.isRequired,
|
updateWikiConfig: PropTypes.func.isRequired,
|
||||||
getWikiConfig: PropTypes.func.isRequired,
|
getWikiConfig: PropTypes.func.isRequired,
|
||||||
setCurrentPage: PropTypes.func.isRequired,
|
setCurrentPage: PropTypes.func.isRequired,
|
||||||
currentPageId: PropTypes.string,
|
getCurrentPageId: PropTypes.func.isRequired,
|
||||||
onUpdatePage: PropTypes.func.isRequired,
|
onUpdatePage: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
class SidePanel extends Component {
|
class SidePanel extends PureComponent {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -104,7 +106,7 @@ class SidePanel extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
toggelTrashDialog = () => {
|
toggelTrashDialog = () => {
|
||||||
this.setState({ 'isShowTrashDialog': !this.state.isShowTrashDialog });
|
this.setState({ isShowTrashDialog: !this.state.isShowTrashDialog });
|
||||||
};
|
};
|
||||||
|
|
||||||
renderWikiNav = () => {
|
renderWikiNav = () => {
|
||||||
@@ -124,7 +126,7 @@ class SidePanel extends Component {
|
|||||||
updateWikiConfig={this.props.updateWikiConfig}
|
updateWikiConfig={this.props.updateWikiConfig}
|
||||||
onAddNewPage={this.onAddNewPage}
|
onAddNewPage={this.onAddNewPage}
|
||||||
duplicatePage={this.duplicatePage}
|
duplicatePage={this.duplicatePage}
|
||||||
currentPageId={this.props.currentPageId}
|
getCurrentPageId={this.props.getCurrentPageId}
|
||||||
addPageInside={this.addPageInside}
|
addPageInside={this.addPageInside}
|
||||||
toggelTrashDialog={this.toggelTrashDialog}
|
toggelTrashDialog={this.toggelTrashDialog}
|
||||||
/>
|
/>
|
||||||
@@ -158,10 +160,10 @@ class SidePanel extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isLoading, config, currentPageId } = this.props;
|
const { isLoading, config } = this.props;
|
||||||
const isDesktop = Utils.isDesktop();
|
const isDesktop = Utils.isDesktop();
|
||||||
return (
|
return (
|
||||||
<div className={`wiki2-side-panel${this.props.closeSideBar ? '' : ' left-zero'}`}>
|
<div className={classNames('wiki2-side-panel', { 'left-zero': this.props.isSidePanelOpen })}>
|
||||||
<div className="wiki2-side-panel-top">
|
<div className="wiki2-side-panel-top">
|
||||||
<h4 className="text-truncate ml-0 mb-0" title={repoName}>{repoName}</h4>
|
<h4 className="text-truncate ml-0 mb-0" title={repoName}>{repoName}</h4>
|
||||||
{isDesktop && wikiPermission !== 'public' &&
|
{isDesktop && wikiPermission !== 'public' &&
|
||||||
@@ -181,7 +183,7 @@ class SidePanel extends Component {
|
|||||||
<Wiki2Search
|
<Wiki2Search
|
||||||
wikiId={wikiId}
|
wikiId={wikiId}
|
||||||
config={config}
|
config={config}
|
||||||
currentPageId={currentPageId}
|
getCurrentPageId={this.props.getCurrentPageId}
|
||||||
setCurrentPage={this.props.setCurrentPage}
|
setCurrentPage={this.props.setCurrentPage}
|
||||||
/>
|
/>
|
||||||
<div className="wiki2-side-nav">
|
<div className="wiki2-side-nav">
|
||||||
|
@@ -13,7 +13,7 @@ const propTypes = {
|
|||||||
title: PropTypes.node,
|
title: PropTypes.node,
|
||||||
toggle: PropTypes.func.isRequired,
|
toggle: PropTypes.func.isRequired,
|
||||||
onAddNewPage: PropTypes.func,
|
onAddNewPage: PropTypes.func,
|
||||||
currentPageId: PropTypes.string,
|
getCurrentPageId: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ class AddNewPageDialog extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
createPage = (pageName) => {
|
createPage = (pageName) => {
|
||||||
wikiAPI.createWiki2Page(wikiId, pageName, this.props.currentPageId).then(res => {
|
wikiAPI.createWiki2Page(wikiId, pageName, this.props.getCurrentPageId()).then(res => {
|
||||||
const { page_id, obj_name, doc_uuid, parent_dir } = res.data.file_info;
|
const { page_id, obj_name, doc_uuid, parent_dir } = res.data.file_info;
|
||||||
this.props.onAddNewPage({
|
this.props.onAddNewPage({
|
||||||
page_id: page_id,
|
page_id: page_id,
|
||||||
|
@@ -10,6 +10,7 @@ import AddNewPageDialog from '../add-new-page-dialog';
|
|||||||
import Icon from '../../../../components/icon';
|
import Icon from '../../../../components/icon';
|
||||||
import DraggedPageItem from './dragged-page-item';
|
import DraggedPageItem from './dragged-page-item';
|
||||||
import CustomIcon from '../../custom-icon';
|
import CustomIcon from '../../custom-icon';
|
||||||
|
import { eventBus } from '../../../../components/common/event-bus';
|
||||||
|
|
||||||
class PageItem extends Component {
|
class PageItem extends Component {
|
||||||
|
|
||||||
@@ -21,18 +22,30 @@ class PageItem extends Component {
|
|||||||
isShowDeleteDialog: false,
|
isShowDeleteDialog: false,
|
||||||
isShowInsertPage: false,
|
isShowInsertPage: false,
|
||||||
pageName: props.page.name || '',
|
pageName: props.page.name || '',
|
||||||
isSelected: props.currentPageId === props.page.id,
|
isSelected: props.getCurrentPageId() === props.page.id,
|
||||||
isMouseEnter: false,
|
isMouseEnter: false,
|
||||||
};
|
};
|
||||||
this.pageItemRef = React.createRef();
|
this.pageItemRef = React.createRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.unsubscribeEvent = eventBus.subscribe('update-wiki-current-page', this.updateSelected);
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
this.unsubscribeEvent();
|
||||||
this.setState = () => {
|
this.setState = () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSelected = () => {
|
||||||
|
const isSelected = this.props.getCurrentPageId() === this.props.page.id;
|
||||||
|
if (isSelected !== this.state.isSelected) {
|
||||||
|
this.setState({ isSelected });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
onMouseEnter = () => {
|
onMouseEnter = () => {
|
||||||
this.setState({ isMouseEnter: true });
|
this.setState({ isMouseEnter: true });
|
||||||
if (this.state.isSelected) return;
|
if (this.state.isSelected) return;
|
||||||
@@ -130,7 +143,7 @@ class PageItem extends Component {
|
|||||||
updateWikiConfig={this.props.updateWikiConfig}
|
updateWikiConfig={this.props.updateWikiConfig}
|
||||||
pages={pages}
|
pages={pages}
|
||||||
pathStr={pathStr + '-' + page.id}
|
pathStr={pathStr + '-' + page.id}
|
||||||
currentPageId={this.props.currentPageId}
|
getCurrentPageId={this.props.getCurrentPageId}
|
||||||
addPageInside={this.props.addPageInside}
|
addPageInside={this.props.addPageInside}
|
||||||
getFoldState={this.props.getFoldState}
|
getFoldState={this.props.getFoldState}
|
||||||
toggleExpand={this.props.toggleExpand}
|
toggleExpand={this.props.toggleExpand}
|
||||||
@@ -257,7 +270,7 @@ class PageItem extends Component {
|
|||||||
{this.state.isShowInsertPage &&
|
{this.state.isShowInsertPage &&
|
||||||
<AddNewPageDialog
|
<AddNewPageDialog
|
||||||
toggle={this.toggleInsertPage}
|
toggle={this.toggleInsertPage}
|
||||||
currentPageId={this.props.page.id}
|
getCurrentPageId={this.props.getCurrentPageId}
|
||||||
onAddNewPage={this.onAddNewPage}
|
onAddNewPage={this.onAddNewPage}
|
||||||
title={gettext('Add page inside')}
|
title={gettext('Add page inside')}
|
||||||
/>
|
/>
|
||||||
@@ -302,7 +315,7 @@ PageItem.propTypes = {
|
|||||||
onMovePage: PropTypes.func,
|
onMovePage: PropTypes.func,
|
||||||
isOnlyOnePage: PropTypes.bool,
|
isOnlyOnePage: PropTypes.bool,
|
||||||
pathStr: PropTypes.string,
|
pathStr: PropTypes.string,
|
||||||
currentPageId: PropTypes.string,
|
getCurrentPageId: PropTypes.func,
|
||||||
addPageInside: PropTypes.func,
|
addPageInside: PropTypes.func,
|
||||||
getFoldState: PropTypes.func,
|
getFoldState: PropTypes.func,
|
||||||
toggleExpand: PropTypes.func,
|
toggleExpand: PropTypes.func,
|
||||||
|
@@ -19,7 +19,7 @@ class WikiNav extends Component {
|
|||||||
onDeletePage: PropTypes.func,
|
onDeletePage: PropTypes.func,
|
||||||
onMovePage: PropTypes.func,
|
onMovePage: PropTypes.func,
|
||||||
duplicatePage: PropTypes.func,
|
duplicatePage: PropTypes.func,
|
||||||
currentPageId: PropTypes.string,
|
getCurrentPageId: PropTypes.func,
|
||||||
addPageInside: PropTypes.func,
|
addPageInside: PropTypes.func,
|
||||||
updateWikiConfig: PropTypes.func.isRequired,
|
updateWikiConfig: PropTypes.func.isRequired,
|
||||||
toggelTrashDialog: PropTypes.func.isRequired,
|
toggelTrashDialog: PropTypes.func.isRequired,
|
||||||
@@ -83,7 +83,7 @@ class WikiNav extends Component {
|
|||||||
onMovePage={this.props.onMovePage}
|
onMovePage={this.props.onMovePage}
|
||||||
updateWikiConfig={this.props.updateWikiConfig}
|
updateWikiConfig={this.props.updateWikiConfig}
|
||||||
pathStr={page.id}
|
pathStr={page.id}
|
||||||
currentPageId={this.props.currentPageId}
|
getCurrentPageId={this.props.getCurrentPageId}
|
||||||
addPageInside={this.props.addPageInside}
|
addPageInside={this.props.addPageInside}
|
||||||
getFoldState={this.getFoldState}
|
getFoldState={this.getFoldState}
|
||||||
toggleExpand={this.toggleExpand}
|
toggleExpand={this.toggleExpand}
|
||||||
|
Reference in New Issue
Block a user