PageSideContents.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React from 'react';
  2. import { IPageHasId, pagePathUtils } from '@growi/core';
  3. import { useTranslation } from 'next-i18next';
  4. import { Link } from 'react-scroll';
  5. import { useDescendantsPageListModal } from '~/stores/modal';
  6. import CountBadge from './Common/CountBadge';
  7. import { ContentLinkButtons } from './ContentLinkButtons';
  8. import PageListIcon from './Icons/PageListIcon';
  9. import TableOfContents from './TableOfContents';
  10. import styles from './PageSideContents.module.scss';
  11. const { isTopPage, isUsersHomePage } = pagePathUtils;
  12. export type PageSideContentsProps = {
  13. page: IPageHasId,
  14. isSharedUser?: boolean,
  15. }
  16. export const PageSideContents = (props: PageSideContentsProps): JSX.Element => {
  17. const { t } = useTranslation();
  18. const { open: openDescendantPageListModal } = useDescendantsPageListModal();
  19. const { page, isSharedUser } = props;
  20. const pagePath = page.path;
  21. const isTopPagePath = isTopPage(pagePath);
  22. const isUsersHomePagePath = isUsersHomePage(pagePath);
  23. return (
  24. <>
  25. {/* Page list */}
  26. <div className={`grw-page-accessories-control ${styles['grw-page-accessories-control']}`}>
  27. {!isSharedUser && (
  28. <button
  29. type="button"
  30. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  31. onClick={() => openDescendantPageListModal(pagePath)}
  32. data-testid="pageListButton"
  33. >
  34. <div className="grw-page-accessories-control-icon">
  35. <PageListIcon />
  36. </div>
  37. {t('page_list')}
  38. <CountBadge count={page?.descendantCount} offset={1} />
  39. </button>
  40. )}
  41. </div>
  42. {/* Comments */}
  43. {!isTopPagePath && (
  44. <div className={`mt-2 grw-page-accessories-control ${styles['grw-page-accessories-control']}`}>
  45. <Link to={'page-comments'} offset={-120}>
  46. <button
  47. type="button"
  48. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  49. data-testid="page-comment-button"
  50. >
  51. <i className="icon-fw icon-bubbles grw-page-accessories-control-icon"></i>
  52. <span>Comments</span>
  53. <CountBadge count={page.commentCount} />
  54. </button>
  55. </Link>
  56. </div>
  57. )}
  58. <div className="d-none d-lg-block">
  59. <TableOfContents />
  60. {isUsersHomePagePath && <ContentLinkButtons author={page?.creator} />}
  61. </div>
  62. </>
  63. );
  64. };