mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 15:40:51 +01:00
listen for event categories
This commit is contained in:
parent
269f1c1ad0
commit
f913d03185
@ -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 { LocalizeText, SendMessageComposer } from '../../../../../api';
|
||||
import { Base, Column, Text } from '../../../../../common';
|
||||
import { Base, Button, Column, Text } from '../../../../../common';
|
||||
import { UseMessageEventHook } from '../../../../../hooks';
|
||||
import { CatalogLayoutProps } from './CatalogLayout.types';
|
||||
|
||||
@ -10,10 +10,11 @@ export const CatalogLayoutRoomAdsView: FC<CatalogLayoutProps> = props =>
|
||||
const { page = null } = props;
|
||||
const [ eventName, setEventName ] = 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 [ 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) =>
|
||||
{
|
||||
@ -23,7 +24,7 @@ export const CatalogLayoutRoomAdsView: FC<CatalogLayoutProps> = props =>
|
||||
|
||||
setAvailableRooms(parser.rooms);
|
||||
}, []);
|
||||
|
||||
|
||||
UseMessageEventHook(RoomAdPurchaseInfoEvent, onRoomAdPurchaseInfoEvent);
|
||||
|
||||
const purchaseAd = useCallback(() =>
|
||||
@ -33,29 +34,45 @@ export const CatalogLayoutRoomAdsView: FC<CatalogLayoutProps> = props =>
|
||||
const flatId = roomId;
|
||||
const name = eventName;
|
||||
const desc = eventDesc;
|
||||
const categoryId = -1;
|
||||
const catId = categoryId;
|
||||
|
||||
SendMessageComposer(new PurchaseRoomAdMessageComposer(pageId, offerId, flatId, name, extended, desc, categoryId))
|
||||
}, [eventDesc, eventName, extended, page.offers, page.pageId, roomId]);
|
||||
SendMessageComposer(new PurchaseRoomAdMessageComposer(pageId, offerId, flatId, name, extended, desc, catId))
|
||||
}, [ categoryId, eventDesc, eventName, extended, page.offers, page.pageId, roomId ]);
|
||||
|
||||
|
||||
const onUserEventCatsEvent = (event: UserEventCatsEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
setCategories(parser.categories);
|
||||
}
|
||||
|
||||
UseMessageEventHook(UserEventCatsEvent, onUserEventCatsEvent);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
SendMessageComposer(new GetRoomAdPurchaseInfoComposer());
|
||||
//SendMessageComposer(new GetUserEventCatsMessageComposer());
|
||||
// TODO: someone needs to fix this for morningstar
|
||||
SendMessageComposer(new GetUserEventCatsMessageComposer());
|
||||
}, []);
|
||||
|
||||
return (<>
|
||||
<Text bold center>{LocalizeText('roomad.catalog_header')}</Text>
|
||||
<Column size={12} overflow="hidden" className='text-black'>
|
||||
<Base>{LocalizeText('roomad.catalog_text')}</Base>
|
||||
<Base className='bg-muted rounded p-1'>
|
||||
<Text bold center>{ LocalizeText('roomad.catalog_header') }</Text>
|
||||
<Column size={ 12 } overflow="hidden" className="text-black">
|
||||
<Base>{ LocalizeText('roomad.catalog_text') }</Base>
|
||||
<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 }>
|
||||
<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) } />
|
||||
</Column>
|
||||
<Column gap={ 1 }>
|
||||
< Text bold>{LocalizeText('roomad.catalog_description')}</Text>
|
||||
<textarea className='form-control form-control-sm' maxLength={ 64 } value={ eventDesc } onChange={ event => setEventDesc(event.target.value) }/>
|
||||
< Text bold>{ LocalizeText('roomad.catalog_description') }</Text>
|
||||
<textarea className="form-control form-control-sm" maxLength={ 64 } value={ eventDesc } onChange={ event => setEventDesc(event.target.value) }/>
|
||||
</Column>
|
||||
<Column gap={ 1 }>
|
||||
<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>) }
|
||||
</select>
|
||||
</Column>
|
||||
<Column gap={ 1 }>
|
||||
<Button onClick={ purchaseAd }>{ LocalizeText('buy') }</Button>
|
||||
</Column>
|
||||
</Base>
|
||||
</Column>
|
||||
</>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
interface INavigatorCategory {
|
||||
id: number;
|
||||
name: string;
|
||||
visible: boolean;
|
||||
}
|
||||
|
@ -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 { INavigatorData } from '../../api';
|
||||
|
||||
@ -6,6 +6,8 @@ interface INavigatorContext
|
||||
{
|
||||
categories: NavigatorCategoryDataParser[];
|
||||
setCategories: Dispatch<SetStateAction<NavigatorCategoryDataParser[]>>;
|
||||
eventCategories: NavigatorEventCategoryDataParser[];
|
||||
setEventCategories: Dispatch<SetStateAction<NavigatorEventCategoryDataParser[]>>;
|
||||
topLevelContext: NavigatorTopLevelContext;
|
||||
setTopLevelContext: Dispatch<SetStateAction<NavigatorTopLevelContext>>;
|
||||
topLevelContexts: NavigatorTopLevelContext[];
|
||||
@ -22,6 +24,8 @@ const NavigatorContext = createContext<INavigatorContext>({
|
||||
categories: null,
|
||||
setCategories: null,
|
||||
topLevelContext: null,
|
||||
setEventCategories: null,
|
||||
eventCategories: null,
|
||||
setTopLevelContext: null,
|
||||
topLevelContexts: null,
|
||||
setTopLevelContexts: null,
|
||||
|
@ -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 { CreateLinkEvent, CreateRoomSession, DoorStateType, GetConfiguration, GetSessionDataManager, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer, TryVisitRoom, VisitDesktop } from '../../api';
|
||||
import { UseMessageEventHook } from '../../hooks';
|
||||
@ -6,7 +6,7 @@ import { useNavigatorContext } from './NavigatorContext';
|
||||
|
||||
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) =>
|
||||
{
|
||||
@ -317,6 +317,14 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
setCategories(parser.categories);
|
||||
}, [ setCategories ]);
|
||||
|
||||
const onNavigatorEventCategoriesEvent = (event: UserEventCatsEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
setEventCategories(parser.categories);
|
||||
console.log(parser);
|
||||
}
|
||||
|
||||
const onRoomCreatedEvent = useCallback((event: FlatCreatedEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
@ -428,6 +436,7 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
UseMessageEventHook(NavigatorMetadataEvent, onNavigatorMetadataEvent);
|
||||
UseMessageEventHook(NavigatorSearchEvent, onNavigatorSearchEvent);
|
||||
UseMessageEventHook(UserFlatCatsEvent, onNavigatorCategoriesEvent);
|
||||
UseMessageEventHook(UserEventCatsEvent, onNavigatorEventCategoriesEvent);
|
||||
UseMessageEventHook(FlatCreatedEvent, onRoomCreatedEvent);
|
||||
UseMessageEventHook(NavigatorHomeRoomEvent, onNavigatorHomeRoomEvent);
|
||||
UseMessageEventHook(RoomEnterErrorEvent, onRoomEnterErrorEvent);
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 { AddEventLinkTracker, DoorStateType, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api';
|
||||
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 [ needsSearch, setNeedsSearch ] = useState(false);
|
||||
const [ categories, setCategories ] = useState<NavigatorCategoryDataParser[]>(null);
|
||||
const [ eventCategories, setEventCategories ] = useState<NavigatorEventCategoryDataParser[]>(null);
|
||||
const [ topLevelContext, setTopLevelContext ] = useState<NavigatorTopLevelContext>(null);
|
||||
const [ topLevelContexts, setTopLevelContexts ] = useState<NavigatorTopLevelContext[]>(null);
|
||||
const [ navigatorData, setNavigatorData ] = useSharedNavigatorData();
|
||||
@ -59,7 +60,7 @@ export const NavigatorView: FC<{}> = props =>
|
||||
if(!isReady)
|
||||
{
|
||||
setNeedsSearch(true);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,7 +81,7 @@ export const NavigatorView: FC<{}> = props =>
|
||||
}
|
||||
|
||||
if(!topLevelContext) return;
|
||||
|
||||
|
||||
sendSearch('', topLevelContext.code);
|
||||
}, [ isReady, searchResult, topLevelContext, sendSearch ]);
|
||||
|
||||
@ -154,7 +155,7 @@ export const NavigatorView: FC<{}> = props =>
|
||||
setNeedsSearch(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, [ isVisible, navigatorData ]);
|
||||
|
||||
useEffect(() =>
|
||||
@ -207,7 +208,7 @@ export const NavigatorView: FC<{}> = props =>
|
||||
}, []);
|
||||
|
||||
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 />
|
||||
{ isVisible &&
|
||||
<NitroCardView uniqueKey="navigator" className="nitro-navigator">
|
||||
|
Loading…
Reference in New Issue
Block a user