Spaces:
Build error
Build error
Update static/script.js
Browse files- static/script.js +84 -70
static/script.js
CHANGED
|
@@ -36,6 +36,7 @@ function sendMessage() {
|
|
| 36 |
}
|
| 37 |
}
|
| 38 |
|
|
|
|
| 39 |
function handleResponse(userInput) {
|
| 40 |
const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
|
| 41 |
let botResponse = '';
|
|
@@ -47,29 +48,19 @@ 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 |
-
|
| 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:';
|
| 62 |
fetchIngredients('vegetarian');
|
| 63 |
return;
|
| 64 |
-
} else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
|
| 65 |
-
conversation.push({ role: 'user', message: lastMessage });
|
| 66 |
-
console.log(`Non-veg option selected: ${lastMessage}`);
|
| 67 |
-
botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
|
| 68 |
-
fetchIngredients(lastMessage.toLowerCase());
|
| 69 |
-
return;
|
| 70 |
} else if (lastMessage.includes('yes') && selectedMenuItem) {
|
| 71 |
-
botResponse = 'Here are some ingredients
|
| 72 |
-
fetchIngredients('both'); //
|
| 73 |
return;
|
| 74 |
} else if (lastMessage.includes('no') && selectedMenuItem) {
|
| 75 |
addToCart(selectedMenuItem);
|
|
@@ -111,29 +102,6 @@ function fetchIngredients(foodPreference) {
|
|
| 111 |
});
|
| 112 |
}
|
| 113 |
|
| 114 |
-
function fetchMenuItems(category) {
|
| 115 |
-
fetch('/get_menu_items', {
|
| 116 |
-
method: 'POST',
|
| 117 |
-
headers: {
|
| 118 |
-
'Content-Type': 'application/json',
|
| 119 |
-
},
|
| 120 |
-
body: JSON.stringify({ category: category })
|
| 121 |
-
})
|
| 122 |
-
.then(response => response.json())
|
| 123 |
-
.then(data => {
|
| 124 |
-
if (data.error) {
|
| 125 |
-
addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
|
| 126 |
-
} else {
|
| 127 |
-
const menuItems = data.menu_items || [];
|
| 128 |
-
addMessage('bot', 'Here are some dishes based on your selection:');
|
| 129 |
-
displayMenuItems(menuItems);
|
| 130 |
-
}
|
| 131 |
-
})
|
| 132 |
-
.catch(error => {
|
| 133 |
-
addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
|
| 134 |
-
});
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
function displayIngredientsList(ingredients) {
|
| 138 |
const chatMessages = document.getElementById('chatMessages');
|
| 139 |
if (!chatMessages) {
|
|
@@ -176,6 +144,85 @@ function displayIngredientsList(ingredients) {
|
|
| 176 |
});
|
| 177 |
}
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
function displayMenuItems(menuItems) {
|
| 180 |
const chatMessages = document.getElementById('chatMessages');
|
| 181 |
if (!chatMessages) {
|
|
@@ -221,39 +268,6 @@ function displayMenuItems(menuItems) {
|
|
| 221 |
});
|
| 222 |
}
|
| 223 |
|
| 224 |
-
function displaySelectedIngredients() {
|
| 225 |
-
const chatMessages = document.getElementById('chatMessages');
|
| 226 |
-
if (!chatMessages) {
|
| 227 |
-
console.error('Chat messages container not found for selected ingredients!');
|
| 228 |
-
return;
|
| 229 |
-
}
|
| 230 |
-
|
| 231 |
-
let selectedArea = document.querySelector('.selected-ingredients');
|
| 232 |
-
if (!selectedArea) {
|
| 233 |
-
selectedArea = document.createElement('div');
|
| 234 |
-
selectedArea.className = 'selected-ingredients';
|
| 235 |
-
chatMessages.appendChild(selectedArea);
|
| 236 |
-
} else {
|
| 237 |
-
selectedArea.innerHTML = '';
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
selectedIngredients.forEach(ingredient => {
|
| 241 |
-
const div = document.createElement('div');
|
| 242 |
-
div.textContent = ingredient.name;
|
| 243 |
-
selectedArea.appendChild(div);
|
| 244 |
-
});
|
| 245 |
-
|
| 246 |
-
if (selectedIngredients.length > 0) {
|
| 247 |
-
let submitButton = document.querySelector('.submit-button');
|
| 248 |
-
if (!submitButton) {
|
| 249 |
-
submitButton = document.createElement('button');
|
| 250 |
-
submitButton.className = 'submit-button';
|
| 251 |
-
submitButton.textContent = 'Submit Ingredients';
|
| 252 |
-
submitButton.onclick = submitIngredients;
|
| 253 |
-
chatMessages.appendChild(submitButton);
|
| 254 |
-
}
|
| 255 |
-
}
|
| 256 |
-
}
|
| 257 |
|
| 258 |
function submitIngredients() {
|
| 259 |
fetch('/submit_ingredients', {
|
|
|
|
| 36 |
}
|
| 37 |
}
|
| 38 |
|
| 39 |
+
|
| 40 |
function handleResponse(userInput) {
|
| 41 |
const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
|
| 42 |
let botResponse = '';
|
|
|
|
| 48 |
{ text: 'Vegetarian', class: 'green' },
|
| 49 |
{ text: 'Non-Vegetarian', class: 'red' }
|
| 50 |
];
|
| 51 |
+
} else if (lastMessage.includes('non-vegetarian')) {
|
| 52 |
conversation.push({ role: 'user', message: '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 |
botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
|
| 59 |
fetchIngredients('vegetarian');
|
| 60 |
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
} else if (lastMessage.includes('yes') && selectedMenuItem) {
|
| 62 |
+
botResponse = 'Here are some ingredients with both options:';
|
| 63 |
+
fetchIngredients('both'); // Show both vegetarian and non-vegetarian ingredients
|
| 64 |
return;
|
| 65 |
} else if (lastMessage.includes('no') && selectedMenuItem) {
|
| 66 |
addToCart(selectedMenuItem);
|
|
|
|
| 102 |
});
|
| 103 |
}
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
function displayIngredientsList(ingredients) {
|
| 106 |
const chatMessages = document.getElementById('chatMessages');
|
| 107 |
if (!chatMessages) {
|
|
|
|
| 144 |
});
|
| 145 |
}
|
| 146 |
|
| 147 |
+
function displaySelectedIngredients() {
|
| 148 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 149 |
+
if (!chatMessages) {
|
| 150 |
+
console.error('Chat messages container not found for selected ingredients!');
|
| 151 |
+
return;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
let selectedArea = document.querySelector('.selected-ingredients');
|
| 155 |
+
if (!selectedArea) {
|
| 156 |
+
selectedArea = document.createElement('div');
|
| 157 |
+
selectedArea.className = 'selected-ingredients';
|
| 158 |
+
chatMessages.appendChild(selectedArea);
|
| 159 |
+
} else {
|
| 160 |
+
selectedArea.innerHTML = '';
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
selectedIngredients.forEach(ingredient => {
|
| 164 |
+
const div = document.createElement('div');
|
| 165 |
+
div.textContent = ingredient.name;
|
| 166 |
+
selectedArea.appendChild(div);
|
| 167 |
+
});
|
| 168 |
+
|
| 169 |
+
if (selectedIngredients.length > 0) {
|
| 170 |
+
let instructionsArea = document.querySelector('.instructions-area');
|
| 171 |
+
if (!instructionsArea) {
|
| 172 |
+
instructionsArea = document.createElement('div');
|
| 173 |
+
instructionsArea.className = 'instructions-area';
|
| 174 |
+
const textarea = document.createElement('textarea');
|
| 175 |
+
textarea.placeholder = 'Enter any special instructions...';
|
| 176 |
+
const submitButton = document.createElement('button');
|
| 177 |
+
submitButton.textContent = 'Submit';
|
| 178 |
+
submitButton.onclick = () => {
|
| 179 |
+
const instructions = textarea.value.trim();
|
| 180 |
+
if (instructions) {
|
| 181 |
+
addMessage('user', instructions);
|
| 182 |
+
conversation.push({ role: 'user', message: instructions });
|
| 183 |
+
}
|
| 184 |
+
addToCart({ ...selectedMenuItem, instructions, ingredients: selectedIngredients });
|
| 185 |
+
addMessage('bot', 'Item added to cart! Would you like to order more?');
|
| 186 |
+
const options = [
|
| 187 |
+
{ text: 'Yes', class: 'green' },
|
| 188 |
+
{ text: 'No', class: 'red' }
|
| 189 |
+
];
|
| 190 |
+
displayOptions(options);
|
| 191 |
+
selectedMenuItem = null;
|
| 192 |
+
selectedIngredients = [];
|
| 193 |
+
};
|
| 194 |
+
instructionsArea.appendChild(textarea);
|
| 195 |
+
instructionsArea.appendChild(submitButton);
|
| 196 |
+
chatMessages.appendChild(instructionsArea);
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
function fetchMenuItems(category) {
|
| 203 |
+
fetch('/get_menu_items', {
|
| 204 |
+
method: 'POST',
|
| 205 |
+
headers: {
|
| 206 |
+
'Content-Type': 'application/json',
|
| 207 |
+
},
|
| 208 |
+
body: JSON.stringify({ category: category })
|
| 209 |
+
})
|
| 210 |
+
.then(response => response.json())
|
| 211 |
+
.then(data => {
|
| 212 |
+
if (data.error) {
|
| 213 |
+
addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
|
| 214 |
+
} else {
|
| 215 |
+
const menuItems = data.menu_items || [];
|
| 216 |
+
addMessage('bot', 'Here are some dishes based on your selection:');
|
| 217 |
+
displayMenuItems(menuItems);
|
| 218 |
+
}
|
| 219 |
+
})
|
| 220 |
+
.catch(error => {
|
| 221 |
+
addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
|
| 222 |
+
});
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
|
| 226 |
function displayMenuItems(menuItems) {
|
| 227 |
const chatMessages = document.getElementById('chatMessages');
|
| 228 |
if (!chatMessages) {
|
|
|
|
| 268 |
});
|
| 269 |
}
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
function submitIngredients() {
|
| 273 |
fetch('/submit_ingredients', {
|