mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-27 08:00:51 +01:00
Fix groups on profile
This commit is contained in:
parent
b61ea0b409
commit
8b1e5dc552
8
src/api/groups/ToggleFavoriteGroup.ts
Normal file
8
src/api/groups/ToggleFavoriteGroup.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { GroupFavoriteComposer, HabboGroupEntryData } from '@nitrots/nitro-renderer';
|
||||
import { SendMessageComposer } from '..';
|
||||
|
||||
export const ToggleFavoriteGroup = (group: HabboGroupEntryData) =>
|
||||
{
|
||||
// new GroupUnfavoriteComposer(group.groupId)
|
||||
SendMessageComposer(group.favourite ? null : new GroupFavoriteComposer(group.groupId));
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
export * from './GetGroupInformation';
|
||||
export * from './GetGroupManager';
|
||||
export * from './GetGroupMembers';
|
||||
export * from './ToggleFavoriteGroup';
|
||||
export * from './TryJoinGroup';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { GroupFavoriteComposer, GroupInformationComposer, GroupInformationEvent, GroupInformationParser, HabboGroupEntryData } from '@nitrots/nitro-renderer';
|
||||
import { GroupInformationComposer, GroupInformationEvent, GroupInformationParser, HabboGroupEntryData } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback, useEffect, useState } from 'react';
|
||||
import { SendMessageComposer } from '../../../api';
|
||||
import { SendMessageComposer, ToggleFavoriteGroup } from '../../../api';
|
||||
import { AutoGrid, Base, Column, Flex, Grid, GridProps, LayoutBadgeImageView, LayoutGridItem } from '../../../common';
|
||||
import { BatchUpdates, UseMessageEventHook } from '../../../hooks';
|
||||
import { GroupInformationView } from '../../groups/views/GroupInformationView';
|
||||
@ -18,18 +18,14 @@ export const GroupsContainerView: FC<GroupsContainerViewProps> = props =>
|
||||
const [ selectedGroupId, setSelectedGroupId ] = useState<number>(null);
|
||||
const [ groupInformation, setGroupInformation ] = useState<GroupInformationParser>(null);
|
||||
|
||||
const favoriteGroup = (groupId: number) => SendMessageComposer(new GroupFavoriteComposer(groupId));
|
||||
|
||||
const onGroupInformationEvent = useCallback((event: GroupInformationEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!selectedGroupId || (selectedGroupId !== parser.id) || parser.flag) return;
|
||||
|
||||
if(groupInformation) setGroupInformation(null);
|
||||
|
||||
setGroupInformation(parser);
|
||||
}, [ groupInformation, selectedGroupId ]);
|
||||
}, [ selectedGroupId ]);
|
||||
|
||||
UseMessageEventHook(GroupInformationEvent, onGroupInformationEvent);
|
||||
|
||||
@ -46,7 +42,18 @@ export const GroupsContainerView: FC<GroupsContainerViewProps> = props =>
|
||||
{
|
||||
setGroupInformation(null);
|
||||
|
||||
if(groups.length > 0) setSelectedGroupId(groups[0].groupId);
|
||||
if(groups.length > 0)
|
||||
{
|
||||
setSelectedGroupId(prevValue =>
|
||||
{
|
||||
if(prevValue === groups[0].groupId)
|
||||
{
|
||||
SendMessageComposer(new GroupInformationComposer(groups[0].groupId, false));
|
||||
}
|
||||
|
||||
return groups[0].groupId;
|
||||
});
|
||||
}
|
||||
});
|
||||
}, [ groups ]);
|
||||
|
||||
@ -72,7 +79,7 @@ export const GroupsContainerView: FC<GroupsContainerViewProps> = props =>
|
||||
return (
|
||||
<LayoutGridItem key={ index } overflow="unset" itemActive={ (selectedGroupId === group.groupId) } onClick={ () => setSelectedGroupId(group.groupId) } className="p-1">
|
||||
{ itsMe &&
|
||||
<i className={ 'position-absolute end-0 top-0 z-index-1 icon icon-group-' + (group.favourite ? 'favorite' : 'not-favorite') } onClick={ () => favoriteGroup(group.groupId) } /> }
|
||||
<i className={ 'position-absolute end-0 top-0 z-index-1 icon icon-group-' + (group.favourite ? 'favorite' : 'not-favorite') } onClick={ () => ToggleFavoriteGroup(group) } /> }
|
||||
<LayoutBadgeImageView badgeCode={ group.badgeCode } isGroup={ true } />
|
||||
</LayoutGridItem>
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user