PageSideContents.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. >
  50. <i className="icon-fw icon-bubbles grw-page-accessories-control-icon"></i>
  51. <span>Comments</span>
  52. <CountBadge count={page.commentCount} />
  53. </button>
  54. </Link>
  55. </div>
  56. ) }
  57. <div className="d-none d-lg-block">
  58. <TableOfContents />
  59. { isUsersHomePagePath && <ContentLinkButtons author={page?.creator} /> }
  60. </div>
  61. </>
  62. );
  63. };