mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 15:36:18 +00:00
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:
@@ -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
|
||||
});
|
||||
Reference in New Issue
Block a user