diff --git a/src/api/groups/ToggleFavoriteGroup.ts b/src/api/groups/ToggleFavoriteGroup.ts new file mode 100644 index 00000000..ad1a669c --- /dev/null +++ b/src/api/groups/ToggleFavoriteGroup.ts @@ -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)); +} diff --git a/src/api/groups/index.ts b/src/api/groups/index.ts index 1f8b545d..2f528cab 100644 --- a/src/api/groups/index.ts +++ b/src/api/groups/index.ts @@ -1,4 +1,5 @@ export * from './GetGroupInformation'; export * from './GetGroupManager'; export * from './GetGroupMembers'; +export * from './ToggleFavoriteGroup'; export * from './TryJoinGroup'; diff --git a/src/components/user-profile/views/GroupsContainerView.tsx b/src/components/user-profile/views/GroupsContainerView.tsx index 845113e1..56643e46 100644 --- a/src/components/user-profile/views/GroupsContainerView.tsx +++ b/src/components/user-profile/views/GroupsContainerView.tsx @@ -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 = props => const [ selectedGroupId, setSelectedGroupId ] = useState(null); const [ groupInformation, setGroupInformation ] = useState(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 = 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 = props => return ( setSelectedGroupId(group.groupId) } className="p-1"> { itsMe && - favoriteGroup(group.groupId) } /> } + ToggleFavoriteGroup(group) } /> } )