CountBadgeForPageTreeItem.tsx 651 B

1234567891011121314151617181920212223
  1. import type { JSX } from 'react';
  2. import CountBadge from '~/client/components/Common/CountBadge';
  3. import type { TreeItemToolProps } from '~/features/page-tree/interfaces';
  4. import { usePageTreeDescCountMap } from '~/features/page-tree/states';
  5. export const CountBadgeForPageTreeItem = (props: TreeItemToolProps): JSX.Element => {
  6. const { getDescCount } = usePageTreeDescCountMap();
  7. const { item } = props;
  8. const page = item.getItemData();
  9. const descendantCount = getDescCount(page._id) || page.descendantCount || 0;
  10. return (
  11. <>
  12. {descendantCount > 0 && (
  13. <CountBadge count={descendantCount} />
  14. )}
  15. </>
  16. );
  17. };