Skip to content

Commit 839d335

Browse files
refactor: duplicated code
1 parent c5dc43d commit 839d335

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

client-app/pages/cart.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@
6262
</VcWidget>
6363

6464
<CartForLater
65-
v-if="savedForLaterList?.items?.length && !shouldHide('cart-for-later')"
65+
v-if="!shouldHideSavedForLater && savedForLaterList?.items?.length"
6666
:saved-for-later-list="savedForLaterList"
6767
class="mt-5"
6868
@add-to-cart="(lineItemId) => handleMoveToCart([lineItemId])"
6969
/>
7070

7171
<RecentlyBrowsedProducts
72-
v-if="recentlyBrowsedProducts.length && !shouldHide('recently-browsed-products')"
72+
v-if="recentlyBrowsedProducts.length && !shouldHideRecentlyBrowsed"
7373
:products="recentlyBrowsedProducts"
7474
class="mt-5"
7575
/>
@@ -111,14 +111,14 @@
111111
</template>
112112

113113
<CartForLater
114-
v-if="savedForLaterList?.items?.length && !shouldHide('cart-for-later')"
114+
v-if="!shouldHideSavedForLater && savedForLaterList?.items?.length"
115115
:saved-for-later-list="savedForLaterList"
116116
class="mt-5"
117117
@add-to-cart="(lineItemId) => handleMoveToCart([lineItemId])"
118118
/>
119119

120120
<RecentlyBrowsedProducts
121-
v-if="recentlyBrowsedProducts.length && !shouldHide('recently-browsed-products')"
121+
v-if="recentlyBrowsedProducts.length && !shouldHideRecentlyBrowsed"
122122
:products="recentlyBrowsedProducts"
123123
class="mt-5"
124124
/>
@@ -366,6 +366,10 @@ function selectItemEvent(item: LineItemType | undefined): void {
366366
});
367367
}
368368
369+
const shouldHideSavedForLater = computed(() => !isAuthenticated.value || shouldHide("cart-for-later"));
370+
371+
const shouldHideRecentlyBrowsed = computed(() => shouldHide("recently-browsed-products"));
372+
369373
function shouldHide(id: string) {
370374
return props.blocksToHide?.includes(id);
371375
}
@@ -427,10 +431,10 @@ void (async () => {
427431
}
428432
429433
const isXRecommendModuleEnabled = isEnabledXRecommend(XRECOMMEND_ENABLED_KEY);
430-
if (isAuthenticated.value && isXRecommendModuleEnabled && !shouldHide("recently-browsed-products")) {
434+
if (isAuthenticated.value && isXRecommendModuleEnabled && !shouldHideRecentlyBrowsed.value) {
431435
recentlyBrowsedProducts.value = (await recentlyBrowsed())?.products || [];
432436
}
433-
if (isAuthenticated.value && !shouldHide("cart-for-later")) {
437+
if (!shouldHideSavedForLater.value) {
434438
await getSavedForLater();
435439
}
436440
})();

0 commit comments

Comments
 (0)