import React from 'react'; import { FormattedMessage } from 'react-intl'; import { useLocation, useRouteMatch } from 'react-router-dom'; import { groupComposeModal } from 'soapbox/actions/compose'; import { openModal } from 'soapbox/actions/modals'; import { useGroupLookup } from 'soapbox/api/hooks'; import { Avatar, Button, HStack } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; const ComposeButton = () => { const location = useLocation(); const isOnGroupPage = location.pathname.startsWith('/group/'); const match = useRouteMatch<{ groupSlug: string }>('/group/:groupSlug'); const { entity: group } = useGroupLookup(match?.params.groupSlug || ''); const isGroupMember = !!group?.relationship?.member; if (isOnGroupPage && isGroupMember) { return ; } return ; }; const HomeComposeButton = () => { const dispatch = useAppDispatch(); const onOpenCompose = () => dispatch(openModal('COMPOSE')); return ( ); }; const GroupComposeButton = () => { const dispatch = useAppDispatch(); const match = useRouteMatch<{ groupSlug: string }>('/group/:groupSlug'); const { entity: group } = useGroupLookup(match?.params.groupSlug || ''); if (!group) return null; const onOpenCompose = () => { dispatch(groupComposeModal(group)); }; return ( ); }; export default ComposeButton;