From a328f55ca938935c352cc79df5342eb62b4cec7b Mon Sep 17 00:00:00 2001 From: Alexander Devitsky Date: Fri, 13 May 2022 19:42:35 +0300 Subject: [PATCH] fix: fixed errors during wishlist loading --- .../customer/pages/MyAccount/MyWishlist.vue | 28 +++++++++---------- .../wishlist/composables/useWishlist/index.ts | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue b/packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue index e64e5dbf1..7ba0879a7 100644 --- a/packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue +++ b/packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue @@ -252,16 +252,17 @@ import { import { computed, defineComponent, + onMounted, useRouter, useRoute, useContext, - useAsync, } from '@nuxtjs/composition-api'; import productGetters from '~/modules/catalog/product/getters/productGetters'; import type { Product } from '~/modules/catalog/product/types'; import { useWishlist } from '~/modules/wishlist/composables/useWishlist'; import wishlistGetters from '~/modules/wishlist/getters/wishlistGetters'; import { useCart } from '~/modules/checkout/composables/useCart'; +import { useWishlistStore } from '~/modules/wishlist/store/wishlistStore'; import { useUiHelpers, @@ -297,19 +298,10 @@ export default defineComponent({ const th = useUiHelpers(); const uiState = useUiState(); const { addItem: addItemToCartBase, isInCart } = useCart(); - const wishlist = useAsync(async () => { - const wishlistData = await load({ - searchParams: { - currentPage: page ? Number.parseInt(page.toString(), 10) : 1, - pageSize: itemsPerPage ? Number.parseInt(itemsPerPage.toString(), 10) : 10, - }, - }); - - return wishlistData; - }); + const wishlistStore = useWishlistStore(); - const products = computed(() => wishlistGetters.getProducts(wishlist?.value)); - const pagination = computed(() => wishlistGetters.getPagination(wishlist?.value?.[0])); + const products = computed(() => wishlistGetters.getProducts(wishlistStore.wishlist)); + const pagination = computed(() => wishlistGetters.getPagination(wishlistStore.wishlist)); const addItemToCart = async ({ product, quantity }: { product: Product, quantity: number }) => { // eslint-disable-next-line no-underscore-dangle @@ -342,6 +334,15 @@ export default defineComponent({ const { getMagentoImage, imageSizes } = useImage(); + onMounted(async () => { + await load({ + searchParams: { + currentPage: page ? Number.parseInt(page.toString(), 10) : 1, + pageSize: itemsPerPage ? Number.parseInt(itemsPerPage.toString(), 10) : 10, + }, + }); + }); + return { ...uiState, addItemToCart, @@ -352,7 +353,6 @@ export default defineComponent({ productGetters, products, th, - wishlist, getMagentoImage, imageSizes, }; diff --git a/packages/theme/modules/wishlist/composables/useWishlist/index.ts b/packages/theme/modules/wishlist/composables/useWishlist/index.ts index 945472e5d..562c9de1c 100644 --- a/packages/theme/modules/wishlist/composables/useWishlist/index.ts +++ b/packages/theme/modules/wishlist/composables/useWishlist/index.ts @@ -117,7 +117,7 @@ export function useWishlist(): UseWishlistInterface { const loadedWishlist = data?.customer?.wishlists ?? []; itemsCount = calculateWishlistTotal(loadedWishlist); wishlistStore.$patch((state) => { - state.wishlist = { items_count: itemsCount }; + state.wishlist.items_count = itemsCount; }); } } catch (err) {