Skip to content

Commit

Permalink
feat: update handleSearch function
Browse files Browse the repository at this point in the history
  • Loading branch information
rylanharper committed Nov 30, 2024
1 parent f66c703 commit 46579ea
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions app/components/search/search-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ const shopify = useShopify();
// Debounce query
const handleSearch = async (query: string) => {
searchQuery.value = query;
searchQuery.value = query.trim();
if (searchQuery.value) {
const searchVars: PredictiveSearchQueryVariables = {
query: searchQuery.value,
country: shopStore.buyerCountryCode,
language: shopStore.buyerLanguageCode,
};
try {
const response = await shopify.search.predictive(searchVars);
searchResults.value = response?.products || [];
} catch (error) {
console.error('Error fetching predictive search data.', error);
const searchVars: PredictiveSearchQueryVariables = {
query: searchQuery.value,
country: shopStore.buyerCountryCode,
language: shopStore.buyerLanguageCode,
};
try {
const response = await shopify.search.predictive(searchVars);
if (!response) {
throw new Error('No predictive search data found.');
}
searchResults.value = response.products;
} catch (error) {
console.error('Error fetching predictive search data:', error);
}
};
Expand Down

0 comments on commit 46579ea

Please sign in to comment.