lokesh341 commited on
Commit
d93ba85
·
verified ·
1 Parent(s): b13ffad

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +25 -3
static/script.js CHANGED
@@ -151,9 +151,10 @@ function handleResponse(userInput) {
151
  fetchMenuItems(lowerInput);
152
  return;
153
  } else {
154
- botResponse = `Hmm, let’s see what I can find for "${userInput}"...`;
 
155
  addMessage('bot', botResponse);
156
- suggestItems(userInput);
157
  return;
158
  }
159
 
@@ -236,6 +237,27 @@ function fetchItemDetails(itemName) {
236
  });
237
  }
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  function showDescriptionPopup(item) {
240
  const existingPopup = document.querySelector('.description-popup');
241
  if (existingPopup) existingPopup.remove();
@@ -302,7 +324,7 @@ function displayItemsList(items, containerId, isSectorDetail = false) {
302
  return;
303
  }
304
  container.innerHTML = '';
305
- container.className = 'ingredients-list'; // Ensure horizontal scroll
306
 
307
  items.forEach(item => {
308
  const itemDiv = document.createElement('div');
 
151
  fetchMenuItems(lowerInput);
152
  return;
153
  } else {
154
+ // Treat input as an item name and fetch details
155
+ botResponse = `Looking up details for "${userInput}"...`;
156
  addMessage('bot', botResponse);
157
+ fetchItemDetailsByName(userInput);
158
  return;
159
  }
160
 
 
237
  });
238
  }
239
 
240
+ function fetchItemDetailsByName(itemName) {
241
+ fetch('/get_item_details_by_name', {
242
+ method: 'POST',
243
+ headers: { 'Content-Type': 'application/json' },
244
+ body: JSON.stringify({ item_name: itemName })
245
+ })
246
+ .then(response => response.json())
247
+ .then(data => {
248
+ if (data.error) {
249
+ addMessage('bot', `Sorry, I couldn’t find "${itemName}" in Sector_Detail__c. Try another item or use the options below!`);
250
+ } else {
251
+ const details = data.item_details;
252
+ addMessage('bot', `Details for "${details.name}":\n- Category: ${details.category}\n- Description: ${details.description}`);
253
+ }
254
+ })
255
+ .catch(error => {
256
+ addMessage('bot', `Error fetching details for "${itemName}": ${error.message}. I’ll retry in a sec...`);
257
+ setTimeout(() => fetchItemDetailsByName(itemName), 2000);
258
+ });
259
+ }
260
+
261
  function showDescriptionPopup(item) {
262
  const existingPopup = document.querySelector('.description-popup');
263
  if (existingPopup) existingPopup.remove();
 
324
  return;
325
  }
326
  container.innerHTML = '';
327
+ container.className = 'ingredients-list';
328
 
329
  items.forEach(item => {
330
  const itemDiv = document.createElement('div');