PageAttachmentList.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React 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 {
  14. attachments, inUse, onAttachmentDeleteClicked, isUserLoggedIn,
  15. } = props;
  16. if (attachments.length === 0) {
  17. return <>{t('No_attachments_yet')}</>;
  18. }
  19. return (
  20. <div>
  21. <ul className="pl-2">
  22. {attachments.map((attachment) => {
  23. return (
  24. <Attachment
  25. key={`page:attachment:${attachment._id}`}
  26. attachment={attachment}
  27. inUse={inUse[attachment._id] || false}
  28. onAttachmentDeleteClicked={onAttachmentDeleteClicked}
  29. isUserLoggedIn={isUserLoggedIn}
  30. />
  31. );
  32. })}
  33. </ul>
  34. </div>
  35. );
  36. };