PageSideContents.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 { useCurrentPathname } from '~/stores/context';
  7. import { useDescendantsPageListModal } from '~/stores/modal';
  8. import CountBadge from './Common/CountBadge';
  9. import { ContentLinkButtons } from './ContentLinkButtons';
  10. import PageListIcon from './Icons/PageListIcon';
  11. import TableOfContents from './TableOfContents';
  12. import styles from './PageSideContents.module.scss';
  13. const { isTopPage, isUsersHomePage } = pagePathUtils;
  14. export type PageSideContentsProps = {
  15. page?: IPageHasId,
  16. isSharedUser?: boolean,
  17. }
  18. export const PageSideContents = (props: PageSideContentsProps): JSX.Element => {
  19. const { t } = useTranslation();
  20. const { data: currentPathname } = useCurrentPathname();
  21. const { open: openDescendantPageListModal } = useDescendantsPageListModal();
  22. const { page, isSharedUser } = props;
  23. const pagePath = page?.path ?? currentPathname;
  24. const isTopPagePath = isTopPage(pagePath ?? '');
  25. const isUsersHomePagePath = isUsersHomePage(pagePath ?? '');
  26. return (
  27. <>
  28. {/* Page list */}
  29. <div className={`grw-page-accessories-control ${styles['grw-page-accessories-control']}`}>
  30. { pagePath != null && !isSharedUser && (
  31. <button
  32. type="button"
  33. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  34. onClick={() => openDescendantPageListModal(pagePath)}
  35. data-testid="pageListButton"
  36. >
  37. <div className="grw-page-accessories-control-icon">
  38. <PageListIcon />
  39. </div>
  40. {t('page_list')}
  41. <CountBadge count={page?.descendantCount} offset={1} />
  42. </button>
  43. ) }
  44. </div>
  45. {/* Comments */}
  46. { page != null && !isTopPagePath && (
  47. <div className={`mt-2 grw-page-accessories-control ${styles['grw-page-accessories-control']}`}>
  48. <Link to={'page-comments'} offset={-100} {...DEFAULT_AUTO_SCROLL_OPTS}>
  49. <button
  50. type="button"
  51. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  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. };