From 28f4b9fd5325abb2200b191d1986c0d45716d1b3 Mon Sep 17 00:00:00 2001 From: dank074 Date: Wed, 5 Jan 2022 11:56:39 -0600 Subject: [PATCH] add missing packet listeners --- src/views/catalog/CatalogMessageHandler.tsx | 44 ++++++++++++++++++- src/views/catalog/CatalogView.tsx | 10 ++++- src/views/catalog/reducers/CatalogReducer.tsx | 13 +++++- .../post-offer/MarketplacePostOfferView.tsx | 12 +++-- 4 files changed, 71 insertions(+), 8 deletions(-) diff --git a/src/views/catalog/CatalogMessageHandler.tsx b/src/views/catalog/CatalogMessageHandler.tsx index 89c1e6fc..e536a6a9 100644 --- a/src/views/catalog/CatalogMessageHandler.tsx +++ b/src/views/catalog/CatalogMessageHandler.tsx @@ -1,12 +1,15 @@ -import { ApproveNameMessageEvent, CatalogPageMessageEvent, CatalogPagesListEvent, CatalogPublishedMessageEvent, GiftReceiverNotFoundEvent, GiftWrappingConfigurationEvent, HabboClubOffersMessageEvent, LimitedEditionSoldOutEvent, ProductOfferEvent, PurchaseErrorMessageEvent, PurchaseNotAllowedMessageEvent, PurchaseOKMessageEvent, SellablePetPalettesMessageEvent, UserSubscriptionEvent } from '@nitrots/nitro-renderer'; +import { ApproveNameMessageEvent, CatalogPageMessageEvent, CatalogPagesListEvent, CatalogPublishedMessageEvent, GiftReceiverNotFoundEvent, GiftWrappingConfigurationEvent, HabboClubOffersMessageEvent, LimitedEditionSoldOutEvent, MarketplaceConfigurationEvent, MarketplaceMakeOfferResult, ProductOfferEvent, PurchaseErrorMessageEvent, PurchaseNotAllowedMessageEvent, PurchaseOKMessageEvent, SellablePetPalettesMessageEvent, UserSubscriptionEvent } from '@nitrots/nitro-renderer'; import { GuildMembershipsMessageEvent } from '@nitrots/nitro-renderer/src/nitro/communication/messages/incoming/user/GuildMembershipsMessageEvent'; import { FC, useCallback } from 'react'; +import { LocalizeText } from '../../api'; import { CatalogNameResultEvent, CatalogPurchaseFailureEvent } from '../../events'; import { CatalogGiftReceiverNotFoundEvent } from '../../events/catalog/CatalogGiftReceiverNotFoundEvent'; import { CatalogPurchasedEvent } from '../../events/catalog/CatalogPurchasedEvent'; import { CatalogPurchaseSoldOutEvent } from '../../events/catalog/CatalogPurchaseSoldOutEvent'; import { dispatchUiEvent } from '../../hooks/events/ui/ui-event'; import { CreateMessageHook } from '../../hooks/messages/message-event'; +import { NotificationAlertType } from '../notification-center/common/NotificationAlertType'; +import { NotificationUtilities } from '../notification-center/common/NotificationUtilities'; import { CatalogMessageHandlerProps } from './CatalogMessageHandler.types'; import { CatalogPetPalette } from './common/CatalogPetPalette'; import { SubscriptionInfo } from './common/SubscriptionInfo'; @@ -164,6 +167,43 @@ export const CatalogMessageHandler: FC = props => }); }, [ dispatchCatalogState ]); + const onMarketplaceMakeOfferResult = useCallback((event: MarketplaceMakeOfferResult) => + { + const parser = event.getParser(); + + if(!parser) return; + + let title = ''; + if(parser.result === 1) + { + title = LocalizeText('inventory.marketplace.result.title.success'); + } + else + { + title = LocalizeText('inventory.marketplace.result.title.failure'); + } + + const message = LocalizeText(`inventory.marketplace.result.${parser.result}`); + + NotificationUtilities.simpleAlert(message, NotificationAlertType.DEFAULT, null, null, title); + }, []); + + const onMarketplaceConfigurationEvent = useCallback((event: MarketplaceConfigurationEvent) => + { + const parser = event.getParser(); + + if(!parser) return; + + console.log(parser); + + dispatchCatalogState({ + type: CatalogActions.SET_MARKETPLACE_CONFIGURATION, + payload: { + marketplaceConfiguration: parser + } + }); + }, [dispatchCatalogState]); + CreateMessageHook(CatalogPagesListEvent, onCatalogPagesListEvent); CreateMessageHook(CatalogPageMessageEvent, onCatalogPageMessageEvent); CreateMessageHook(PurchaseOKMessageEvent, onPurchaseOKMessageEvent); @@ -179,6 +219,8 @@ export const CatalogMessageHandler: FC = props => CreateMessageHook(UserSubscriptionEvent, onUserSubscriptionEvent); CreateMessageHook(CatalogPublishedMessageEvent, onCatalogPublishedMessageEvent); CreateMessageHook(GiftWrappingConfigurationEvent, onGiftWrappingConfigurationEvent); + CreateMessageHook(MarketplaceMakeOfferResult, onMarketplaceMakeOfferResult); + CreateMessageHook(MarketplaceConfigurationEvent, onMarketplaceConfigurationEvent); return null; } diff --git a/src/views/catalog/CatalogView.tsx b/src/views/catalog/CatalogView.tsx index cbe704c8..739f126d 100644 --- a/src/views/catalog/CatalogView.tsx +++ b/src/views/catalog/CatalogView.tsx @@ -1,8 +1,9 @@ -import { GetCatalogIndexComposer, GetCatalogPageComposer, GetGiftWrappingConfigurationComposer, ILinkEventTracker, INodeData, RoomPreviewer } from '@nitrots/nitro-renderer'; +import { GetCatalogIndexComposer, GetCatalogPageComposer, GetGiftWrappingConfigurationComposer, GetMarketplaceConfigurationMessageComposer, ILinkEventTracker, INodeData, RoomPreviewer } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useReducer, useState } from 'react'; import { AddEventLinkTracker, GetRoomEngine, LocalizeText, RemoveLinkEventTracker } from '../../api'; import { CREDITS, PlaySound } from '../../api/utils/PlaySound'; import { CatalogEvent } from '../../events'; +import { UseMountEffect } from '../../hooks'; import { useUiEvent } from '../../hooks/events/ui/ui-event'; import { SendMessageHook } from '../../hooks/messages/message-event'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView, NitroLayoutGrid, NitroLayoutGridColumn } from '../../layout'; @@ -115,7 +116,6 @@ export const CatalogView: FC = props => if(loadCatalog) { SendMessageHook(new GetCatalogIndexComposer(CatalogMode.MODE_NORMAL)); - SendMessageHook(new GetGiftWrappingConfigurationComposer()); return; } @@ -189,6 +189,12 @@ export const CatalogView: FC = props => } }, []); + UseMountEffect(() => + { + SendMessageHook(new GetMarketplaceConfigurationMessageComposer()); + SendMessageHook(new GetGiftWrappingConfigurationComposer()); + }); + const currentNavigationPage = ((searchResult && searchResult.page) || currentTab); const navigationHidden = !!(pageParser && pageParser.frontPageItems.length); diff --git a/src/views/catalog/reducers/CatalogReducer.tsx b/src/views/catalog/reducers/CatalogReducer.tsx index 35b1daf3..87eba150 100644 --- a/src/views/catalog/reducers/CatalogReducer.tsx +++ b/src/views/catalog/reducers/CatalogReducer.tsx @@ -1,4 +1,4 @@ -import { CatalogPageMessageOfferData, CatalogPageMessageParser, ClubOfferData, GiftWrappingConfigurationParser, INodeData } from '@nitrots/nitro-renderer'; +import { CatalogPageMessageOfferData, CatalogPageMessageParser, ClubOfferData, GiftWrappingConfigurationParser, INodeData, MarketplaceConfigurationMessageParser } from '@nitrots/nitro-renderer'; import { HabboGroupEntryData } from '@nitrots/nitro-renderer/src/nitro/communication/messages/parser/user/HabboGroupEntryData'; import { Reducer } from 'react'; import { CatalogPetPalette } from '../common/CatalogPetPalette'; @@ -19,6 +19,7 @@ export interface ICatalogState clubOffers: ClubOfferData[]; subscriptionInfo: SubscriptionInfo; giftConfiguration: GiftWrappingConfiguration; + marketplaceConfiguration: MarketplaceConfigurationMessageParser; } export interface ICatalogAction @@ -36,6 +37,7 @@ export interface ICatalogAction clubOffers?: ClubOfferData[]; subscriptionInfo?: SubscriptionInfo; giftConfiguration?: GiftWrappingConfigurationParser; + marketplaceConfiguration?: MarketplaceConfigurationMessageParser; } } @@ -52,6 +54,7 @@ export class CatalogActions public static SET_SEARCH_RESULT: string = 'CA_SET_SEARCH_RESULT'; public static SET_SUBSCRIPTION_INFO: string = 'CA_SET_SUBSCRIPTION_INFO'; public static SET_GIFT_CONFIGURATION: string = 'CA_SET_GIFT_CONFIGURATION'; + public static SET_MARKETPLACE_CONFIGURATION: string = 'CA_SET_MARKETPLACE_CONFIGURATION'; } export const initialCatalog: ICatalogState = { @@ -65,7 +68,8 @@ export const initialCatalog: ICatalogState = { petPalettes: [], clubOffers: null, subscriptionInfo: new SubscriptionInfo(), - giftConfiguration: null + giftConfiguration: null, + marketplaceConfiguration: null } export const CatalogReducer: Reducer = (state, action) => @@ -160,6 +164,11 @@ export const CatalogReducer: Reducer = (state, ac return { ...state, giftConfiguration }; } + case CatalogActions.SET_MARKETPLACE_CONFIGURATION: { + let marketplaceConfiguration = (action.payload.marketplaceConfiguration || state.marketplaceConfiguration || null); + + return { ...state, marketplaceConfiguration } + } default: return state; } diff --git a/src/views/catalog/views/page/layout/marketplace/post-offer/MarketplacePostOfferView.tsx b/src/views/catalog/views/page/layout/marketplace/post-offer/MarketplacePostOfferView.tsx index 445cd5cb..80d9e63c 100644 --- a/src/views/catalog/views/page/layout/marketplace/post-offer/MarketplacePostOfferView.tsx +++ b/src/views/catalog/views/page/layout/marketplace/post-offer/MarketplacePostOfferView.tsx @@ -6,11 +6,13 @@ import { SendMessageHook, useUiEvent } from '../../../../../../../hooks'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView, NitroLayoutFlex } from '../../../../../../../layout'; import { FurnitureItem } from '../../../../../../inventory/common/FurnitureItem'; import { NotificationUtilities } from '../../../../../../notification-center/common/NotificationUtilities'; +import { useCatalogContext } from '../../../../../context/CatalogContext'; export const MarketplacePostOfferView : FC<{}> = props => { const [ item, setItem ] = useState(null); const [ askingPrice, setAskingPrice ] = useState(0); + const { catalogState = null, dispatchCatalogState = null } = useCatalogContext(); const close = useCallback(() => { @@ -91,17 +93,21 @@ export const MarketplacePostOfferView : FC<{}> = props =>
- { LocalizeText('inventory.marketplace.make_offer.expiration_info') } + { LocalizeText('inventory.marketplace.make_offer.expiration_info', ['time'], [catalogState.marketplaceConfiguration.offerTime.toString()]) }
{ LocalizeText('inventory.marketplace.make_offer.price_request') }
setAskingPrice(event.target.valueAsNumber) } />
- { askingPrice <= 0 || isNaN(askingPrice) ? LocalizeText('inventory.marketplace.make_offer.min_price', ['minprice'], ['1']) : LocalizeText('inventory.marketplace.make_offer.final_price', ['commission', 'finalprice'], ['1', (askingPrice + 1).toString()])} + { (askingPrice < catalogState.marketplaceConfiguration.minimumPrice || isNaN(askingPrice)) && LocalizeText('inventory.marketplace.make_offer.min_price', ['minprice'], [catalogState.marketplaceConfiguration.minimumPrice.toString()]) } + { askingPrice > catalogState.marketplaceConfiguration.maximumPrice && !isNaN(askingPrice) && + LocalizeText('inventory.marketplace.make_offer.max_price', ['maxprice'], [catalogState.marketplaceConfiguration.maximumPrice.toString()]) + } + { !(askingPrice < catalogState.marketplaceConfiguration.minimumPrice || askingPrice > catalogState.marketplaceConfiguration.maximumPrice || isNaN(askingPrice)) && LocalizeText('inventory.marketplace.make_offer.final_price', ['commission', 'finalprice'], [catalogState.marketplaceConfiguration.commission.toString(), (askingPrice + catalogState.marketplaceConfiguration.commission).toString()])}
-