listen for event categories

This commit is contained in:
dank074 2022-06-17 23:26:13 -05:00
parent 269f1c1ad0
commit f913d03185
4 changed files with 64 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import { GetRoomAdPurchaseInfoComposer, PurchaseRoomAdMessageComposer, RoomAdPurchaseInfoEvent, RoomEntryData } from '@nitrots/nitro-renderer'; import { GetRoomAdPurchaseInfoComposer, GetUserEventCatsMessageComposer, PurchaseRoomAdMessageComposer, RoomAdPurchaseInfoEvent, RoomEntryData, UserEventCatsEvent } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react'; import { FC, useCallback, useEffect, useState } from 'react';
import { LocalizeText, SendMessageComposer } from '../../../../../api'; import { LocalizeText, SendMessageComposer } from '../../../../../api';
import { Base, Column, Text } from '../../../../../common'; import { Base, Button, Column, Text } from '../../../../../common';
import { UseMessageEventHook } from '../../../../../hooks'; import { UseMessageEventHook } from '../../../../../hooks';
import { CatalogLayoutProps } from './CatalogLayout.types'; import { CatalogLayoutProps } from './CatalogLayout.types';
@ -10,10 +10,11 @@ export const CatalogLayoutRoomAdsView: FC<CatalogLayoutProps> = props =>
const { page = null } = props; const { page = null } = props;
const [ eventName, setEventName ] = useState<string>(''); const [ eventName, setEventName ] = useState<string>('');
const [ eventDesc, setEventDesc ] = useState<string>(''); const [ eventDesc, setEventDesc ] = useState<string>('');
const [ roomId, setRoomId ] = useState<number>(null); const [ roomId, setRoomId ] = useState<number>(-1);
const [ availableRooms, setAvailableRooms ] = useState<RoomEntryData[]>([]); const [ availableRooms, setAvailableRooms ] = useState<RoomEntryData[]>([]);
const [ extended, setExtended ] = useState<boolean>(false); const [ extended, setExtended ] = useState<boolean>(false);
const [ categories, setCategories ] = useState(null); const [ categoryId, setCategoryId ] = useState<number>(1);
const [ categories, setCategories ] = useState<INavigatorCategory[]>(null);
const onRoomAdPurchaseInfoEvent = useCallback((event: RoomAdPurchaseInfoEvent) => const onRoomAdPurchaseInfoEvent = useCallback((event: RoomAdPurchaseInfoEvent) =>
{ {
@ -33,29 +34,45 @@ export const CatalogLayoutRoomAdsView: FC<CatalogLayoutProps> = props =>
const flatId = roomId; const flatId = roomId;
const name = eventName; const name = eventName;
const desc = eventDesc; const desc = eventDesc;
const categoryId = -1; const catId = categoryId;
SendMessageComposer(new PurchaseRoomAdMessageComposer(pageId, offerId, flatId, name, extended, desc, categoryId)) SendMessageComposer(new PurchaseRoomAdMessageComposer(pageId, offerId, flatId, name, extended, desc, catId))
}, [eventDesc, eventName, extended, page.offers, page.pageId, roomId]); }, [ categoryId, eventDesc, eventName, extended, page.offers, page.pageId, roomId ]);
const onUserEventCatsEvent = (event: UserEventCatsEvent) =>
{
const parser = event.getParser();
setCategories(parser.categories);
}
UseMessageEventHook(UserEventCatsEvent, onUserEventCatsEvent);
useEffect(() => useEffect(() =>
{ {
SendMessageComposer(new GetRoomAdPurchaseInfoComposer()); SendMessageComposer(new GetRoomAdPurchaseInfoComposer());
//SendMessageComposer(new GetUserEventCatsMessageComposer()); // TODO: someone needs to fix this for morningstar
SendMessageComposer(new GetUserEventCatsMessageComposer());
}, []); }, []);
return (<> return (<>
<Text bold center>{ LocalizeText('roomad.catalog_header') }</Text> <Text bold center>{ LocalizeText('roomad.catalog_header') }</Text>
<Column size={12} overflow="hidden" className='text-black'> <Column size={ 12 } overflow="hidden" className="text-black">
<Base>{ LocalizeText('roomad.catalog_text') }</Base> <Base>{ LocalizeText('roomad.catalog_text') }</Base>
<Base className='bg-muted rounded p-1'> <Base className="bg-muted rounded p-1">
<Column gap={ 2 }>
<select className="form-select form-select-sm" value={ categoryId } onChange={ event => setCategoryId(parseInt(event.target.value)) }>
{ categories && categories.map((cat, index) => <option key={ index } value={ cat.id }>{ cat.name }</option>) }
</select>
</Column>
<Column gap={ 1 }> <Column gap={ 1 }>
<Text bold>{ LocalizeText('roomad.catalog_name') }</Text> <Text bold>{ LocalizeText('roomad.catalog_name') }</Text>
<input type="text" className="form-control form-control-sm" maxLength={ 64 } value={ eventName } onChange={ event => setEventName(event.target.value) } /> <input type="text" className="form-control form-control-sm" maxLength={ 64 } value={ eventName } onChange={ event => setEventName(event.target.value) } />
</Column> </Column>
<Column gap={ 1 }> <Column gap={ 1 }>
< Text bold>{ LocalizeText('roomad.catalog_description') }</Text> < Text bold>{ LocalizeText('roomad.catalog_description') }</Text>
<textarea className='form-control form-control-sm' maxLength={ 64 } value={ eventDesc } onChange={ event => setEventDesc(event.target.value) }/> <textarea className="form-control form-control-sm" maxLength={ 64 } value={ eventDesc } onChange={ event => setEventDesc(event.target.value) }/>
</Column> </Column>
<Column gap={ 1 }> <Column gap={ 1 }>
<Text bold>{ LocalizeText('roomad.catalog_roomname') }</Text> <Text bold>{ LocalizeText('roomad.catalog_roomname') }</Text>
@ -64,8 +81,17 @@ export const CatalogLayoutRoomAdsView: FC<CatalogLayoutProps> = props =>
{ availableRooms && availableRooms.map((room, index) => <option key={ index } value={ room.roomId }>{ room.roomName }</option>) } { availableRooms && availableRooms.map((room, index) => <option key={ index } value={ room.roomId }>{ room.roomName }</option>) }
</select> </select>
</Column> </Column>
<Column gap={ 1 }>
<Button onClick={ purchaseAd }>{ LocalizeText('buy') }</Button>
</Column>
</Base> </Base>
</Column> </Column>
</> </>
); );
} }
interface INavigatorCategory {
id: number;
name: string;
visible: boolean;
}

