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 PageCreator from './PageCreator';
import RevisionAuthor from './RevisionAuthor';
import DrawerToggler from './DrawerToggler';
import UserPicture from '../User/UserPicture';
// 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-disable-next-line react/prop-types
const UserPagePathNav = ({ pageId, pagePath }) => {
const linkedPagePath = new LinkedPagePath(pagePath);
const latterLink = ;
return (
{latterLink}
);
};
/* eslint-disable react/prop-types */
const UserInfo = ({ pageUser }) => {
return (
{pageUser.name}
{pageUser.username}
{pageUser.isEmailPublished ? pageUser.email : '*****'}
{pageUser.introduction && {pageUser.introduction}}
);
};
/* 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 } = navigationContainer.state;
const {
pageId, path, createdAt, creator, updatedAt, revisionAuthor,
isForbidden: isPageForbidden, pageUser,
} = pageContainer.state;
const isPageNotFound = pageId == null;
const isUserPage = pageUser != null;
const isPageInTrash = isTrashPage(path);
// Display only the RevisionPath
if (isPageNotFound || isPageForbidden) {
return (
);
}
return (
{/* Left side */}
{ isDrawerMode && (
) }
{ !isCompactMode && !isPageNotFound && !isPageForbidden && !isUserPage && (
) }
{ isUserPage
? (
<>
>
)
: (
)
}
{/* Right side */}
{/* Page Authors */}
{ (!isCompactMode && !isUserPage) && (
{ creator != null && (
-
) }
{ revisionAuthor != null && (
-
) }
) }
);
};
/**
* 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);