Enhancements: - Introduced `wishlist.vue` for displaying and managing the wishlist. - Added guest cart and wishlist handling via cookies for unauthenticated users. - Implemented synchronization logic for wishlist and cart (`useOrderSync` and `useWishlistSync`) upon user login. - Updated `cart.vue` layout with a bulk 'add all to cart' button for wishlist items. - Enhanced `post.vue` prop handling for improved type safety. Fixes: - Fixed breadcrumbs console log removal in `useBreadcrumbs.ts`. - Corrected and unified translations in `en-gb.json` for cart and wishlist descriptions. - Fixed stale routes in footer (`terms-and-condition` -> `terms-and-conditions`, etc.). Extras: - Refactored composables `useWishlistOverwrite` and `useOrderOverwrite` for cookie-based fallback. - Applied code styling improvements, organized imports, and optimized API requests in Apollo plugin.
158 lines
No EOL
3.8 KiB
Vue
158 lines
No EOL
3.8 KiB
Vue
<template>
|
|
<div class="wishlist">
|
|
<div class="container">
|
|
<div class="wishlist__wrapper">
|
|
<div class="wishlist__top">
|
|
<h1 class="wishlist__top-title">{{ t('wishlist.title') }}</h1>
|
|
<div class="wishlist__top-inner">
|
|
<p>({{ t('wishlist.items', productsInWishlist.length, { count: productsInWishlist.length }) }})</p>
|
|
<ui-button
|
|
:type="'button'"
|
|
class="wishlist__top-button"
|
|
@click="onBulkAdd"
|
|
:isLoading="bulkLoading"
|
|
>
|
|
<icon name="material-symbols:add" size="20" />
|
|
{{ t('buttons.addAllToCart') }}
|
|
</ui-button>
|
|
</div>
|
|
</div>
|
|
<div class="wishlist__list">
|
|
<div class="wishlist__list-inner" v-if="productsInWishlist.length">
|
|
<cards-product
|
|
v-for="product in productsInWishlist"
|
|
:key="product.node.uuid"
|
|
:product="product.node"
|
|
/>
|
|
</div>
|
|
<p class="wishlist__empty" v-else>{{ t('wishlist.empty') }}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import {usePageTitle} from '@composables/utils';
|
|
import {useWishlistOverwrite} from '@composables/wishlist';
|
|
import {useOrderOverwrite} from "@composables/orders";
|
|
|
|
const {t} = useI18n();
|
|
const wishlistStore = useWishlistStore();
|
|
const userStore = useUserStore();
|
|
const { $appHelpers } = useNuxtApp();
|
|
|
|
const isAuthenticated = computed(() => userStore.isAuthenticated);
|
|
|
|
const cookieWishlist = useCookie($appHelpers.COOKIES_WISHLIST_KEY, {
|
|
default: () => [],
|
|
path: '/',
|
|
});
|
|
|
|
const { overwriteWishlist } = useWishlistOverwrite();
|
|
const { overwriteOrder, bulkLoading } = useOrderOverwrite();
|
|
|
|
const productsInWishlist = computed(() => {
|
|
if (isAuthenticated.value) {
|
|
return wishlistStore.wishlist ? wishlistStore.wishlist.products.edges : [];
|
|
} else {
|
|
return cookieWishlist.value.map(product => ({
|
|
node: product
|
|
}));
|
|
}
|
|
});
|
|
const totalPrice = computed(() => {
|
|
return productsInWishlist.value.reduce((acc, p) => acc + p.node.price, 0);
|
|
});
|
|
|
|
const selectedProducts = ref<{ uuid: string }[]>([]);
|
|
|
|
const productsUuid = computed<boolean>(() => {
|
|
return productsInWishlist.value.map(p => ({ uuid: p.node.uuid }));
|
|
});
|
|
|
|
function toggleUuid(uuid: string, checked: boolean) {
|
|
if (checked) {
|
|
if (!selectedProducts.value.some(o => o.uuid === uuid)) {
|
|
selectedProducts.value.push({ uuid });
|
|
}
|
|
}
|
|
else {
|
|
selectedProducts.value = selectedProducts.value
|
|
.filter(o => o.uuid !== uuid);
|
|
}
|
|
}
|
|
|
|
function onBulkAdd() {
|
|
overwriteOrder({
|
|
type: 'bulk',
|
|
bulkAction: 'add',
|
|
products: productsUuid.value
|
|
});
|
|
}
|
|
|
|
function onBulkRemove() {
|
|
overwriteWishlist({
|
|
type: 'bulkRemove',
|
|
bulkAction: 'remove',
|
|
products: productsUuid.value
|
|
});
|
|
}
|
|
|
|
const { setPageTitle } = usePageTitle();
|
|
|
|
setPageTitle(t('breadcrumbs.wishlist'));
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.wishlist {
|
|
padding-block: 50px 100px;
|
|
background-color: $white;
|
|
|
|
&__wrapper {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 50px;
|
|
}
|
|
|
|
&__top {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
|
|
&-title {
|
|
color: #1a1a1a;
|
|
font-family: "Playfair Display", sans-serif;
|
|
font-size: 36px;
|
|
font-weight: 600;
|
|
letter-spacing: -0.5px;
|
|
}
|
|
|
|
&-inner {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 35px;
|
|
}
|
|
|
|
& p {
|
|
color: #4b5563;
|
|
font-size: 18px;
|
|
font-weight: 400;
|
|
letter-spacing: -0.5px;
|
|
}
|
|
|
|
&-button {
|
|
width: fit-content;
|
|
padding-inline: 25px;
|
|
}
|
|
}
|
|
|
|
&__list {
|
|
&-inner {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
gap: 25px;
|
|
}
|
|
}
|
|
}
|
|
</style> |