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 { DEFAULT_AUTO_SCROLL_OPTS } from '~/client/util/smooth-scroll';
  6. import { useDescendantsPageListModal } from '~/stores/modal';
  7. import CountBadge from './Common/CountBadge';
  8. import { ContentLinkButtons } from './ContentLinkButtons';
  9. import PageListIcon from './Icons/PageListIcon';
  10. import TableOfContents from './TableOfContents';
  11. import styles from './PageSideContents.module.scss';
  12. const { isTopPage, isUsersHomePage } = pagePathUtils;
  13. export type PageSideContentsProps = {
  14. page: IPageHasId,
  15. isSharedUser?: boolean,
  16. }
  17. export const PageSideContents = (props: PageSideContentsProps): JSX.Element => {
  18. const { t } = useTranslation();
  19. const { open: openDescendantPageListModal } = useDescendantsPageListModal();
  20. const { page, isSharedUser } = props;
  21. const pagePath = page.path;
  22. const isTopPagePath = isTopPage(pagePath);
  23. const isUsersHomePagePath = isUsersHomePage(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. <CountBadge count={page?.descendantCount} offset={1} />
  40. </button>
  41. ) }
  42. </div>
  43. {/* Comments */}
  44. { !isTopPagePath && (
  45. <div className={`mt-2 grw-page-accessories-control ${styles['grw-page-accessories-control']}`}>
  46. <Link to={'page-comments'} offset={-100} {...DEFAULT_AUTO_SCROLL_OPTS}>
  47. <button
  48. type="button"
  49. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  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. };