Skip to content

Commit

Permalink
refactor: remove explicit sponsored product call
Browse files Browse the repository at this point in the history
  • Loading branch information
hcaula committed Apr 19, 2024
1 parent a38c587 commit 372cceb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 77 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Always send `showSponsored` as true to the backend.
- Remove explicit call for `sponsoredProduct`, always relying on the backend return value.

## [3.130.2] - 2024-03-08

## [3.130.1] - 2024-03-08
Expand Down
7 changes: 1 addition & 6 deletions react/SearchContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ const SearchContent = () => {
const { searchQuery, showFacets, lazyItemsRemaining } = useSearchPage()
const { mobileLayout, showContentLoader } = useSearchPageState()

const searchProducts =
const products =
path(['data', 'productSearch', 'products'], searchQuery) || []

const sponsoredProducts =
path(['data', 'sponsoredProducts'], searchQuery) || []

const products = sponsoredProducts.concat(searchProducts)

const redirect = path(['data', 'productSearch', 'redirect'], searchQuery)

/* No need to show the spinner if it is loading because
Expand Down
47 changes: 2 additions & 45 deletions react/components/SearchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useRuntime } from 'vtex.render-runtime'
import productSearchQuery from 'vtex.store-resources/QueryProductSearchV3'
import searchMetadataQuery from 'vtex.store-resources/QuerySearchMetadataV2'
import facetsQuery from 'vtex.store-resources/QueryFacetsV2'
import sponsoredProductsQuery from 'vtex.store-resources/QuerySponsoredProducts'
import { equals } from 'ramda'
import { canUseDOM } from 'exenv'

Expand All @@ -13,7 +12,6 @@ import {
detachFiltersByType,
buildQueryArgsFromSelectedFacets,
} from '../utils/compatibilityLayer'
import shouldSkipSponsoredProducts from '../utils/shouldSkipSponsoredProducts'
import { FACETS_RENDER_THRESHOLD } from '../constants/filterConstants'
import useRedirect from '../hooks/useRedirect'
import useSession from '../hooks/useSession'
Expand Down Expand Up @@ -170,27 +168,7 @@ const useCorrectSearchStateVariables = (
return result
}

const sponsoredProductsResult = (
sponsoredProductsLoading,
sponsoredProductsError,
sponsoredProducts
) => {
const showSponsoredProducts =
!sponsoredProductsLoading && !sponsoredProductsError

const sponsoredProductsResponse = showSponsoredProducts
? sponsoredProducts
: []

return sponsoredProductsResponse
}

const useQueries = (
variables,
facetsArgs,
price,
sponsoredProductsBehavior = 'sync'
) => {
const useQueries = (variables, facetsArgs, price) => {
const { getSettings, query: runtimeQuery } = useRuntime()
const settings = getSettings('vtex.store')

Expand All @@ -199,31 +177,11 @@ const useQueries = (
const productSearchResult = useQuery(productSearchQuery, {
variables: {
...variables,
showSponsored:
settings?.fetchSponsoredProductsOnSearch &&
sponsoredProductsBehavior === 'sync',
showSponsored: true,
variant: getCookie('sp-variant'),
},
})

const {
data: { sponsoredProducts } = [],
loading: sponsoredProductLoading,
error: sponsoredProductsError,
} = useQuery(sponsoredProductsQuery, {
variables: {
...variables,
anonymousId: getCookie('biggy-anonymous'),
},
skip: shouldSkipSponsoredProducts(sponsoredProductsBehavior, settings),
})

const sponsoredProductsReturn = sponsoredProductsResult(
sponsoredProductLoading,
sponsoredProductsError,
sponsoredProducts
)

const {
refetch: searchRefetch,
loading: searchLoading,
Expand Down Expand Up @@ -313,7 +271,6 @@ const useQueries = (
sampling: facets?.sampling,
},
searchMetadata,
sponsoredProducts: sponsoredProductsReturn,
},
productSearchResult,
refetch,
Expand Down
26 changes: 0 additions & 26 deletions react/utils/shouldSkipSponsoredProducts.ts

This file was deleted.

0 comments on commit 372cceb

Please sign in to comment.