PageSideContents.tsx 3.1 KB

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