Last active
June 27, 2019 07:11
-
-
Save Morganjackson/993c1f84095e0edee10c1ab6fe3a9afb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { compose } from 'redux'; | |
| import { graphql } from 'react-apollo'; | |
| import { connect } from 'react-redux'; | |
| import { remapSearchFilterFaceted } from '../../lib/config/api-mappings-elastic'; | |
| import { getQueryString } from '../../lib/config/api-endpoints-elastic'; | |
| import AGGREGATIONS_QUERY from '../graphql/queries/aggregations.graphql'; | |
| import LISTINGS_QUERY from '../graphql/queries/listings.graphql'; | |
| import LISTING_SEARCH from "../graphql/queries/listings-and-aggregations.graphql" | |
| const mapResultsToProps = ({ data, ownProps }) => { | |
| if (data.loading) return { isLoading: data.loading }; | |
| const { listingAggregations, listingSearch, loading } = data; | |
| const { facets, total, prices, inspections, auctions } = listingAggregations; | |
| const { listings } = listingSearch; | |
| return { | |
| isLoading: loading, | |
| facets, | |
| total, | |
| prices, | |
| inspections, | |
| auctions, | |
| listings, | |
| }; | |
| }; | |
| // Get required state to build query string | |
| const mapStateToProps = state => { | |
| const { listingsFilter: filter, listingsViewType: viewType, listingsByViewType } = state; | |
| const { page } = listingsByViewType.list; | |
| // Search results query | |
| const listingsSearch = remapSearchFilterFaceted(filter, state, page, viewType); | |
| const listingsSearchQuery = getQueryString(listingsSearch); | |
| // Aggregations Query | |
| const aggregations = remapSearchFilterFaceted(filter, state, page); | |
| const aggregationsQuery = getQueryString({ aggregations }); | |
| return { listingsSearchQuery, aggregationsQuery }; | |
| }; | |
| const withBffData = graphql(LISTING_SEARCH, { | |
| props: mapResultsToProps, | |
| options: ({ gqlQueryString }) => ({ variables: { query: gqlQueryString } }), | |
| }); | |
| const reduxWrapper = connect(mapStateToProps); | |
| export default compose(reduxWrapper, withBffData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment