nagasurendra commited on
Commit
6fa3c1c
·
verified ·
1 Parent(s): c40741f

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +8 -75
static/script.js CHANGED
@@ -47,13 +47,15 @@ function handleResponse(userInput) {
47
  { text: 'Vegetarian', class: 'green' },
48
  { text: 'Non-Vegetarian', class: 'red' }
49
  ];
50
- } else if (lastMessage.includes('non-vegetarian')) {
51
  conversation.push({ role: 'user', message: 'Non-Vegetarian' });
52
  console.log("Food preference selected: Non-Vegetarian");
53
  botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
54
  fetchIngredients('non-vegetarian');
55
  return;
56
- } else if (lastMessage.includes('vegetarian')) {
 
 
57
  conversation.push({ role: 'user', message: 'Vegetarian' });
58
  console.log("Food preference selected: Vegetarian");
59
  botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
@@ -66,8 +68,8 @@ function handleResponse(userInput) {
66
  fetchIngredients(lastMessage.toLowerCase());
67
  return;
68
  } else if (lastMessage.includes('yes') && selectedMenuItem) {
69
- botResponse = 'Awesome! Let’s customize your dish. Here are some ingredients you can add:';
70
- fetchCustomizationIngredients('both'); // New function for customization
71
  return;
72
  } else if (lastMessage.includes('no') && selectedMenuItem) {
73
  addToCart(selectedMenuItem);
@@ -84,70 +86,6 @@ function handleResponse(userInput) {
84
  displayOptions(options);
85
  }
86
  }
87
- function fetchCustomizationIngredients(foodPreference) {
88
- fetch('/get_ingredients', {
89
- method: 'POST',
90
- headers: {
91
- 'Content-Type': 'application/json',
92
- },
93
- body: JSON.stringify({ dietary_preference: foodPreference })
94
- })
95
- .then(response => response.json())
96
- .then(data => {
97
- if (data.error) {
98
- addMessage('bot', `Sorry, there was an error fetching customization ingredients: ${data.error}`);
99
- } else {
100
- const ingredients = data.ingredients || [];
101
- addMessage('bot', 'Select ingredients to customize your dish:');
102
- displayCustomizationIngredients(ingredients); // New function for customization UI
103
- displaySelectedIngredientsForCustomization(); // New function for selected ingredients
104
- }
105
- })
106
- .catch(error => {
107
- addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
108
- });
109
- }
110
- function displayCustomizationIngredients(ingredients) {
111
- const chatMessages = document.getElementById('chatMessages');
112
- if (!chatMessages) {
113
- console.error('Chat messages container not found for customization ingredients!');
114
- return;
115
- }
116
-
117
- let ingredientsList = document.querySelector('.customization-ingredients-list');
118
- if (!ingredientsList) {
119
- ingredientsList = document.createElement('div');
120
- ingredientsList.className = 'customization-ingredients-list ingredients-list'; // Reuse .ingredients-list CSS
121
- chatMessages.appendChild(ingredientsList);
122
- } else {
123
- ingredientsList.innerHTML = '';
124
- }
125
-
126
- ingredients.forEach(ingredient => {
127
- const item = document.createElement('div');
128
- item.className = 'ingredient-item'; // Same CSS as original
129
- const img = document.createElement('img');
130
- img.src = ingredient.image_url || 'https://via.placeholder.com/80';
131
- img.alt = ingredient.name;
132
- const name = document.createElement('div');
133
- name.textContent = ingredient.name;
134
- name.style.textAlign = 'center';
135
- name.style.marginTop = '5px';
136
- name.style.fontSize = '12px';
137
- const button = document.createElement('button');
138
- button.textContent = 'Add';
139
- button.onclick = () => {
140
- if (!selectedIngredients.some(item => item.name === ingredient.name)) {
141
- selectedIngredients.push(ingredient);
142
- displaySelectedIngredientsForCustomization();
143
- }
144
- };
145
- item.appendChild(img);
146
- item.appendChild(name);
147
- item.appendChild(button);
148
- ingredientsList.appendChild(item);
149
- });
150
- }
151
 
152
  function fetchIngredients(foodPreference) {
153
  fetch('/get_ingredients', {
@@ -402,17 +340,12 @@ function displayCustomizationInput() {
402
  chatMessages.appendChild(customizationArea);
403
  }
404
  }
 
405
  function addToCart(item) {
406
- cart.push({
407
- ...item,
408
- ingredients: item.ingredients || [], // Original ingredients (if any)
409
- customizationIngredients: item.customizationIngredients || [], // Customization ingredients
410
- instructions: item.instructions || '' // Special instructions
411
- });
412
  console.log('Cart:', cart);
413
  }
414
 
415
-
416
  function displayOptions(options) {
417
  const chatMessages = document.getElementById('chatMessages');
418
  if (!chatMessages) {
 
47
  { text: 'Vegetarian', class: 'green' },
48
  { text: 'Non-Vegetarian', class: 'red' }
49
  ];
50
+ }else if (lastMessage.includes('non-vegetarian')) {
51
  conversation.push({ role: 'user', message: 'Non-Vegetarian' });
52
  console.log("Food preference selected: Non-Vegetarian");
53
  botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
54
  fetchIngredients('non-vegetarian');
55
  return;
56
+
57
+ }
58
+ else if (lastMessage.includes('vegetarian')) {
59
  conversation.push({ role: 'user', message: 'Vegetarian' });
60
  console.log("Food preference selected: Vegetarian");
61
  botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
 
68
  fetchIngredients(lastMessage.toLowerCase());
69
  return;
70
  } else if (lastMessage.includes('yes') && selectedMenuItem) {
71
+ botResponse = 'Here are some ingredients to customize your dish:';
72
+ fetchIngredients('both'); // Fetch non-veg ingredients for customization
73
  return;
74
  } else if (lastMessage.includes('no') && selectedMenuItem) {
75
  addToCart(selectedMenuItem);
 
86
  displayOptions(options);
87
  }
88
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
  function fetchIngredients(foodPreference) {
91
  fetch('/get_ingredients', {
 
340
  chatMessages.appendChild(customizationArea);
341
  }
342
  }
343
+
344
  function addToCart(item) {
345
+ cart.push(item);
 
 
 
 
 
346
  console.log('Cart:', cart);
347
  }
348
 
 
349
  function displayOptions(options) {
350
  const chatMessages = document.getElementById('chatMessages');
351
  if (!chatMessages) {