Fixes: 1) Replace `ElNotification` calls with `useNotification` utility across all authentication and user-related composables; 2) Add missing semicolons in multiple index exports and styled components; 3) Resolve issues with reactivity in `useStore` composable by renaming and restructuring product variables; Extra: 1) Refactor localized strings and translations for better readability and maintenance; 2) Tweak styles including scoped styles, z-index adjustments, and SCSS mixins; 3) Remove unused components and imports to streamline storefront layout.
53 lines
No EOL
1.4 KiB
TypeScript
53 lines
No EOL
1.4 KiB
TypeScript
import {SEARCH} from "~/graphql/mutations/search";
|
|
import type {ISearchResponse, ISearchResults} from "~/types";
|
|
import {isGraphQLError} from "~/utils/error";
|
|
import {useNotification} from "~/composables/notification";
|
|
|
|
export function useSearch() {
|
|
const {t} = useI18n();
|
|
|
|
const searchResults = ref<ISearchResults | null>(null);
|
|
|
|
const { mutate, loading, error } = useMutation<ISearchResponse>(SEARCH);
|
|
|
|
async function search(
|
|
query: string
|
|
) {
|
|
searchResults.value = null;
|
|
const result = await mutate({ query });
|
|
|
|
if (result?.data?.search) {
|
|
const limitedResults = {
|
|
brands: result.data.search.results.brands?.slice(0, 7) || [],
|
|
categories: result.data.search.results.categories?.slice(0, 7) || [],
|
|
posts: result.data.search.results.posts?.slice(0, 7) || [],
|
|
products: result.data.search.results.products?.slice(0, 7) || []
|
|
};
|
|
|
|
searchResults.value = limitedResults;
|
|
return { results: limitedResults };
|
|
}
|
|
}
|
|
|
|
watch(error, (err) => {
|
|
if (!err) return;
|
|
console.error('useSearch error:', err);
|
|
let message = t('popup.errors.defaultError');
|
|
if (isGraphQLError(err)) {
|
|
message = err.graphQLErrors?.[0]?.message || message;
|
|
} else {
|
|
message = err.message;
|
|
}
|
|
useNotification(
|
|
message,
|
|
'error',
|
|
t('popup.errors.main')
|
|
);
|
|
});
|
|
|
|
return {
|
|
search,
|
|
loading,
|
|
searchResults
|
|
};
|
|
} |