import React from 'react'; import { FormattedMessage } from 'react-intl'; import { openModal } from 'soapbox/actions/modals'; import { useGroup, useGroupMedia } from 'soapbox/api/hooks'; import LoadMore from 'soapbox/components/load-more'; import MissingIndicator from 'soapbox/components/missing-indicator'; import { Column, Spinner } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; import MediaItem from '../account-gallery/components/media-item'; import type { Attachment, Status } from 'soapbox/types/entities'; interface IGroupGallery { params: { groupId: string } } const GroupGallery: React.FC = (props) => { const { groupId } = props.params; const dispatch = useAppDispatch(); const { group, isLoading: groupIsLoading } = useGroup(groupId); const { entities: statuses, fetchNextPage, isLoading, isFetching, hasNextPage, } = useGroupMedia(groupId); const attachments = statuses.reduce((result, status) => { result.push(...status.media_attachments.map((a) => a.set('status', status))); return result; }, []); const handleOpenMedia = (attachment: Attachment) => { if (attachment.type === 'video') { dispatch(openModal('VIDEO', { media: attachment, status: attachment.status, account: attachment.account })); } else { const media = (attachment.status as Status).media_attachments; const index = media.findIndex((x) => x.id === attachment.id); dispatch(openModal('MEDIA', { media, index, status: attachment.status })); } }; if (isLoading || groupIsLoading) { return (
); } if (!group) { return (
); } return (
{attachments.map((attachment) => ( ))} {(!isLoading && attachments.length === 0) && (
)}
{hasNextPage && ( )}
); }; export default GroupGallery;