View File

@ -1,4 +1,4 @@
import { NavigatorCategoryDataParser, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser } from '@nitrots/nitro-renderer'; import { NavigatorCategoryDataParser, NavigatorEventCategoryDataParser, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser } from '@nitrots/nitro-renderer';
import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react'; import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react';
import { INavigatorData } from '../../api'; import { INavigatorData } from '../../api';
@ -6,6 +6,8 @@ interface INavigatorContext
{ {
categories: NavigatorCategoryDataParser[]; categories: NavigatorCategoryDataParser[];
setCategories: Dispatch<SetStateAction<NavigatorCategoryDataParser[]>>; setCategories: Dispatch<SetStateAction<NavigatorCategoryDataParser[]>>;
eventCategories: NavigatorEventCategoryDataParser[];
setEventCategories: Dispatch<SetStateAction<NavigatorEventCategoryDataParser[]>>;
topLevelContext: NavigatorTopLevelContext; topLevelContext: NavigatorTopLevelContext;
setTopLevelContext: Dispatch<SetStateAction<NavigatorTopLevelContext>>; setTopLevelContext: Dispatch<SetStateAction<NavigatorTopLevelContext>>;
topLevelContexts: NavigatorTopLevelContext[]; topLevelContexts: NavigatorTopLevelContext[];
@ -22,6 +24,8 @@ const NavigatorContext = createContext<INavigatorContext>({
categories: null, categories: null,
setCategories: null, setCategories: null,
topLevelContext: null, topLevelContext: null,
setEventCategories: null,
eventCategories: null,
setTopLevelContext: null, setTopLevelContext: null,
topLevelContexts: null, topLevelContexts: null,
setTopLevelContexts: null, setTopLevelContexts: null,

View File

@ -1,4 +1,4 @@
import { CanCreateRoomEventEvent, CantConnectMessageParser, DoorbellMessageEvent, FlatAccessDeniedMessageEvent, FlatCreatedEvent, FollowFriendMessageComposer, GenericErrorEvent, GetGuestRoomMessageComposer, GetGuestRoomResultEvent, GetUserEventCatsMessageComposer, GetUserFlatCatsMessageComposer, HabboWebTools, LegacyExternalInterface, NavigatorHomeRoomEvent, NavigatorMetadataEvent, NavigatorOpenRoomCreatorEvent, NavigatorSearchEvent, RoomDataParser, RoomDoorbellAcceptedEvent, RoomEnterErrorEvent, RoomEntryInfoMessageEvent, RoomForwardEvent, RoomScoreEvent, RoomSettingsUpdatedEvent, SecurityLevel, UserFlatCatsEvent, UserInfoEvent, UserPermissionsEvent } from '@nitrots/nitro-renderer'; import { CanCreateRoomEventEvent, CantConnectMessageParser, DoorbellMessageEvent, FlatAccessDeniedMessageEvent, FlatCreatedEvent, FollowFriendMessageComposer, GenericErrorEvent, GetGuestRoomMessageComposer, GetGuestRoomResultEvent, GetUserEventCatsMessageComposer, GetUserFlatCatsMessageComposer, HabboWebTools, LegacyExternalInterface, NavigatorHomeRoomEvent, NavigatorMetadataEvent, NavigatorOpenRoomCreatorEvent, NavigatorSearchEvent, RoomDataParser, RoomDoorbellAcceptedEvent, RoomEnterErrorEvent, RoomEntryInfoMessageEvent, RoomForwardEvent, RoomScoreEvent, RoomSettingsUpdatedEvent, SecurityLevel, UserEventCatsEvent, UserFlatCatsEvent, UserInfoEvent, UserPermissionsEvent } from '@nitrots/nitro-renderer';
import { FC, useCallback } from 'react'; import { FC, useCallback } from 'react';
import { CreateLinkEvent, CreateRoomSession, DoorStateType, GetConfiguration, GetSessionDataManager, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer, TryVisitRoom, VisitDesktop } from '../../api'; import { CreateLinkEvent, CreateRoomSession, DoorStateType, GetConfiguration, GetSessionDataManager, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer, TryVisitRoom, VisitDesktop } from '../../api';
import { UseMessageEventHook } from '../../hooks'; import { UseMessageEventHook } from '../../hooks';
@ -6,7 +6,7 @@ import { useNavigatorContext } from './NavigatorContext';
export const NavigatorMessageHandler: FC<{}> = props => export const NavigatorMessageHandler: FC<{}> = props =>
{ {
const { setCategories = null, setTopLevelContext = null, topLevelContexts = null, setTopLevelContexts = null, setNavigatorData = null, setDoorData = null, setSearchResult = null } = useNavigatorContext(); const { setCategories = null, setEventCategories = null, setTopLevelContext = null, topLevelContexts = null, setTopLevelContexts = null, setNavigatorData = null, setDoorData = null, setSearchResult = null } = useNavigatorContext();
const onRoomSettingsUpdatedEvent = useCallback((event: RoomSettingsUpdatedEvent) => const onRoomSettingsUpdatedEvent = useCallback((event: RoomSettingsUpdatedEvent) =>
{ {
@ -317,6 +317,14 @@ export const NavigatorMessageHandler: FC<{}> = props =>
setCategories(parser.categories); setCategories(parser.categories);
}, [ setCategories ]); }, [ setCategories ]);
const onNavigatorEventCategoriesEvent = (event: UserEventCatsEvent) =>
{
const parser = event.getParser();
setEventCategories(parser.categories);
console.log(parser);
}
const onRoomCreatedEvent = useCallback((event: FlatCreatedEvent) => const onRoomCreatedEvent = useCallback((event: FlatCreatedEvent) =>
{ {
const parser = event.getParser(); const parser = event.getParser();
@ -428,6 +436,7 @@ export const NavigatorMessageHandler: FC<{}> = props =>
UseMessageEventHook(NavigatorMetadataEvent, onNavigatorMetadataEvent); UseMessageEventHook(NavigatorMetadataEvent, onNavigatorMetadataEvent);
UseMessageEventHook(NavigatorSearchEvent, onNavigatorSearchEvent); UseMessageEventHook(NavigatorSearchEvent, onNavigatorSearchEvent);
UseMessageEventHook(UserFlatCatsEvent, onNavigatorCategoriesEvent); UseMessageEventHook(UserFlatCatsEvent, onNavigatorCategoriesEvent);
UseMessageEventHook(UserEventCatsEvent, onNavigatorEventCategoriesEvent);
UseMessageEventHook(FlatCreatedEvent, onRoomCreatedEvent); UseMessageEventHook(FlatCreatedEvent, onRoomCreatedEvent);
UseMessageEventHook(NavigatorHomeRoomEvent, onNavigatorHomeRoomEvent); UseMessageEventHook(NavigatorHomeRoomEvent, onNavigatorHomeRoomEvent);
UseMessageEventHook(RoomEnterErrorEvent, onRoomEnterErrorEvent); UseMessageEventHook(RoomEnterErrorEvent, onRoomEnterErrorEvent);

View File

@ -1,5 +1,5 @@
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { ConvertGlobalRoomIdMessageComposer, HabboWebTools, ILinkEventTracker, LegacyExternalInterface, NavigatorCategoryDataParser, NavigatorInitComposer, NavigatorSearchComposer, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser, RoomSessionEvent } from '@nitrots/nitro-renderer'; import { ConvertGlobalRoomIdMessageComposer, HabboWebTools, ILinkEventTracker, LegacyExternalInterface, NavigatorCategoryDataParser, NavigatorEventCategoryDataParser, NavigatorInitComposer, NavigatorSearchComposer, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser, RoomSessionEvent } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useRef, useState } from 'react'; import { FC, useCallback, useEffect, useRef, useState } from 'react';
import { AddEventLinkTracker, DoorStateType, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api'; import { AddEventLinkTracker, DoorStateType, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api';
import { Base, Column, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; import { Base, Column, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common';
@ -25,6 +25,7 @@ export const NavigatorView: FC<{}> = props =>
const [ needsInit, setNeedsInit ] = useState(true); const [ needsInit, setNeedsInit ] = useState(true);
const [ needsSearch, setNeedsSearch ] = useState(false); const [ needsSearch, setNeedsSearch ] = useState(false);
const [ categories, setCategories ] = useState<NavigatorCategoryDataParser[]>(null); const [ categories, setCategories ] = useState<NavigatorCategoryDataParser[]>(null);
const [ eventCategories, setEventCategories ] = useState<NavigatorEventCategoryDataParser[]>(null);
const [ topLevelContext, setTopLevelContext ] = useState<NavigatorTopLevelContext>(null); const [ topLevelContext, setTopLevelContext ] = useState<NavigatorTopLevelContext>(null);
const [ topLevelContexts, setTopLevelContexts ] = useState<NavigatorTopLevelContext[]>(null); const [ topLevelContexts, setTopLevelContexts ] = useState<NavigatorTopLevelContext[]>(null);
const [ navigatorData, setNavigatorData ] = useSharedNavigatorData(); const [ navigatorData, setNavigatorData ] = useSharedNavigatorData();
@ -207,7 +208,7 @@ export const NavigatorView: FC<{}> = props =>
}, []); }, []);
return ( return (
<NavigatorContextProvider value={ { categories, setCategories, topLevelContext, setTopLevelContext, topLevelContexts, setTopLevelContexts, navigatorData, setNavigatorData, doorData, setDoorData, searchResult, setSearchResult } }> <NavigatorContextProvider value={ { categories, setCategories, eventCategories, setEventCategories, topLevelContext, setTopLevelContext, topLevelContexts, setTopLevelContexts, navigatorData, setNavigatorData, doorData, setDoorData, searchResult, setSearchResult } }>
<NavigatorMessageHandler /> <NavigatorMessageHandler />
{ isVisible && { isVisible &&
<NitroCardView uniqueKey="navigator" className="nitro-navigator"> <NitroCardView uniqueKey="navigator" className="nitro-navigator">