2022-03-21 11:09:01 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-04-26 10:45:39 -07:00
|
|
|
import { useLocation, useRouteMatch } from 'react-router-dom';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
import { openModal } from 'soapbox/actions/modals';
|
2023-04-26 10:45:39 -07:00
|
|
|
import { Avatar, Button, HStack } from 'soapbox/components/ui';
|
2023-01-27 14:04:42 -08:00
|
|
|
import { useAppDispatch } from 'soapbox/hooks';
|
2023-04-26 10:45:39 -07:00
|
|
|
import { useGroupLookup } from 'soapbox/hooks/api/groups/useGroupLookup';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
const ComposeButton = () => {
|
2023-04-26 10:45:39 -07:00
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
if (location.pathname.startsWith('/group/')) {
|
|
|
|
return <GroupComposeButton />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <HomeComposeButton />;
|
|
|
|
};
|
|
|
|
|
|
|
|
const HomeComposeButton = () => {
|
2023-01-27 14:04:42 -08:00
|
|
|
const dispatch = useAppDispatch();
|
2022-03-21 11:09:01 -07:00
|
|
|
const onOpenCompose = () => dispatch(openModal('COMPOSE'));
|
|
|
|
|
|
|
|
return (
|
2022-12-23 13:22:41 -08:00
|
|
|
<Button
|
|
|
|
theme='accent'
|
|
|
|
icon={require('@tabler/icons/pencil-plus.svg')}
|
|
|
|
size='lg'
|
|
|
|
onClick={onOpenCompose}
|
|
|
|
block
|
|
|
|
>
|
|
|
|
<FormattedMessage id='navigation.compose' defaultMessage='Compose' />
|
|
|
|
</Button>
|
2022-03-21 11:09:01 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-04-26 10:45:39 -07:00
|
|
|
const GroupComposeButton = () => {
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
const match = useRouteMatch<{ groupSlug: string }>('/group/:groupSlug');
|
|
|
|
const { entity: group } = useGroupLookup(match?.params.groupSlug || '');
|
|
|
|
|
|
|
|
const onOpenCompose = () => dispatch(openModal('COMPOSE'));
|
|
|
|
|
|
|
|
if (group) {
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
theme='accent'
|
|
|
|
size='lg'
|
|
|
|
onClick={onOpenCompose}
|
|
|
|
block
|
|
|
|
>
|
|
|
|
<HStack space={3} alignItems='center'>
|
|
|
|
<Avatar className='-my-1 border-2 border-white' size={30} src={group.avatar} />
|
|
|
|
<span>
|
|
|
|
<FormattedMessage id='navigation.compose_group' defaultMessage='Compose to Group' />
|
|
|
|
</span>
|
|
|
|
</HStack>
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
export default ComposeButton;
|