Skip to content

Commit

Permalink
fix: remove "exists-in-wishlist" logic from search results
Browse files Browse the repository at this point in the history
the wishlist store initially downloads only product counts. the actual products
are loaded later on demand, because that's a slow request.

the problem is if you search the wishlist while the actual wishlist products
aren't loaded yet, every search result will appear as if it's not in the
wishlist (heart icon instead of heart_fill)
  • Loading branch information
sethidden committed Jun 2, 2022
1 parent c1637ea commit 1742f45
Showing 1 changed file with 8 additions and 33 deletions.
41 changes: 8 additions & 33 deletions packages/theme/components/Header/SearchBar/SearchResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
>
<div class="results-listing">
<SfProductCard
v-for="(product, index) in searchResultsWithWishlistInfo"
v-for="(product, index) in searchResults"
:key="index"
class="result-card"
image-tag="nuxt-img"
Expand All @@ -59,22 +59,16 @@
localePath(
`/p/${productGetters.getProductSku(
product
)}${productGetters.getSlug(
product,
product.categories[0]
)}`
)}${productGetters.getSlug(product, product.categories[0])}`
)
"
:wishlist-icon="isAuthenticated ? 'heart' : ''"
:is-in-wishlist-icon="isAuthenticated ? 'heart_fill' : ''"
:is-in-wishlist="product.isInWishlist"
@click:wishlist="addOrRemoveWishlistItem(product)"
:wishlist-icon="false"
/>
</div>
</SfScrollable>
<div class="results--mobile smartphone-only">
<SfProductCard
v-for="(product, index) in searchResultsWithWishlistInfo"
v-for="(product, index) in searchResults"
:key="index"
class="result-card"
image-tag="nuxt-img"
Expand All @@ -101,10 +95,7 @@
)}${productGetters.getSlug(product, product.categories[0])}`
)
"
:wishlist-icon="isAuthenticated ? 'heart' : ''"
:is-in-wishlist-icon="isAuthenticated ? 'heart_fill' : ''"
:is-in-wishlist="product.isInWishlist"
@click:wishlist="addOrRemoveWishlistItem(product)"
:wishlist-icon="false"
/>
</div>
</SfMegaMenuColumn>
Expand Down Expand Up @@ -154,12 +145,10 @@ import {
SfMenuItem,
SfButton,
} from '@storefront-ui/vue';
import { defineComponent, computed } from '@nuxtjs/composition-api';
import { defineComponent } from '@nuxtjs/composition-api';
import type { PropType } from '@nuxtjs/composition-api';
import productGetters from '~/modules/catalog/product/getters/productGetters';
import { useUiHelpers, useImage } from '~/composables';
import { useWishlist } from '~/modules/wishlist/composables/useWishlist';
import { useUser } from '~/modules/customer/composables/useUser';
import { useImage } from '~/composables';
import SvgImage from '~/components/General/SvgImage.vue';
import type { Product } from '~/modules/catalog/product/types';
Expand All @@ -183,27 +172,13 @@ export default defineComponent({
default: () => [],
},
},
setup(props) {
const { isAuthenticated } = useUser();
const { isInWishlist, addOrRemoveItem: addOrRemoveWishlistItem } = useWishlist();
const th = useUiHelpers();
const searchResultsWithWishlistInfo = computed(() => props.searchResults?.map((product) => ({
...product,
isInWishlist: isInWishlist({ product }),
})));
setup() {
const { getMagentoImage, imageSizes } = useImage();
return {
th,
productGetters,
addOrRemoveWishlistItem,
isInWishlist,
isAuthenticated,
getMagentoImage,
imageSizes,
searchResultsWithWishlistInfo,
};
},
});
Expand Down

0 comments on commit 1742f45

Please sign in to comment.