Fixes: 1) Refactor `useProducts` and `useCategorybySlug` composables for improved error handling and lazy loading; 2) Correct import path in `product-page.vue` for `useProductBySlug`; 3) Update `useLanguages` composable to set current locale from local storage; 4) Remove unused `auth.js`, `base-header.vue`, and deprecated GraphQL fragments; Extra: Minor styling adjustments and removal of redundant console logs; Updated `package-lock.json` dependencies for version consistency.
52 lines
No EOL
1.1 KiB
JavaScript
52 lines
No EOL
1.1 KiB
JavaScript
import {useMutation} from "@vue/apollo-composable";
|
|
import {ref} from "vue";
|
|
import {ElNotification} from "element-plus";
|
|
import {useI18n} from "vue-i18n";
|
|
import {SEARCH} from "@/graphql/mutations/search.js";
|
|
|
|
export function useSearch() {
|
|
const {t} = useI18n();
|
|
|
|
const { mutate: searchMutation } = useMutation(SEARCH);
|
|
|
|
const loading = ref(false);
|
|
const searchResults = ref(null);
|
|
|
|
async function search(
|
|
query
|
|
) {
|
|
loading.value = true;
|
|
searchResults.value = null;
|
|
|
|
try {
|
|
const response = await searchMutation({
|
|
query
|
|
});
|
|
|
|
if (response.data?.search) {
|
|
searchResults.value = response.data.search.results;
|
|
return response.data.search;
|
|
}
|
|
} catch (error) {
|
|
console.error("useSearch error:", error);
|
|
|
|
const errorMessage = error.graphQLErrors?.[0]?.message ||
|
|
error.message ||
|
|
t('popup.errors.defaultError');
|
|
|
|
ElNotification({
|
|
title: t('popup.errors.main'),
|
|
message: errorMessage,
|
|
type: 'error'
|
|
});
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
return {
|
|
search,
|
|
loading,
|
|
searchResults
|
|
};
|
|
} |