**chore(storefront): apply consistent code formatting and improve readability**
Refactored multiple files for code styling consistency, using proper indentation and spacing to align with team standards. Improved readability and maintainability across composables, Apollo plugin, and localization files. Enhancements: - Standardized import and function indentation across all composables. - Updated `biome.json` schema to the latest version (v2.4.4) for tool compatibility. - Organized code blocks in Apollo plugin for better understandability. No functional changes introduced—this is a non-breaking, code refinement commit.
This commit is contained in:
parent
c36135d78d
commit
e65e7b7d73
18 changed files with 600 additions and 576 deletions
|
|
@ -31,7 +31,7 @@ export function useRegister() {
|
|||
password: payload.password,
|
||||
confirmPassword: payload.confirmPassword,
|
||||
referrer: payload.referrer,
|
||||
isSubscribed: payload.isSubscribed
|
||||
isSubscribed: payload.isSubscribed,
|
||||
});
|
||||
|
||||
if (result?.data?.createUser?.success) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export function useBrands(args: IBrandArgs = {}) {
|
|||
endCursor: string;
|
||||
}>({
|
||||
hasNextPage: false,
|
||||
endCursor: ''
|
||||
endCursor: '',
|
||||
});
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import {
|
|||
} from '@graphql/mutations/cart';
|
||||
import type {
|
||||
IAddToOrderResponse,
|
||||
IBulkOrderResponse, IProduct,
|
||||
IBulkOrderResponse,
|
||||
IProduct,
|
||||
IRemoveAllFromOrderResponse,
|
||||
IRemoveFromOrderResponse,
|
||||
IRemoveKindFromOrderResponse,
|
||||
|
|
@ -168,17 +169,20 @@ export function useOrderOverwrite() {
|
|||
switch (args.type) {
|
||||
case 'add': {
|
||||
const currentCart = cookieCart.value || [];
|
||||
const existingItem = currentCart.find(
|
||||
(item) => item.product.uuid === args.product.uuid
|
||||
);
|
||||
const existingItem = currentCart.find((item) => item.product.uuid === args.product.uuid);
|
||||
|
||||
if (existingItem) {
|
||||
existingItem.quantity += 1;
|
||||
cookieCart.value = [...currentCart];
|
||||
cookieCart.value = [
|
||||
...currentCart,
|
||||
];
|
||||
} else {
|
||||
cookieCart.value = [
|
||||
...currentCart,
|
||||
{ product: args.product, quantity: 1 }
|
||||
{
|
||||
product: args.product,
|
||||
quantity: 1,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -194,18 +198,16 @@ export function useOrderOverwrite() {
|
|||
|
||||
case 'remove': {
|
||||
const currentCart = cookieCart.value || [];
|
||||
const existingItem = currentCart.find(
|
||||
(item) => item.product.uuid === args.product.uuid
|
||||
);
|
||||
const existingItem = currentCart.find((item) => item.product.uuid === args.product.uuid);
|
||||
|
||||
if (existingItem) {
|
||||
if (existingItem.quantity > 1) {
|
||||
existingItem.quantity -= 1;
|
||||
cookieCart.value = [...currentCart];
|
||||
cookieCart.value = [
|
||||
...currentCart,
|
||||
];
|
||||
} else {
|
||||
cookieCart.value = currentCart.filter(
|
||||
(item) => item.product.uuid !== args.product.uuid
|
||||
);
|
||||
cookieCart.value = currentCart.filter((item) => item.product.uuid !== args.product.uuid);
|
||||
}
|
||||
|
||||
useNotification({
|
||||
|
|
@ -220,9 +222,7 @@ export function useOrderOverwrite() {
|
|||
}
|
||||
|
||||
case 'removeKind': {
|
||||
cookieCart.value = cookieCart.value.filter(
|
||||
(item) => item.product.uuid !== args.product.uuid
|
||||
);
|
||||
cookieCart.value = cookieCart.value.filter((item) => item.product.uuid !== args.product.uuid);
|
||||
|
||||
useNotification({
|
||||
message: t('popup.success.removeFromCart', {
|
||||
|
|
@ -247,10 +247,8 @@ export function useOrderOverwrite() {
|
|||
|
||||
case 'bulk': {
|
||||
if (args.bulkAction === 'remove' && args.products) {
|
||||
const uuidsToRemove = args.products.map(p => p.uuid);
|
||||
cookieCart.value = cookieCart.value.filter(
|
||||
(item) => !uuidsToRemove.includes(item.product.uuid)
|
||||
);
|
||||
const uuidsToRemove = args.products.map((p) => p.uuid);
|
||||
cookieCart.value = cookieCart.value.filter((item) => !uuidsToRemove.includes(item.product.uuid));
|
||||
|
||||
useNotification({
|
||||
message: t('popup.success.bulkRemoveOrder'),
|
||||
|
|
@ -260,16 +258,16 @@ export function useOrderOverwrite() {
|
|||
const currentCart = cookieCart.value || [];
|
||||
|
||||
for (const productRef of args.products) {
|
||||
const existingItem = currentCart.find(
|
||||
(item) => item.product.uuid === productRef.uuid
|
||||
);
|
||||
const existingItem = currentCart.find((item) => item.product.uuid === productRef.uuid);
|
||||
|
||||
if (existingItem) {
|
||||
existingItem.quantity += 1;
|
||||
}
|
||||
}
|
||||
|
||||
cookieCart.value = [...currentCart];
|
||||
cookieCart.value = [
|
||||
...currentCart,
|
||||
];
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,10 @@ export function useOrderSync() {
|
|||
const apiCartProducts = cartStore.currentOrder?.orderProducts?.edges || [];
|
||||
|
||||
const apiProductMap = new Map(
|
||||
apiCartProducts.map(e => [e.node.product.uuid, e.node.quantity])
|
||||
apiCartProducts.map((e) => [
|
||||
e.node.product.uuid,
|
||||
e.node.quantity,
|
||||
]),
|
||||
);
|
||||
|
||||
const productsToSync = [];
|
||||
|
|
@ -40,7 +43,9 @@ export function useOrderSync() {
|
|||
|
||||
if (quantityDifference > 0) {
|
||||
for (let i = 0; i < quantityDifference; i++) {
|
||||
productsToSync.push({ uuid: cartItem.product.uuid });
|
||||
productsToSync.push({
|
||||
uuid: cartItem.product.uuid,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,7 +60,7 @@ export function useOrderSync() {
|
|||
type: 'bulk',
|
||||
bulkAction: 'add',
|
||||
isBulkSync: true,
|
||||
products: productsToSync
|
||||
products: productsToSync,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to sync cart:', err);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {GET_POSTS} from "@graphql/queries/standalone/blog";
|
||||
import { GET_POSTS } from '@graphql/queries/standalone/blog';
|
||||
import type { IPostResponse } from '@types';
|
||||
|
||||
export function usePosts() {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,15 @@ import type { Ref } from 'vue';
|
|||
export function useFilters(filterableAttributes: Ref<IStoreFilters[]>) {
|
||||
const selectedMap = reactive<Record<string, Record<string, boolean>>>({});
|
||||
const selectedAllMap = reactive<Record<string, boolean>>({});
|
||||
const priceRange = ref<[number, number]>([0, 50000]);
|
||||
const priceRange = ref<
|
||||
[
|
||||
number,
|
||||
number,
|
||||
]
|
||||
>([
|
||||
0,
|
||||
50000,
|
||||
]);
|
||||
const collapse = ref<string[]>([]);
|
||||
|
||||
watch(
|
||||
|
|
@ -100,7 +108,10 @@ export function useFilters(filterableAttributes: Ref<IStoreFilters[]>) {
|
|||
if (expr.startsWith('range-')) {
|
||||
const parts = expr.slice(6).split('-');
|
||||
if (parts.length >= 2) {
|
||||
result[name] = [parts.slice(0, parts.length - 1).join('-'), parts[parts.length - 1]];
|
||||
result[name] = [
|
||||
parts.slice(0, parts.length - 1).join('-'),
|
||||
parts[parts.length - 1],
|
||||
];
|
||||
}
|
||||
} else if (expr.startsWith('in-')) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ export function useAvatarUpload() {
|
|||
context: {
|
||||
hasUpload: true,
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
onDone(({ data }) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { orderStatuses } from '@appConstants';
|
||||
import { useOrderSync } from '@composables/orders';
|
||||
import {useWishlistSync} from "@composables/wishlist";
|
||||
import { useWishlistSync } from '@composables/wishlist';
|
||||
import { getUserBaseData } from '@graphql/queries/combined/userBaseData';
|
||||
import type { IUserBaseDataResponse } from '@types';
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import {
|
|||
} from '@graphql/mutations/wishlist';
|
||||
import type {
|
||||
IAddToWishlistResponse,
|
||||
IBulkWishlistResponse, IProduct,
|
||||
IBulkWishlistResponse,
|
||||
IProduct,
|
||||
IRemoveAllFromWishlistResponse,
|
||||
IRemoveFromWishlistResponse,
|
||||
} from '@types';
|
||||
|
|
@ -147,9 +148,7 @@ export function useWishlistOverwrite() {
|
|||
} else {
|
||||
switch (args.type) {
|
||||
case 'add': {
|
||||
const isAlreadyInWishlist = cookieWishlist.value.some(
|
||||
(item) => item.uuid === args.product.uuid
|
||||
);
|
||||
const isAlreadyInWishlist = cookieWishlist.value.some((item) => item.uuid === args.product.uuid);
|
||||
|
||||
if (isAlreadyInWishlist) {
|
||||
useNotification({
|
||||
|
|
@ -159,7 +158,10 @@ export function useWishlistOverwrite() {
|
|||
type: 'warning',
|
||||
});
|
||||
} else {
|
||||
cookieWishlist.value = [...cookieWishlist.value, args.product];
|
||||
cookieWishlist.value = [
|
||||
...cookieWishlist.value,
|
||||
args.product,
|
||||
];
|
||||
|
||||
useNotification({
|
||||
message: t('popup.success.addToWishlist', {
|
||||
|
|
@ -173,9 +175,7 @@ export function useWishlistOverwrite() {
|
|||
}
|
||||
|
||||
case 'remove': {
|
||||
cookieWishlist.value = cookieWishlist.value.filter(
|
||||
(item) => item.uuid !== args.product.uuid
|
||||
);
|
||||
cookieWishlist.value = cookieWishlist.value.filter((item) => item.uuid !== args.product.uuid);
|
||||
|
||||
useNotification({
|
||||
message: t('popup.success.removeFromWishlist', {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {useWishlistOverwrite} from "@composables/wishlist/useWishlistOverwrite";
|
||||
import { useWishlistOverwrite } from '@composables/wishlist/useWishlistOverwrite';
|
||||
|
||||
export function useWishlistSync() {
|
||||
const wishlistStore = useWishlistStore();
|
||||
|
|
@ -26,11 +26,9 @@ export function useWishlistSync() {
|
|||
return;
|
||||
}
|
||||
|
||||
const apiProductUuids = wishlistStore.wishlist?.products?.edges.map(e => e.node.uuid) || [];
|
||||
const apiProductUuids = wishlistStore.wishlist?.products?.edges.map((e) => e.node.uuid) || [];
|
||||
|
||||
const productsToAdd = cookieProducts.filter(
|
||||
(product) => !apiProductUuids.includes(product.uuid)
|
||||
);
|
||||
const productsToAdd = cookieProducts.filter((product) => !apiProductUuids.includes(product.uuid));
|
||||
|
||||
if (productsToAdd.length === 0) {
|
||||
cookieWishlist.value = [];
|
||||
|
|
@ -42,8 +40,10 @@ export function useWishlistSync() {
|
|||
type: 'bulk',
|
||||
bulkAction: 'add',
|
||||
isBulkSync: true,
|
||||
products: productsToAdd.map(p => ({ uuid: p.uuid }))
|
||||
})
|
||||
products: productsToAdd.map((p) => ({
|
||||
uuid: p.uuid,
|
||||
})),
|
||||
});
|
||||
|
||||
if (bulkResult?.data?.bulkWishlistAction?.wishlist) {
|
||||
wishlistStore.setWishlist(bulkResult.data.bulkWishlistAction.wishlist);
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@ export enum docsSlugs {
|
|||
FAQ = 'faq',
|
||||
SHIPPING = 'shipping-information',
|
||||
RETURN = 'return-policy',
|
||||
ABOUT = 'about-us'
|
||||
ABOUT = 'about-us',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
import { ApolloLink, from } from '@apollo/client/core';
|
||||
import { setContext } from '@apollo/client/link/context';
|
||||
import { onError } from '@apollo/client/link/error';
|
||||
import { provideApolloClient } from '@vue/apollo-composable';
|
||||
import createUploadLink from "apollo-upload-client/createUploadLink.mjs";
|
||||
import createUploadLink from 'apollo-upload-client/createUploadLink.mjs';
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
const runtime = useRuntimeConfig();
|
||||
|
|
@ -22,23 +21,29 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||
let locale = 'en-gb';
|
||||
|
||||
if (import.meta.client) {
|
||||
const clientCookies = document.cookie.split(';').reduce((acc, cookie) => {
|
||||
const clientCookies = document.cookie.split(';').reduce(
|
||||
(acc, cookie) => {
|
||||
const [key, value] = cookie.trim().split('=');
|
||||
acc[key] = decodeURIComponent(value);
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
);
|
||||
|
||||
accessToken = clientCookies[$appHelpers.COOKIES_ACCESS_TOKEN_KEY] || '';
|
||||
locale = clientCookies[$appHelpers.COOKIES_LOCALE_KEY] || 'en-gb';
|
||||
} else {
|
||||
const cookieHeader = nuxtApp.ssrContext?.event?.node?.req?.headers?.cookie || '';
|
||||
const serverCookies = cookieHeader.split(';').reduce((acc, cookie) => {
|
||||
const serverCookies = cookieHeader.split(';').reduce(
|
||||
(acc, cookie) => {
|
||||
const [key, value] = cookie.trim().split('=');
|
||||
if (key && value) {
|
||||
acc[key] = decodeURIComponent(value);
|
||||
}
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
);
|
||||
|
||||
accessToken = serverCookies[$appHelpers.COOKIES_ACCESS_TOKEN_KEY] || '';
|
||||
locale = serverCookies[$appHelpers.COOKIES_LOCALE_KEY] || 'en-gb';
|
||||
|
|
@ -46,14 +51,16 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||
|
||||
const hdrs: Record<string, string> = {
|
||||
...headers,
|
||||
'Accept-Language': locale
|
||||
'Accept-Language': locale,
|
||||
};
|
||||
|
||||
if (accessToken) {
|
||||
hdrs['X-SCHON-AUTH'] = `Bearer ${accessToken}`;
|
||||
}
|
||||
|
||||
return { headers: hdrs };
|
||||
return {
|
||||
headers: hdrs,
|
||||
};
|
||||
});
|
||||
|
||||
const customLink = new ApolloLink((operation, forward) => {
|
||||
|
|
@ -63,15 +70,17 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||
});
|
||||
|
||||
const httpLink = createUploadLink({
|
||||
uri: `https://api.${runtime.public.schonBaseDomain}/graphql/`
|
||||
uri: `https://api.${runtime.public.schonBaseDomain}/graphql/`,
|
||||
});
|
||||
|
||||
$apollo.defaultClient.setLink(from([
|
||||
$apollo.defaultClient.setLink(
|
||||
from([
|
||||
errorLink,
|
||||
authLink,
|
||||
customLink,
|
||||
httpLink,
|
||||
]));
|
||||
]),
|
||||
);
|
||||
|
||||
provideApolloClient($apollo.defaultClient);
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.3.8/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.4.4/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
|
|
|
|||
Loading…
Reference in a new issue