nagasurendra commited on
Commit
3f7d9d1
·
verified ·
1 Parent(s): 450d774

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +66 -1
static/script.js CHANGED
@@ -175,6 +175,50 @@ function displayIngredientsList(ingredients) {
175
  ingredientsList.appendChild(item);
176
  });
177
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
  function displaySelectedIngredients() {
180
  const chatMessages = document.getElementById('chatMessages');
@@ -310,7 +354,28 @@ function displayOptions(options) {
310
  };
311
  chatMessages.appendChild(backButton);
312
  }
313
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  document.getElementById('userInput').addEventListener('keypress', function(e) {
315
  if (e.key === 'Enter') {
316
  sendMessage();
 
175
  ingredientsList.appendChild(item);
176
  });
177
  }
178
+ function displayMenuItems(menuItems) {
179
+ const chatMessages = document.getElementById('chatMessages');
180
+ if (!chatMessages) {
181
+ console.error('Chat messages container not found for menu items!');
182
+ return;
183
+ }
184
+
185
+ let menuItemsList = document.querySelector('.menu-items-list');
186
+ if (!menuItemsList) {
187
+ menuItemsList = document.createElement('div');
188
+ menuItemsList.className = 'menu-items-list';
189
+ chatMessages.appendChild(menuItemsList);
190
+ } else {
191
+ menuItemsList.innerHTML = '';
192
+ }
193
+
194
+ menuItems.forEach(item => {
195
+ const menuItem = document.createElement('div');
196
+ menuItem.className = 'menu-item';
197
+ const img = document.createElement('img');
198
+ img.src = item.image_url || 'https://via.placeholder.com/80';
199
+ img.alt = item.name;
200
+ const name = document.createElement('div');
201
+ name.textContent = item.name;
202
+ name.style.textAlign = 'center';
203
+ name.style.marginTop = '5px';
204
+ name.style.fontSize = '12px';
205
+ const button = document.createElement('button');
206
+ button.textContent = 'Add to Cart';
207
+ button.onclick = () => {
208
+ selectedMenuItem = item;
209
+ addMessage('bot', `World-class selection! Would you like to customize your dish further?`);
210
+ const options = [
211
+ { text: 'Yes', class: 'green' },
212
+ { text: 'No', class: 'red' }
213
+ ];
214
+ displayOptions(options);
215
+ };
216
+ menuItem.appendChild(img);
217
+ menuItem.appendChild(name);
218
+ menuItem.appendChild(button);
219
+ menuItemsList.appendChild(menuItem);
220
+ });
221
+ }
222
 
223
  function displaySelectedIngredients() {
224
  const chatMessages = document.getElementById('chatMessages');
 
354
  };
355
  chatMessages.appendChild(backButton);
356
  }
357
+ function fetchMenuItems(ingredientNames) {
358
+ fetch('/get_menu_items', {
359
+ method: 'POST',
360
+ headers: {
361
+ 'Content-Type': 'application/json',
362
+ },
363
+ body: JSON.stringify({ ingredient_names: ingredientNames })
364
+ })
365
+ .then(response => response.json())
366
+ .then(data => {
367
+ if (data.error) {
368
+ addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
369
+ } else {
370
+ const menuItems = data.menu_items || [];
371
+ addMessage('bot', 'Here are some dishes based on your selected ingredients:');
372
+ displayMenuItems(menuItems);
373
+ }
374
+ })
375
+ .catch(error => {
376
+ addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
377
+ });
378
+ }
379
  document.getElementById('userInput').addEventListener('keypress', function(e) {
380
  if (e.key === 'Enter') {
381
  sendMessage();