mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 05:00:43 +10:00
getMarketplaceEntities selector: full Redux store state as param
This commit is contained in:
parent
d42957de2a
commit
1f25e63d60
4 changed files with 7 additions and 14 deletions
|
|
@ -193,7 +193,6 @@ InboxPageComponent.propTypes = {
|
|||
};
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const marketplaceData = state.marketplaceData;
|
||||
const {
|
||||
fetchInProgress,
|
||||
fetchOrdersOrSalesError,
|
||||
|
|
@ -206,7 +205,7 @@ const mapStateToProps = state => {
|
|||
fetchInProgress,
|
||||
fetchOrdersOrSalesError,
|
||||
pagination,
|
||||
transactions: getMarketplaceEntities(marketplaceData, transactionRefs),
|
||||
transactions: getMarketplaceEntities(state, transactionRefs),
|
||||
currentUserHasListings,
|
||||
currentUserHasListingsError,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -67,10 +67,7 @@ const mapStateToProps = state => {
|
|||
const { showListingError: showOrderError } = state.ListingPage;
|
||||
const { currentUser } = state.user;
|
||||
|
||||
const transactions = getMarketplaceEntities(
|
||||
state.marketplaceData,
|
||||
transactionRef ? [transactionRef] : []
|
||||
);
|
||||
const transactions = getMarketplaceEntities(state, transactionRef ? [transactionRef] : []);
|
||||
const transaction = transactions.length > 0 ? transactions[0] : null;
|
||||
|
||||
return { transaction, showOrderError, currentUser };
|
||||
|
|
|
|||
|
|
@ -85,10 +85,7 @@ const mapStateToProps = state => {
|
|||
const { showListingError: showSaleError } = state.ListingPage;
|
||||
const { currentUser } = state.user;
|
||||
|
||||
const transactions = getMarketplaceEntities(
|
||||
state.marketplaceData,
|
||||
transactionRef ? [transactionRef] : []
|
||||
);
|
||||
const transactions = getMarketplaceEntities(state, transactionRef ? [transactionRef] : []);
|
||||
const transaction = transactions.length > 0 ? transactions[0] : null;
|
||||
|
||||
return { transaction, showSaleError, currentUser };
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@ export const getListingsById = (state, listingIds) => {
|
|||
/**
|
||||
* Get the denormalised entities from the given entity references.
|
||||
*
|
||||
* @param {Object} marketplaceData the state part of the Redux store
|
||||
* for this reducer
|
||||
* @param {Object} state the full Redux store
|
||||
*
|
||||
* @param {Array<{ id, type }} entityRefs References to entities that
|
||||
* we want to query from the data. Currently we expect that all the
|
||||
|
|
@ -58,11 +57,12 @@ export const getListingsById = (state, listingIds) => {
|
|||
*
|
||||
* @return {Array<Object>} denormalised entities
|
||||
*/
|
||||
export const getMarketplaceEntities = (marketplaceData, entityRefs) => {
|
||||
export const getMarketplaceEntities = (state, entityRefs) => {
|
||||
const { entities } = state.marketplaceData;
|
||||
const type = entityRefs.length > 0 ? entityRefs[0].type : null;
|
||||
const ids = entityRefs.map(ref => ref.id);
|
||||
try {
|
||||
return denormalisedEntities(marketplaceData.entities, type, ids);
|
||||
return denormalisedEntities(entities, type, ids);
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue