Update Group component with Join buttons

This commit is contained in:
Chewbacca 2023-03-09 11:55:35 -05:00
parent 737c43d847
commit 58527b0656
2 changed files with 57 additions and 43 deletions

View file

@ -5,6 +5,7 @@ import { Link } from 'react-router-dom';
import { Avatar, Button, HStack, Stack, Text } from 'soapbox/components/ui'; import { Avatar, Button, HStack, Stack, Text } from 'soapbox/components/ui';
import GroupMemberCount from 'soapbox/features/group/components/group-member-count'; import GroupMemberCount from 'soapbox/features/group/components/group-member-count';
import GroupPrivacy from 'soapbox/features/group/components/group-privacy'; import GroupPrivacy from 'soapbox/features/group/components/group-privacy';
import { useJoinGroup } from 'soapbox/queries/groups';
import { Group as GroupEntity } from 'soapbox/types/entities'; import { Group as GroupEntity } from 'soapbox/types/entities';
interface IGroup { interface IGroup {
@ -15,6 +16,10 @@ interface IGroup {
const GroupGridItem = forwardRef((props: IGroup, ref: React.ForwardedRef<HTMLDivElement>) => { const GroupGridItem = forwardRef((props: IGroup, ref: React.ForwardedRef<HTMLDivElement>) => {
const { group, width = 'auto' } = props; const { group, width = 'auto' } = props;
const joinGroup = useJoinGroup();
const onJoinGroup = () => joinGroup.mutate(group);
return ( return (
<div <div
key={group.id} key={group.id}
@ -69,6 +74,8 @@ const GroupGridItem = forwardRef((props: IGroup, ref: React.ForwardedRef<HTMLDiv
<Button <Button
theme='primary' theme='primary'
block block
onClick={onJoinGroup}
disabled={joinGroup.isLoading}
> >
{group.locked {group.locked
? <FormattedMessage id='group.join.private' defaultMessage='Request Access' /> ? <FormattedMessage id='group.join.private' defaultMessage='Request Access' />

View file

@ -1,7 +1,9 @@
import React from 'react'; import React from 'react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';
import { Avatar, Button, HStack, Icon, Stack, Text } from 'soapbox/components/ui'; import { Avatar, Button, HStack, Icon, Stack, Text } from 'soapbox/components/ui';
import { useJoinGroup } from 'soapbox/queries/groups';
import { Group as GroupEntity } from 'soapbox/types/entities'; import { Group as GroupEntity } from 'soapbox/types/entities';
import { shortNumberFormat } from 'soapbox/utils/numbers'; import { shortNumberFormat } from 'soapbox/utils/numbers';
@ -13,12 +15,16 @@ interface IGroup {
const GroupListItem = (props: IGroup) => { const GroupListItem = (props: IGroup) => {
const { group, withJoinAction = true } = props; const { group, withJoinAction = true } = props;
const joinGroup = useJoinGroup();
const onJoinGroup = () => joinGroup.mutate(group);
return ( return (
<HStack <HStack
key={group.id}
alignItems='center' alignItems='center'
justifyContent='between' justifyContent='between'
> >
<Link key={group.id} to={`/groups/${group.id}`}>
<HStack alignItems='center' space={2}> <HStack alignItems='center' space={2}>
<Avatar <Avatar
className='ring-2 ring-white dark:ring-primary-900' className='ring-2 ring-white dark:ring-primary-900'
@ -65,9 +71,10 @@ const GroupListItem = (props: IGroup) => {
</HStack> </HStack>
</Stack> </Stack>
</HStack> </HStack>
</Link>
{withJoinAction && ( {withJoinAction && (
<Button theme='primary'> <Button theme='primary' onClick={onJoinGroup} disabled={joinGroup.isLoading}>
{group.locked {group.locked
? <FormattedMessage id='group.join.private' defaultMessage='Request Access' /> ? <FormattedMessage id='group.join.private' defaultMessage='Request Access' />
: <FormattedMessage id='group.join.public' defaultMessage='Join Group' />} : <FormattedMessage id='group.join.public' defaultMessage='Join Group' />}