import React from 'react';
import PropTypes from 'prop-types';
import { withUnstatedContainers } from '../UnstatedUtils';
import AppContainer from '~/client/services/AppContainer';
import NavigationContainer from '~/client/services/NavigationContainer';
import PageContainer from '~/client/services/PageContainer';
import PagePathNav from './PagePathNav';
import TagLabels from '../Page/TagLabels';
import SubnavButtons from './SubNavButtons';
import PageEditorModeManager from './PageEditorModeManager';
import AuthorInfo from './AuthorInfo';
import DrawerToggler from './DrawerToggler';
const GrowiSubNavigation = (props) => {
const {
appContainer,
navigationContainer,
isCompactMode,
isSearchPageMode,
} = props;
const { isDrawerMode, editorMode, isDeviceSmallerThanMd } = navigationContainer.state;
let {
isPageExist, isAbleToShowTagLabel, isAbleToShowPageEditorModeManager, isAbleToShowPageAuthors,
} = false;
let {
pageId,
path,
} = props;
if (props.pageContainer != null) {
({
pageId,
path,
} = props.pageContainer.state);
isPageExist = props.pageContainer.isPageExist;
isAbleToShowTagLabel = props.pageContainer.isAbleToShowTagLabel;
isAbleToShowPageEditorModeManager = props.pageContainer.isAbleToShowPageEditorModeManager;
isAbleToShowPageAuthors = props.pageContainer.isAbleToShowPageAuthors;
}
const { isGuestUser } = appContainer;
const isEditorMode = editorMode !== 'view';
// Tags cannot be edited while the new page and editorMode is view
const isTagLabelHidden = (editorMode !== 'edit' && !isPageExist);
function onPageEditorModeButtonClicked(viewType) {
navigationContainer.setEditorMode(viewType);
}
return (
{/* Left side */}
{ isDrawerMode && (
) }
{/* TODO : display tags when this component is used in SearchResultContent too.
For that, refactor TagLabels such that it can be used while not depending on pageContainer
TASK: #80623 https://estoc.weseek.co.jp/redmine/issues/80623
*/}
{ isAbleToShowTagLabel && !isCompactMode && !isTagLabelHidden && (
) }
{/* Right side */}
{/* TODO: refactor SubNavButtons in a way that it can be used independently from pageContainer
TASK : #80481 https://estoc.weseek.co.jp/redmine/issues/80481
*/}
{isAbleToShowPageEditorModeManager && !isSearchPageMode && (
)}
{/* Page Authors */}
{ (isAbleToShowPageAuthors && !isCompactMode && isSearchPageMode) && (
)}
);
};
GrowiSubNavigation.propTypes = {
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
navigationContainer: PropTypes.instanceOf(NavigationContainer).isRequired,
pageContainer: PropTypes.instanceOf(PageContainer),
isCompactMode: PropTypes.bool,
// Props for searchResultContent
pageId: PropTypes.string,
path: PropTypes.string,
isSearchPageMode: PropTypes.bool,
};
const GrowiSubNavigationWrapper = (props) => {
let GrowiSubNavigationUnstatedWrapper = <>>;
if (props.isSearchPageMode) {
GrowiSubNavigationUnstatedWrapper = withUnstatedContainers(GrowiSubNavigation, [AppContainer, NavigationContainer]);
return ;
}
GrowiSubNavigationUnstatedWrapper = withUnstatedContainers(GrowiSubNavigation, [AppContainer, NavigationContainer, PageContainer]);
return ;
};
GrowiSubNavigationWrapper.propTypes = {
isSearchPageMode: PropTypes.bool,
pageId: PropTypes.string,
path: PropTypes.string,
};
export default GrowiSubNavigationWrapper;