import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import { isTrashPage } from '@commons/util/path-utils';
import DevidedPagePath from '@commons/models/devided-page-path';
import LinkedPagePath from '@commons/models/linked-page-path';
import PagePathHierarchicalLink from '@commons/components/PagePathHierarchicalLink';
import { withUnstatedContainers } from '../UnstatedUtils';
import AppContainer from '../../services/AppContainer';
import NavigationContainer from '../../services/NavigationContainer';
import PageContainer from '../../services/PageContainer';
import RevisionPathControls from '../Page/RevisionPathControls';
import TagLabels from '../Page/TagLabels';
import LikeButton from '../LikeButton';
import BookmarkButton from '../BookmarkButton';
import ThreeStrandedButton from './ThreeStrandedButton';
import AuthorInfo from './AuthorInfo';
import DrawerToggler from './DrawerToggler';
import PageManagement from '../Page/PageManagement';
// eslint-disable-next-line react/prop-types
const PagePathNav = ({ pageId, pagePath, isPageForbidden }) => {
const dPagePath = new DevidedPagePath(pagePath, false, true);
let formerLink;
let latterLink;
// when the path is root or first level
if (dPagePath.isRoot || dPagePath.isFormerRoot) {
const linkedPagePath = new LinkedPagePath(pagePath);
latterLink = ;
}
// when the path is second level or deeper
else {
const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);
const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter);
formerLink = ;
latterLink = ;
}
return (
{formerLink}
{latterLink}
);
};
/* eslint-enable react/prop-types */
/* eslint-disable react/prop-types */
const PageReactionButtons = ({ appContainer, pageContainer }) => {
const {
pageId, isLiked, pageUser,
} = pageContainer.state;
return (
<>
{pageUser == null && (
)}
>
);
};
/* eslint-enable react/prop-types */
const GrowiSubNavigation = (props) => {
const {
appContainer, navigationContainer, pageContainer, isCompactMode,
} = props;
const { isDrawerMode, editorMode } = navigationContainer.state;
const {
pageId, path, createdAt, creator, updatedAt, revisionAuthor,
isForbidden: isPageForbidden, pageUser, isNotCreatable, shareLinkId,
} = pageContainer.state;
const { currentUser } = appContainer;
const isPageNotFound = pageId == null;
// Tags cannot be edited while the new page and editorMode is view
const isTagLabelHidden = (editorMode !== 'edit' && isPageNotFound);
const isUserPage = pageUser != null;
const isPageInTrash = isTrashPage(path);
const isSharedPage = shareLinkId != null;
function onThreeStrandedButtonClicked(viewType) {
navigationContainer.setEditorMode(viewType);
}
return (
{/* Left side */}
{ isDrawerMode && (
) }
{ !isCompactMode && !isTagLabelHidden && !isPageForbidden && !isUserPage && !isSharedPage && (
) }
{/* Right side */}
{ !isPageInTrash && !isPageNotFound && !isPageForbidden &&
}
{ !isPageNotFound && !isPageForbidden &&
}
{!isNotCreatable && !isPageInTrash && !isPageForbidden && (
)}
{/* Page Authors */}
{ (!isCompactMode && !isUserPage && !isPageNotFound && !isPageForbidden) && (
) }
);
};
/**
* Wrapper component for using unstated
*/
const GrowiSubNavigationWrapper = withUnstatedContainers(GrowiSubNavigation, [AppContainer, NavigationContainer, PageContainer]);
GrowiSubNavigation.propTypes = {
t: PropTypes.func.isRequired, // i18next
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
navigationContainer: PropTypes.instanceOf(NavigationContainer).isRequired,
pageContainer: PropTypes.instanceOf(PageContainer).isRequired,
isCompactMode: PropTypes.bool,
};
export default withTranslation()(GrowiSubNavigationWrapper);