Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change wiki nav scroll when change page #7006

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/components/common/event-bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ class EventBus {
}
}

const eventBus = new EventBus();

export default EventBus;

export { eventBus };
7 changes: 4 additions & 3 deletions frontend/src/components/search/wiki2-search-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div
Expand All @@ -19,7 +20,7 @@ function Wiki2SearchResult({ result, currentPageId, setCurrentPage, resetToDefau
<div className='wiki2-search-result-top d-flex align-items-center'>
{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>
{currentPageId === page.id ?
{isCurrentPage ?
<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>
}
Expand All @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/search/wiki2-search.css
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -16,10 +17,6 @@
color: #666;
}

.wiki2-search-input {
position: relative;
}

.wiki2-search-input .sf3-font-search {
position: absolute;
top: 0;
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/search/wiki2-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand Down Expand Up @@ -153,7 +153,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) {
{isModalOpen &&
<Modal className="wiki2-search-modal" isOpen={isModalOpen} toggle={resetToDefault} autoFocus={false} size='lg'>
<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>
<Input
type="text"
Expand All @@ -179,7 +179,7 @@ function Wiki2Search({ setCurrentPage, config, currentPageId, wikiId }) {
<Wiki2SearchResult
result={result}
key={result._id}
currentPageId={currentPageId}
getCurrentPageId={this.props.getCurrentPageId}
setCurrentPage={setCurrentPage}
resetToDefault={resetToDefault}
isHighlight={highlightIndex === index}
Expand All @@ -199,7 +199,7 @@ Wiki2Search.propTypes = {
wikiId: PropTypes.string.isRequired,
setCurrentPage: PropTypes.func.isRequired,
config: PropTypes.object.isRequired,
currentPageId: PropTypes.string.isRequired,
getCurrentPageId: PropTypes.func.isRequired,
};

export default Wiki2Search;
2 changes: 2 additions & 0 deletions frontend/src/pages/wiki2/css/wiki-nav.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
overflow: auto;
user-select: none;
max-height: 100%;
margin-right: -8px;
padding-right: 8px;
}

.wiki-nav .can-drop::after,
Expand Down
46 changes: 33 additions & 13 deletions frontend/src/pages/wiki2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MainPanel from './main-panel';
import PageUtils from './wiki-nav/page-utils';
import LocalStorage from '../../utils/local-storage-utils';
import { DEFAULT_PAGE_NAME } from './constant';
import { eventBus } from '../../components/common/event-bus';

import '../../css/layout.css';
import '../../css/side-panel.css';
Expand All @@ -28,7 +29,7 @@ class Wiki extends Component {
this.state = {
path: '',
pathExist: true,
closeSideBar: false,
isSidePanelOpen: false,
isDataLoading: false,
editorContent: {},
permission: '',
Expand All @@ -45,7 +46,7 @@ class Wiki extends Component {

UNSAFE_componentWillMount() {
if (!Utils.isDesktop()) {
this.setState({ closeSideBar: true });
this.setState({ isSidePanelOpen: true });
}
}

Expand Down Expand Up @@ -142,11 +143,19 @@ class Wiki extends Component {
});
};

onCloseSide = () => {
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,
});
Expand Down Expand Up @@ -204,25 +213,30 @@ 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) {
callback && callback();
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);
Expand Down Expand Up @@ -256,16 +270,16 @@ class Wiki extends Component {
<div id="main" className="wiki-main">
<SidePanel
isLoading={this.state.isConfigLoading}
closeSideBar={this.state.closeSideBar}
isSidePanelOpen={this.state.isSidePanelOpen}
config={this.state.config}
updateWikiConfig={this.updateWikiConfig}
getWikiConfig={this.getWikiConfig}
setCurrentPage={this.setCurrentPage}
currentPageId={this.state.currentPageId}
getCurrentPageId={this.getCurrentPageId}
onUpdatePage={this.onUpdatePage}
/>
<MainPanel
onCloseSide={this.onCloseSide}
mobileOpenSidePanel={this.mobileOpenSidePanel}
path={this.state.path}
config={this.state.config}
currentPageId={this.state.currentPageId}
Expand All @@ -280,7 +294,13 @@ class Wiki extends Component {
isUpdateBySide={this.state.isUpdateBySide}
/>
<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>
</div>
);
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/pages/wiki2/main-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -67,7 +67,13 @@ class MainPanel extends Component {
<div className='wiki2-main-panel-north'>
<div className="d-flex align-items-center flex-fill o-hidden">
<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
config={config}
currentPageId={this.props.currentPageId}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/wiki2/side-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
flex: 1;
overflow: hidden;
padding: 8px;
padding-top: 10px;
padding-top: 20px;
}

.wiki2-side-panel .wiki2-side-nav .wiki2-pages-container:hover {
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/pages/wiki2/side-panel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import deepCopy from 'deep-copy';
import classNames from 'classnames';
import { UncontrolledTooltip } from 'reactstrap';
import { gettext, isWiki2, wikiId, wikiPermission } from '../../utils/constants';
import toaster from '../../components/toast';
Expand All @@ -21,17 +22,18 @@ import './side-panel.css';
const { repoName } = window.wiki.config;

const propTypes = {
closeSideBar: PropTypes.bool.isRequired,
isSidePanelOpen: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
config: PropTypes.object.isRequired,
updateWikiConfig: PropTypes.func.isRequired,
getWikiConfig: PropTypes.func.isRequired,
setCurrentPage: PropTypes.func.isRequired,
currentPageId: PropTypes.string,
getCurrentPageId: PropTypes.func.isRequired,
onUpdatePage: PropTypes.func.isRequired,
};

class SidePanel extends Component {
class SidePanel extends PureComponent {

constructor(props) {
super(props);
this.state = {
Expand Down Expand Up @@ -104,7 +106,7 @@ class SidePanel extends Component {
};

toggelTrashDialog = () => {
this.setState({ 'isShowTrashDialog': !this.state.isShowTrashDialog });
this.setState({ isShowTrashDialog: !this.state.isShowTrashDialog });
};

renderWikiNav = () => {
Expand All @@ -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}
/>
Expand Down Expand Up @@ -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 (
<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">
<h4 className="text-truncate ml-0 mb-0" title={repoName}>{repoName}</h4>
{isDesktop && wikiPermission !== 'public' &&
Expand All @@ -181,7 +183,7 @@ class SidePanel extends Component {
<Wiki2Search
wikiId={wikiId}
config={config}
currentPageId={currentPageId}
getCurrentPageId={this.props.getCurrentPageId}
setCurrentPage={this.props.setCurrentPage}
/>
<div className="wiki2-side-nav">
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/wiki2/wiki-nav/add-new-page-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const propTypes = {
title: PropTypes.node,
toggle: PropTypes.func.isRequired,
onAddNewPage: PropTypes.func,
currentPageId: PropTypes.string,
getCurrentPageId: PropTypes.func.isRequired,
};


Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading