useMarketplaceConfiguration: lift the marketplace config self-fetch

MarketplacePostOfferView was both *the* fetcher and the listener for
MarketplaceConfigurationEvent — it dispatched
GetMarketplaceConfigurationMessageComposer from one effect when item
was set, then routed the response through setCatalogOptions.

useCatalog never touched the field; it was passing through catalogOptions
purely as a transport mechanism for this single component to talk to
itself. Replace with useMarketplaceConfiguration() — staleTime Infinity
(server-side constants for a session), enabled on item, single tidy
data path.

Drops marketplaceConfiguration from ICatalogOptions; with petPalettes
out too, ICatalogOptions is now just { clubGifts }. clubGifts is the
last one and needs invalidation (server pushes ClubGiftInfoEvent after
SelectClubGiftComposer) so it stays put until useNitroEventInvalidator
companion lands.
This commit is contained in:
simoleo89
2026-05-11 22:32:35 +02:00
parent 3947781495
commit 9a807bf335
4 changed files with 33 additions and 27 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
import { ClubGiftInfoParser, MarketplaceConfigurationMessageParser } from '@nitrots/nitro-renderer';
import { ClubGiftInfoParser } from '@nitrots/nitro-renderer';
export interface ICatalogOptions
{
clubGifts?: ClubGiftInfoParser;
marketplaceConfiguration?: MarketplaceConfigurationMessageParser;
}
@@ -1,9 +1,9 @@
import { GetMarketplaceConfigurationMessageComposer, MakeOfferMessageComposer, MarketplaceConfigurationEvent } from '@nitrots/nitro-renderer';
import { MakeOfferMessageComposer } from '@nitrots/nitro-renderer';
import { FC, useEffect, useState } from 'react';
import { FurnitureItem, LocalizeText, ProductTypeEnum, SendMessageComposer } from '../../../../../../api';
import { Button, Column, Grid, LayoutFurniImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../../../common';
import { CatalogPostMarketplaceOfferEvent } from '../../../../../../events';
import { useCatalog, useMessageEvent, useNotification, useUiEvent } from '../../../../../../hooks';
import { useMarketplaceConfiguration, useNotification, useUiEvent } from '../../../../../../hooks';
import { NitroInput } from '../../../../../../layout';
let isPostingMarketplaceOffer = false;
@@ -13,8 +13,7 @@ export const MarketplacePostOfferView: FC<{}> = props =>
const [ item, setItem ] = useState<FurnitureItem>(null);
const [ askingPrice, setAskingPrice ] = useState(0);
const [ tempAskingPrice, setTempAskingPrice ] = useState('0');
const { catalogOptions = null, setCatalogOptions = null } = useCatalog();
const { marketplaceConfiguration = null } = catalogOptions;
const { data: marketplaceConfiguration = null } = useMarketplaceConfiguration({ enabled: !!item });
const { showConfirm = null } = useNotification();
const updateAskingPrice = (price: string) =>
@@ -28,29 +27,8 @@ export const MarketplacePostOfferView: FC<{}> = props =>
setAskingPrice(parseInt(price));
};
useMessageEvent<MarketplaceConfigurationEvent>(MarketplaceConfigurationEvent, event =>
{
const parser = event.getParser();
setCatalogOptions(prevValue =>
{
const newValue = { ...prevValue };
newValue.marketplaceConfiguration = parser;
return newValue;
});
});
useUiEvent<CatalogPostMarketplaceOfferEvent>(CatalogPostMarketplaceOfferEvent.POST_MARKETPLACE, event => setItem(event.item));
useEffect(() =>
{
if(!item || marketplaceConfiguration) return;
SendMessageComposer(new GetMarketplaceConfigurationMessageComposer());
}, [ item, marketplaceConfiguration ]);
useEffect(() =>
{
if(!item) return;
+1
View File
@@ -4,4 +4,5 @@ export * from './useCatalogPlaceMultipleItems';
export * from './useCatalogSkipPurchaseConfirmation';
export * from './useClubOffers';
export * from './useGiftConfiguration';
export * from './useMarketplaceConfiguration';
export * from './useSellablePetPalette';
@@ -0,0 +1,28 @@
import { GetMarketplaceConfigurationMessageComposer, MarketplaceConfigurationEvent, MarketplaceConfigurationMessageParser } from '@nitrots/nitro-renderer';
import { UseQueryResult } from '@tanstack/react-query';
import { useNitroQuery } from '../../api/nitro-query';
/**
* Marketplace configuration (commission rates, min/max ask, etc.) as
* returned by GetMarketplaceConfigurationMessageComposer →
* MarketplaceConfigurationEvent. Cached at session level — the values
* are server-side constants for the duration of a session.
*
* Replaces the previous pattern where MarketplacePostOfferView
* stuffed the parser into catalogOptions.marketplaceConfiguration
* via setCatalogOptions inside its own listener, and dispatched
* GetMarketplaceConfigurationMessageComposer from an effect that
* checked the same field as the cache. With useNitroQuery, the cache
* is React Query's; the component just reads `data`.
*/
export const useMarketplaceConfiguration = (
options: { enabled?: boolean } = {}
): UseQueryResult<MarketplaceConfigurationMessageParser> =>
useNitroQuery<MarketplaceConfigurationEvent, MarketplaceConfigurationMessageParser>({
key: [ 'nitro', 'catalog', 'marketplaceConfiguration' ],
request: () => new GetMarketplaceConfigurationMessageComposer(),
parser: MarketplaceConfigurationEvent,
select: event => event.getParser(),
enabled: options.enabled,
staleTime: Infinity
});