soapbox/src/components/attachment-thumbs.tsx

47 wiersze
1.3 KiB
TypeScript
Czysty Zwykły widok Historia

2022-05-17 14:03:37 +00:00
import React from 'react';
import { openModal } from 'soapbox/actions/modals';
import Bundle from 'soapbox/features/ui/components/bundle';
import { MediaGallery } from 'soapbox/features/ui/util/async-components';
2023-05-30 13:02:03 +00:00
import { useAppDispatch } from 'soapbox/hooks';
2022-05-17 14:03:37 +00:00
import type { List as ImmutableList } from 'immutable';
2022-10-10 20:16:35 +00:00
import type { Attachment } from 'soapbox/types/entities';
2022-05-17 14:03:37 +00:00
interface IAttachmentThumbs {
media: ImmutableList<Attachment>;
onClick?(): void;
sensitive?: boolean;
2022-05-17 14:03:37 +00:00
}
const AttachmentThumbs = (props: IAttachmentThumbs) => {
const { media, onClick, sensitive } = props;
2023-05-30 13:02:03 +00:00
const dispatch = useAppDispatch();
2022-05-17 14:03:37 +00:00
const renderLoading = () => <div className='media-gallery--compact' />;
2022-10-10 20:16:35 +00:00
const onOpenMedia = (media: ImmutableList<Attachment>, index: number) => dispatch(openModal('MEDIA', { media, index }));
2022-05-17 14:03:37 +00:00
return (
<div className='attachment-thumbs'>
<Bundle fetchComponent={MediaGallery} loading={renderLoading}>
{(Component: any) => (
<Component
media={media}
onOpenMedia={onOpenMedia}
height={50}
compact
sensitive={sensitive}
2022-10-10 20:16:35 +00:00
visible
2022-05-17 14:03:37 +00:00
/>
)}
</Bundle>
{onClick && (
<div className='attachment-thumbs__clickable-region' onClick={onClick} />
)}
</div>
);
};
export default AttachmentThumbs;