import React, { useMemo } from 'react'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { useRouteMatch } from 'react-router-dom'; import { useGroup, useGroupMembershipRequests } from 'soapbox/api/hooks'; import GroupLookupHoc from 'soapbox/components/hoc/group-lookup-hoc'; import { Column, Icon, Layout, Stack, Text } from 'soapbox/components/ui'; import GroupHeader from 'soapbox/features/group/components/group-header'; import LinkFooter from 'soapbox/features/ui/components/link-footer'; import BundleContainer from 'soapbox/features/ui/containers/bundle-container'; import { CtaBanner, GroupMediaPanel, SignUpPanel, SuggestedGroupsPanel, } from 'soapbox/features/ui/util/async-components'; import { useFeatures, useOwnAccount } from 'soapbox/hooks'; import { Tabs } from '../components/ui'; import type { Group } from 'soapbox/schemas'; const messages = defineMessages({ all: { id: 'group.tabs.all', defaultMessage: 'All' }, members: { id: 'group.tabs.members', defaultMessage: 'Members' }, media: { id: 'group.tabs.media', defaultMessage: 'Media' }, tags: { id: 'group.tabs.tags', defaultMessage: 'Topics' }, }); interface IGroupPage { params?: { groupId?: string } children: React.ReactNode } const DeletedBlankslate = () => (
); const PrivacyBlankslate = () => (
); const BlockedBlankslate = ({ group }: { group: Group }) => (
, }} />
); /** Page to display a group. */ const GroupPage: React.FC = ({ params, children }) => { const intl = useIntl(); const features = useFeatures(); const match = useRouteMatch(); const { account: me } = useOwnAccount(); const id = params?.groupId || ''; const { group } = useGroup(id); const { accounts: pending } = useGroupMembershipRequests(id); const isMember = !!group?.relationship?.member; const isBlocked = group?.relationship?.blocked_by; const isPrivate = group?.locked; const isDeleted = !!group?.deleted_at; const tabItems = useMemo(() => { const items = []; items.push({ text: intl.formatMessage(messages.all), to: `/group/${group?.slug}`, name: '/group/:groupSlug', }); if (features.groupsTags) { items.push({ text: intl.formatMessage(messages.tags), to: `/group/${group?.slug}/tags`, name: '/group/:groupSlug/tags', }); } items.push( { text: intl.formatMessage(messages.media), to: `/group/${group?.slug}/media`, name: '/group/:groupSlug/media', }, { text: intl.formatMessage(messages.members), to: `/group/${group?.slug}/members`, name: '/group/:groupSlug/members', count: pending.length, }, ); return items; }, [features.groupsTags, pending.length, group?.slug]); const renderChildren = () => { if (isDeleted) { return ; } else if (!isMember && isPrivate) { return ; } else if (isBlocked) { return ; } else { return children; } }; return ( <> {renderChildren()} {!me && ( {Component => } )} {!me && ( {Component => } )} {Component => } {Component => } ); }; export default GroupLookupHoc(GroupPage as any) as any;