PageAttachmentList.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React, { type JSX } from 'react';
  2. import type { IAttachmentHasId } from '@growi/core';
  3. import { Attachment } from '@growi/ui/dist/components';
  4. import { useTranslation } from 'next-i18next';
  5. type Props = {
  6. attachments: IAttachmentHasId[];
  7. inUse: { [id: string]: boolean };
  8. onAttachmentDeleteClicked: (attachment: IAttachmentHasId) => void;
  9. isUserLoggedIn?: boolean;
  10. };
  11. export const PageAttachmentList = (props: Props): JSX.Element => {
  12. const { t } = useTranslation();
  13. const { attachments, inUse, onAttachmentDeleteClicked, isUserLoggedIn } =
  14. props;
  15. if (attachments.length === 0) {
  16. return <>{t('No_attachments_yet')}</>;
  17. }
  18. return (
  19. <div>
  20. <ul className="ps-2">
  21. {attachments.map((attachment) => {
  22. return (
  23. <Attachment
  24. key={`page:attachment:${attachment._id}`}
  25. attachment={attachment}
  26. inUse={inUse[attachment._id] || false}
  27. onAttachmentDeleteClicked={onAttachmentDeleteClicked}
  28. isUserLoggedIn={isUserLoggedIn}
  29. />
  30. );
  31. })}
  32. </ul>
  33. </div>
  34. );
  35. };