import { connect } from 'react-redux'; import ContentBody from './ContentBody'; import { getCatalog } from '../../redux/actions/catalog'; const mapStateToProps = state => { let pending = state.ui.pending; // NOTE: do this in a middleware didn't work if (!pending) { // case where we have no items (but not because there are no search results) if (!state.ui.showingSearchResults && state.catalog.length === 0) { pending = true; } // case where we only have ads and are still pending catalog items if (!state.ui.showingSearchResults && state.catalog.every(item => !item.inventory_number)) { pending = true; } } return { pending, catalogFetched: !!state.catalog.length }; }; const mapDispatchToProps = dispatch => { return { getCatalog: () => dispatch(getCatalog()) }; }; const ContentBodyContainer = connect(mapStateToProps, mapDispatchToProps)(ContentBody); export default ContentBodyContainer;