PageList.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React from 'react';
  2. import type { IPageInfoForEntity, IPageWithMeta } from '@growi/core';
  3. import { LoadingSpinner } from '@growi/ui/dist/components';
  4. import { useTranslation } from 'next-i18next';
  5. import type { OnDeletedFunction, OnPutBackedFunction } from '~/interfaces/ui';
  6. import type { ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
  7. import { PageListItemL } from './PageListItemL';
  8. import styles from './PageList.module.scss';
  9. type Props<M extends IPageInfoForEntity> = {
  10. pages: IPageWithMeta<M>[],
  11. isEnableActions?: boolean,
  12. isReadOnlyUser: boolean,
  13. forceHideMenuItems?: ForceHideMenuItems,
  14. onPagesDeleted?: OnDeletedFunction,
  15. onPagePutBacked?: OnPutBackedFunction,
  16. }
  17. const PageList = (props: Props<IPageInfoForEntity>): JSX.Element => {
  18. const { t } = useTranslation();
  19. const {
  20. pages, isEnableActions, isReadOnlyUser, forceHideMenuItems, onPagesDeleted, onPagePutBacked,
  21. } = props;
  22. if (pages == null) {
  23. return (
  24. <div className="wiki">
  25. <div className="text-muted text-center">
  26. <LoadingSpinner className="me-1 fs-3" />
  27. </div>
  28. </div>
  29. );
  30. }
  31. const pageList = pages.map(page => (
  32. <PageListItemL
  33. key={page.data._id}
  34. page={page}
  35. isEnableActions={isEnableActions}
  36. isReadOnlyUser={isReadOnlyUser}
  37. forceHideMenuItems={forceHideMenuItems}
  38. onPageDeleted={onPagesDeleted}
  39. onPagePutBacked={onPagePutBacked}
  40. />
  41. ));
  42. if (pageList.length === 0) {
  43. return (
  44. <div className="mt-2">
  45. <p>{t('custom_navigation.no_pages_under_this_page')}</p>
  46. </div>
  47. );
  48. }
  49. return (
  50. <div className={`page-list ${styles['page-list']}`}>
  51. <ul className="page-list-ul list-group list-group-flush">
  52. {pageList}
  53. </ul>
  54. </div>
  55. );
  56. };
  57. export default PageList;