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:
@@ -1,7 +1,6 @@
|
|||||||
import { ClubGiftInfoParser, MarketplaceConfigurationMessageParser } from '@nitrots/nitro-renderer';
|
import { ClubGiftInfoParser } from '@nitrots/nitro-renderer';
|
||||||
|
|
||||||
export interface ICatalogOptions
|
export interface ICatalogOptions
|
||||||
{
|
{
|
||||||
clubGifts?: ClubGiftInfoParser;
|
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 { FC, useEffect, useState } from 'react';
|
||||||
import { FurnitureItem, LocalizeText, ProductTypeEnum, SendMessageComposer } from '../../../../../../api';
|
import { FurnitureItem, LocalizeText, ProductTypeEnum, SendMessageComposer } from '../../../../../../api';
|
||||||
import { Button, Column, Grid, LayoutFurniImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../../../common';
|
import { Button, Column, Grid, LayoutFurniImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../../../common';
|
||||||
import { CatalogPostMarketplaceOfferEvent } from '../../../../../../events';
|
import { CatalogPostMarketplaceOfferEvent } from '../../../../../../events';
|
||||||
import { useCatalog, useMessageEvent, useNotification, useUiEvent } from '../../../../../../hooks';
|
import { useMarketplaceConfiguration, useNotification, useUiEvent } from '../../../../../../hooks';
|
||||||
import { NitroInput } from '../../../../../../layout';
|
import { NitroInput } from '../../../../../../layout';
|
||||||
|
|
||||||
let isPostingMarketplaceOffer = false;
|
let isPostingMarketplaceOffer = false;
|
||||||
@@ -13,8 +13,7 @@ export const MarketplacePostOfferView: FC<{}> = props =>
|
|||||||
const [ item, setItem ] = useState<FurnitureItem>(null);
|
const [ item, setItem ] = useState<FurnitureItem>(null);
|
||||||
const [ askingPrice, setAskingPrice ] = useState(0);
|
const [ askingPrice, setAskingPrice ] = useState(0);
|
||||||
const [ tempAskingPrice, setTempAskingPrice ] = useState('0');
|
const [ tempAskingPrice, setTempAskingPrice ] = useState('0');
|
||||||
const { catalogOptions = null, setCatalogOptions = null } = useCatalog();
|
const { data: marketplaceConfiguration = null } = useMarketplaceConfiguration({ enabled: !!item });
|
||||||
const { marketplaceConfiguration = null } = catalogOptions;
|
|
||||||
const { showConfirm = null } = useNotification();
|
const { showConfirm = null } = useNotification();
|
||||||
|
|
||||||
const updateAskingPrice = (price: string) =>
|
const updateAskingPrice = (price: string) =>
|
||||||
@@ -28,29 +27,8 @@ export const MarketplacePostOfferView: FC<{}> = props =>
|
|||||||
setAskingPrice(parseInt(price));
|
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));
|
useUiEvent<CatalogPostMarketplaceOfferEvent>(CatalogPostMarketplaceOfferEvent.POST_MARKETPLACE, event => setItem(event.item));
|
||||||
|
|
||||||
useEffect(() =>
|
|
||||||
{
|
|
||||||
if(!item || marketplaceConfiguration) return;
|
|
||||||
|
|
||||||
SendMessageComposer(new GetMarketplaceConfigurationMessageComposer());
|
|
||||||
}, [ item, marketplaceConfiguration ]);
|
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
if(!item) return;
|
if(!item) return;
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ export * from './useCatalogPlaceMultipleItems';
|
|||||||
export * from './useCatalogSkipPurchaseConfirmation';
|
export * from './useCatalogSkipPurchaseConfirmation';
|
||||||
export * from './useClubOffers';
|
export * from './useClubOffers';
|
||||||
export * from './useGiftConfiguration';
|
export * from './useGiftConfiguration';
|
||||||
|
export * from './useMarketplaceConfiguration';
|
||||||
export * from './useSellablePetPalette';
|
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