diff --git a/frontend/src/components/common/event-bus.js b/frontend/src/components/common/event-bus.js index ceb58b75b52..6487d1cfe8f 100644 --- a/frontend/src/components/common/event-bus.js +++ b/frontend/src/components/common/event-bus.js @@ -25,4 +25,8 @@ class EventBus { } } +const eventBus = new EventBus(); + export default EventBus; + +export { eventBus }; diff --git a/frontend/src/components/search/wiki2-search-result.js b/frontend/src/components/search/wiki2-search-result.js index cb244ec9cfc..57fb76d5d8b 100644 --- a/frontend/src/components/search/wiki2-search-result.js +++ b/frontend/src/components/search/wiki2-search-result.js @@ -7,8 +7,9 @@ import { gettext } from '../../utils/constants'; 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 currentPageId = getCurrentPageId(); const isCurrentPage = currentPageId === page.id; return (
{page.icon ? : } {page.name} - {currentPageId === page.id ? + {isCurrentPage ? {gettext('Current page')} : } @@ -37,7 +38,7 @@ function Wiki2SearchResult({ result, currentPageId, setCurrentPage, resetToDefau Wiki2SearchResult.propTypes = { result: PropTypes.object.isRequired, - currentPageId: PropTypes.string.isRequired, + getCurrentPageId: PropTypes.func.isRequired, setCurrentPage: PropTypes.func.isRequired, resetToDefault: PropTypes.func.isRequired, setRef: PropTypes.func.isRequired, diff --git a/frontend/src/components/search/wiki2-search.css b/frontend/src/components/search/wiki2-search.css index e80a00643e9..5a164594e59 100644 --- a/frontend/src/components/search/wiki2-search.css +++ b/frontend/src/components/search/wiki2-search.css @@ -1,8 +1,9 @@ .wiki2-search { - margin: 10px 8px 10px; + margin: 10px 8px 0px; height: 32px; display: flex; align-items: center; + flex-shrink: 0; border-radius: 3px; } @@ -16,10 +17,6 @@ color: #666; } -.wiki2-search-input { - position: relative; -} - .wiki2-search-input .sf3-font-search { position: absolute; top: 0; diff --git a/frontend/src/components/search/wiki2-search.js b/frontend/src/components/search/wiki2-search.js index 3fbc308d31d..8c23893ff06 100644 --- a/frontend/src/components/search/wiki2-search.js +++ b/frontend/src/components/search/wiki2-search.js @@ -16,7 +16,7 @@ const isEnter = isHotkey('enter'); const isUp = isHotkey('up'); const isDown = isHotkey('down'); -function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) { +function Wiki2Search({ setCurrentPage, config, getCurrentPageId, wikiId }) { const [isModalOpen, setIsModalOpen] = useState(false); const [value, setValue] = useState(''); @@ -60,7 +60,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) { if (isResultGetted) { if (isEnter(e)) { const hightlightResult = results[highlightIndex]; - if (hightlightResult && hightlightResult.page.id !== currentPageId) { + if (hightlightResult && hightlightResult.page.id !== getCurrentPageId()) { setCurrentPage(hightlightResult.page.id); resetToDefault(); } @@ -75,7 +75,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) { } } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isResultGetted, value, results, highlightIndex, currentPageId]); + }, [isResultGetted, value, results, highlightIndex]); const onUp = useCallback((e, highlightIndex) => { e.preventDefault(); @@ -153,7 +153,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) { {isModalOpen && -
+
{ - this.setState({ closeSideBar: !this.state.closeSideBar }); + mobileCloseSidePanel = () => { + this.setState({ isSidePanelOpen: false }); }; - showPage = (pageId, filePath) => { + mobileOpenSidePanel = () => { + this.setState({ isSidePanelOpen: true }); + }; + + getCurrentPageId = () => { + return this.state.currentPageId; + }; + + updateSdocPage = (pageId, filePath) => { this.setState({ isDataLoading: true, }); @@ -204,11 +213,11 @@ class Wiki extends Component { }; setCurrentPage = (pageId, callback) => { - const { currentPageId, config } = this.state; - if (pageId === currentPageId) { + if (pageId === this.state.currentPageId) { callback && callback(); return; } + const { config } = this.state; const { pages } = config; const currentPage = PageUtils.getPageById(pages, pageId); if (!currentPage) { @@ -216,13 +225,18 @@ class Wiki extends Component { return; } const { path, id, name, docUuid } = currentPage; - if (path !== this.state.path) this.showPage(pageId, path); - this.onCloseSide(); + if (path !== this.state.path) { + this.updateSdocPage(pageId, path); + } + if (!Utils.isDesktop()) { + this.mobileCloseSidePanel(); + } this.setState({ currentPageId: pageId, path: path, }, () => { callback && callback(); + eventBus.dispatch('update-wiki-current-page'); }); this.cacheHistoryFiles(docUuid, name, id); this.updateDocumentTitle(name); @@ -256,16 +270,16 @@ class Wiki extends Component {
- + +
); diff --git a/frontend/src/pages/wiki2/main-panel.js b/frontend/src/pages/wiki2/main-panel.js index b1797f77f17..7edd93644e1 100644 --- a/frontend/src/pages/wiki2/main-panel.js +++ b/frontend/src/pages/wiki2/main-panel.js @@ -23,7 +23,7 @@ const propTypes = { isUpdateBySide: PropTypes.bool, onUpdatePage: PropTypes.func, onAddWikiPage: PropTypes.func, - onCloseSide: PropTypes.func.isRequired + mobileOpenSidePanel: PropTypes.func.isRequired }; class MainPanel extends Component { @@ -67,7 +67,13 @@ class MainPanel extends Component {
- + + { - this.setState({ 'isShowTrashDialog': !this.state.isShowTrashDialog }); + this.setState({ isShowTrashDialog: !this.state.isShowTrashDialog }); }; renderWikiNav = () => { @@ -124,7 +126,7 @@ class SidePanel extends Component { updateWikiConfig={this.props.updateWikiConfig} onAddNewPage={this.onAddNewPage} duplicatePage={this.duplicatePage} - currentPageId={this.props.currentPageId} + getCurrentPageId={this.props.getCurrentPageId} addPageInside={this.addPageInside} toggelTrashDialog={this.toggelTrashDialog} /> @@ -158,10 +160,10 @@ class SidePanel extends Component { }; render() { - const { isLoading, config, currentPageId } = this.props; + const { isLoading, config } = this.props; const isDesktop = Utils.isDesktop(); return ( -
+

{repoName}

{isDesktop && wikiPermission !== 'public' && @@ -181,7 +183,7 @@ class SidePanel extends Component {
diff --git a/frontend/src/pages/wiki2/wiki-nav/add-new-page-dialog.js b/frontend/src/pages/wiki2/wiki-nav/add-new-page-dialog.js index c2d71fcc894..c22d62a7e2c 100644 --- a/frontend/src/pages/wiki2/wiki-nav/add-new-page-dialog.js +++ b/frontend/src/pages/wiki2/wiki-nav/add-new-page-dialog.js @@ -13,7 +13,7 @@ const propTypes = { title: PropTypes.node, toggle: PropTypes.func.isRequired, onAddNewPage: PropTypes.func, - currentPageId: PropTypes.string, + getCurrentPageId: PropTypes.func.isRequired, }; @@ -71,7 +71,7 @@ class AddNewPageDialog extends React.Component { }; 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; this.props.onAddNewPage({ page_id: page_id, diff --git a/frontend/src/pages/wiki2/wiki-nav/pages/page-item.js b/frontend/src/pages/wiki2/wiki-nav/pages/page-item.js index 883d79190c5..4cc6fcc89f8 100644 --- a/frontend/src/pages/wiki2/wiki-nav/pages/page-item.js +++ b/frontend/src/pages/wiki2/wiki-nav/pages/page-item.js @@ -10,6 +10,7 @@ import AddNewPageDialog from '../add-new-page-dialog'; import Icon from '../../../../components/icon'; import DraggedPageItem from './dragged-page-item'; import CustomIcon from '../../custom-icon'; +import { eventBus } from '../../../../components/common/event-bus'; class PageItem extends Component { @@ -21,18 +22,30 @@ class PageItem extends Component { isShowDeleteDialog: false, isShowInsertPage: false, pageName: props.page.name || '', - isSelected: props.currentPageId === props.page.id, + isSelected: props.getCurrentPageId() === props.page.id, isMouseEnter: false, }; this.pageItemRef = React.createRef(); } + componentDidMount() { + this.unsubscribeEvent = eventBus.subscribe('update-wiki-current-page', this.updateSelected); + } + componentWillUnmount() { + this.unsubscribeEvent(); this.setState = () => { return; }; } + updateSelected = () => { + const isSelected = this.props.getCurrentPageId() === this.props.page.id; + if (isSelected !== this.state.isSelected) { + this.setState({ isSelected }); + } + }; + onMouseEnter = () => { this.setState({ isMouseEnter: true }); if (this.state.isSelected) return; @@ -130,7 +143,7 @@ class PageItem extends Component { updateWikiConfig={this.props.updateWikiConfig} pages={pages} pathStr={pathStr + '-' + page.id} - currentPageId={this.props.currentPageId} + getCurrentPageId={this.props.getCurrentPageId} addPageInside={this.props.addPageInside} getFoldState={this.props.getFoldState} toggleExpand={this.props.toggleExpand} @@ -257,7 +270,7 @@ class PageItem extends Component { {this.state.isShowInsertPage && @@ -302,7 +315,7 @@ PageItem.propTypes = { onMovePage: PropTypes.func, isOnlyOnePage: PropTypes.bool, pathStr: PropTypes.string, - currentPageId: PropTypes.string, + getCurrentPageId: PropTypes.func, addPageInside: PropTypes.func, getFoldState: PropTypes.func, toggleExpand: PropTypes.func, diff --git a/frontend/src/pages/wiki2/wiki-nav/wiki-nav.js b/frontend/src/pages/wiki2/wiki-nav/wiki-nav.js index 184aaa7ee22..2cdb7dc5e92 100644 --- a/frontend/src/pages/wiki2/wiki-nav/wiki-nav.js +++ b/frontend/src/pages/wiki2/wiki-nav/wiki-nav.js @@ -19,7 +19,7 @@ class WikiNav extends Component { onDeletePage: PropTypes.func, onMovePage: PropTypes.func, duplicatePage: PropTypes.func, - currentPageId: PropTypes.string, + getCurrentPageId: PropTypes.func, addPageInside: PropTypes.func, updateWikiConfig: PropTypes.func.isRequired, toggelTrashDialog: PropTypes.func.isRequired, @@ -83,7 +83,7 @@ class WikiNav extends Component { onMovePage={this.props.onMovePage} updateWikiConfig={this.props.updateWikiConfig} pathStr={page.id} - currentPageId={this.props.currentPageId} + getCurrentPageId={this.props.getCurrentPageId} addPageInside={this.props.addPageInside} getFoldState={this.getFoldState} toggleExpand={this.toggleExpand}