Fix more group stuff

This commit is contained in:
MyNameIsBatman 2021-09-06 04:36:29 -03:00
parent be61c0b4a8
commit 0d8f15956b
2 changed files with 16 additions and 25 deletions

View File

@ -1,6 +1,6 @@
import { CatalogGroupsComposer, HabboGroupEntryData } from '@nitrots/nitro-renderer'; import { CatalogGroupsComposer } from '@nitrots/nitro-renderer';
import { FC, useEffect, useState } from 'react'; import { FC, useEffect, useState } from 'react';
import { GetSessionDataManager, LocalizeText } from '../../../../../../api'; import { LocalizeText } from '../../../../../../api';
import { SendMessageHook } from '../../../../../../hooks/messages'; import { SendMessageHook } from '../../../../../../hooks/messages';
import { BadgeImageView } from '../../../../../shared/badge-image/BadgeImageView'; import { BadgeImageView } from '../../../../../shared/badge-image/BadgeImageView';
import { GetCatalogPageText } from '../../../../common/CatalogUtilities'; import { GetCatalogPageText } from '../../../../common/CatalogUtilities';
@ -17,7 +17,6 @@ export const CatalogLayouGuildForumView: FC<CatalogLayoutGuildForumViewProps> =
const { activeOffer = null, groups = null } = catalogState; const { activeOffer = null, groups = null } = catalogState;
const [ selectedGroupIndex, setSelectedGroupIndex ] = useState<number>(0); const [ selectedGroupIndex, setSelectedGroupIndex ] = useState<number>(0);
const [ availableGroups, setAvailableGroups ] = useState<HabboGroupEntryData[]>([]);
const product = ((activeOffer && activeOffer.products[0]) || null); const product = ((activeOffer && activeOffer.products[0]) || null);
@ -35,48 +34,37 @@ export const CatalogLayouGuildForumView: FC<CatalogLayoutGuildForumViewProps> =
}); });
} }
}, [ dispatchCatalogState, pageParser ]); }, [ dispatchCatalogState, pageParser ]);
useEffect(() =>
{
const available: HabboGroupEntryData[] = [];
groups.forEach((group) =>
{
if(!group.hasForum && group.ownerId === GetSessionDataManager().userId) available.push(group);
});
setAvailableGroups(available);
}, [ groups ]);
return ( return (
<div className="row h-100 nitro-catalog-layout-guild-custom-furni"> <div className="row h-100 nitro-catalog-layout-guild-custom-furni">
<div className="col-7 overflow-auto h-100 d-flex flex-column bg-muted rounded py-1 px-2 text-black"> <div className="col-7 overflow-auto h-100 d-flex flex-column bg-muted rounded py-1 px-2 text-black">
<div dangerouslySetInnerHTML={ { __html: GetCatalogPageText(pageParser, 1) } } /> <div dangerouslySetInnerHTML={ { __html: GetCatalogPageText(pageParser, 1) } } />
</div> </div>
<div className="col position-relative d-flex flex-column justify-content-center align-items-center"> { product && <div className="col position-relative d-flex flex-column justify-content-center align-items-center">
{ availableGroups.length === 0 && <div className="bg-muted text-center rounded p-1 text-black"> { groups.length === 0 && <div className="bg-muted text-center rounded p-1 text-black">
{ LocalizeText('catalog.guild_selector.members_only') } { LocalizeText('catalog.guild_selector.members_only') }
<button className="btn btn-sm btn-primary mt-1">{ LocalizeText('catalog.guild_selector.find_groups') }</button> <button className="btn btn-sm btn-primary mt-1">{ LocalizeText('catalog.guild_selector.find_groups') }</button>
</div> } </div> }
{ availableGroups[selectedGroupIndex] && <div style={{ width: '50px', height: '50px', zIndex: 1 }}> { groups[selectedGroupIndex] && <div style={{ width: '50px', height: '50px', zIndex: 1 }}>
<BadgeImageView badgeCode={ availableGroups[selectedGroupIndex].badgeCode } isGroup={ true } /> <BadgeImageView badgeCode={ groups[selectedGroupIndex].badgeCode } isGroup={ true } />
</div> } </div> }
{ availableGroups.length > 0 && <> { groups.length > 0 && <>
<div className="d-flex mb-2 w-100"> <div className="d-flex mb-2 w-100">
<div className="rounded d-flex overflow-hidden me-1 border"> <div className="rounded d-flex overflow-hidden me-1 border">
<div className="h-100" style={{ width: '20px', backgroundColor: '#' + availableGroups[selectedGroupIndex].colorA }}></div> <div className="h-100" style={{ width: '20px', backgroundColor: '#' + groups[selectedGroupIndex].colorA }}></div>
<div className="h-100" style={{ width: '20px', backgroundColor: '#' + availableGroups[selectedGroupIndex].colorB }}></div> <div className="h-100" style={{ width: '20px', backgroundColor: '#' + groups[selectedGroupIndex].colorB }}></div>
</div> </div>
<select className="form-select form-select-sm" value={ selectedGroupIndex } onChange={ (e) => setSelectedGroupIndex(parseInt(e.target.value)) }> <select className="form-select form-select-sm" value={ selectedGroupIndex } onChange={ (e) => setSelectedGroupIndex(parseInt(e.target.value)) }>
{ availableGroups.map((group, index) => { groups.map((group, index) =>
{ {
return <option key={ index } value={ index }>{ group.groupName }</option>; return <option key={ index } value={ index }>{ group.groupName }</option>;
}) } }) }
</select> </select>
</div> </div>
<CatalogPurchaseView offer={ activeOffer } pageId={ pageParser.pageId } extra={ availableGroups[selectedGroupIndex] ? availableGroups[selectedGroupIndex].groupId.toString() : '' } /> { groups[selectedGroupIndex].hasForum && <div className="bg-primary p-1 text-center rounded">{ LocalizeText('catalog.alert.group_has_forum') }</div> }
<CatalogPurchaseView offer={ activeOffer } pageId={ pageParser.pageId } extra={ groups[selectedGroupIndex] ? groups[selectedGroupIndex].groupId.toString() : '' } />
</> } </> }
</div> </div> }
</div> </div>
); );
} }

View File

@ -192,6 +192,9 @@ export const FurnitureContextMenuView: FC<{}> = props =>
<ContextMenuListItemView onClick={ event => processAction('go_to_group_homeroom') }> <ContextMenuListItemView onClick={ event => processAction('go_to_group_homeroom') }>
{ LocalizeText('widget.furniture.button.go.to.group.home.room') } { LocalizeText('widget.furniture.button.go.to.group.home.room') }
</ContextMenuListItemView> </ContextMenuListItemView>
{ groupData.guildHasReadableForum && <ContextMenuListItemView onClick={ event => processAction('open_forum') }>
{ LocalizeText('widget.furniture.button.open_group_forum') }
</ContextMenuListItemView> }
</> } </> }
</ContextMenuView> } </ContextMenuView> }
</> </>