Added a global `notify` method via Nuxt plugin to replace `useNotification`. Improved messaging structure by embedding progress bars and handled dynamic durations. Updated usage across composables and components for consistency. - Replaced `useNotification` with `$notify` in all applicable files. - Updated `app.config.ts` to support customizable notification positions. - Refactored affected composables for simplified notification calls. - Enhanced progress indicator display within notifications. Breaking Changes: `useNotification` is removed, requiring migration to the new `$notify` API.
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
import { useWishlistOverwrite } from '@composables/wishlist/useWishlistOverwrite';
|
|
|
|
export function useWishlistSync() {
|
|
const wishlistStore = useWishlistStore();
|
|
const userStore = useUserStore();
|
|
const { $appHelpers } = useNuxtApp();
|
|
|
|
const { overwriteWishlist } = useWishlistOverwrite();
|
|
|
|
const isAuthenticated = computed(() => userStore.isAuthenticated);
|
|
const wishlistUuid = computed(() => wishlistStore.wishlist?.uuid);
|
|
|
|
const cookieWishlist = useCookie($appHelpers.COOKIES_WISHLIST_KEY, {
|
|
default: () => [],
|
|
path: '/',
|
|
});
|
|
|
|
async function syncWishlist() {
|
|
if (!isAuthenticated.value || !wishlistUuid.value) {
|
|
return;
|
|
}
|
|
|
|
const cookieProducts = cookieWishlist.value || [];
|
|
|
|
if (cookieProducts.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const apiProductUuids = wishlistStore.wishlist?.products?.edges.map((e) => e.node.uuid) || [];
|
|
|
|
const productsToAdd = cookieProducts.filter((product) => !apiProductUuids.includes(product));
|
|
|
|
if (productsToAdd.length === 0) {
|
|
cookieWishlist.value = [];
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await overwriteWishlist({
|
|
type: 'bulk',
|
|
bulkAction: 'add',
|
|
isBulkSync: true,
|
|
products: productsToAdd.map((p) => ({
|
|
uuid: p,
|
|
})),
|
|
});
|
|
|
|
if (bulkResult?.data?.bulkWishlistAction?.wishlist) {
|
|
wishlistStore.setWishlist(bulkResult.data.bulkWishlistAction.wishlist);
|
|
|
|
cookieWishlist.value = [];
|
|
}
|
|
} catch (err) {
|
|
console.error('useWishlistSync error:', err);
|
|
}
|
|
}
|
|
|
|
return {
|
|
syncWishlist,
|
|
};
|
|
}
|