PageSideContents.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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, isTrashPage } = 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. const isTrash = isTrashPage(pagePath);
  24. return (
  25. <>
  26. {/* Page list */}
  27. <div className={`grw-page-accessories-control ${styles['grw-page-accessories-control']}`}>
  28. {!isSharedUser && (
  29. <button
  30. type="button"
  31. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  32. onClick={() => openDescendantPageListModal(pagePath)}
  33. data-testid="pageListButton"
  34. >
  35. <div className="grw-page-accessories-control-icon">
  36. <PageListIcon />
  37. </div>
  38. {t('page_list')}
  39. {/* Do not display CountBadge if '/trash/*': https://github.com/weseek/growi/pull/7600 */}
  40. { !isTrash ? <CountBadge count={page?.descendantCount} offset={1} /> : <div className='px-2'></div>}
  41. </button>
  42. )}
  43. </div>
  44. {/* Comments */}
  45. {!isTopPagePath && (
  46. <div className={`mt-2 grw-page-accessories-control ${styles['grw-page-accessories-control']}`}>
  47. <Link to={'page-comments'} offset={-120}>
  48. <button
  49. type="button"
  50. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  51. data-testid="page-comment-button"
  52. >
  53. <i className="icon-fw icon-bubbles grw-page-accessories-control-icon"></i>
  54. <span>Comments</span>
  55. <CountBadge count={page.commentCount} />
  56. </button>
  57. </Link>
  58. </div>
  59. )}
  60. <div className="d-none d-lg-block">
  61. <TableOfContents />
  62. {isUsersHomePagePath && <ContentLinkButtons author={page?.creator} />}
  63. </div>
  64. </>
  65. );
  66. };