Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +42 -37
static/script.js
CHANGED
|
@@ -102,6 +102,7 @@ function fetchIngredients(foodPreference) {
|
|
| 102 |
});
|
| 103 |
}
|
| 104 |
|
|
|
|
| 105 |
function displayIngredientsList(ingredients) {
|
| 106 |
const chatMessages = document.getElementById('chatMessages');
|
| 107 |
if (!chatMessages) {
|
|
@@ -167,6 +168,7 @@ function displaySelectedIngredients() {
|
|
| 167 |
});
|
| 168 |
|
| 169 |
if (selectedIngredients.length > 0) {
|
|
|
|
| 170 |
let instructionsArea = document.querySelector('.instructions-area');
|
| 171 |
if (!instructionsArea) {
|
| 172 |
instructionsArea = document.createElement('div');
|
|
@@ -198,6 +200,46 @@ function displaySelectedIngredients() {
|
|
| 198 |
}
|
| 199 |
}
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
function fetchMenuItems(category) {
|
| 203 |
fetch('/get_menu_items', {
|
|
@@ -355,44 +397,7 @@ function displayCustomizationInput() {
|
|
| 355 |
}
|
| 356 |
}
|
| 357 |
|
| 358 |
-
function addToCart(item) {
|
| 359 |
-
cart.push(item);
|
| 360 |
-
console.log('Cart:', cart);
|
| 361 |
-
}
|
| 362 |
|
| 363 |
-
function displayOptions(options) {
|
| 364 |
-
const chatMessages = document.getElementById('chatMessages');
|
| 365 |
-
if (!chatMessages) {
|
| 366 |
-
console.error('Chat messages container not found for options!');
|
| 367 |
-
return;
|
| 368 |
-
}
|
| 369 |
-
options.forEach(opt => {
|
| 370 |
-
const button = document.createElement('button');
|
| 371 |
-
button.textContent = opt.text;
|
| 372 |
-
button.className = `option-button ${opt.class}`;
|
| 373 |
-
button.onclick = () => {
|
| 374 |
-
addMessage('user', opt.text);
|
| 375 |
-
conversation.push({ role: 'user', message: opt.text });
|
| 376 |
-
chatMessages.innerHTML = '';
|
| 377 |
-
conversation.forEach(msg => addMessage(msg.role, msg.message));
|
| 378 |
-
setTimeout(() => handleResponse(opt.text), 500);
|
| 379 |
-
};
|
| 380 |
-
chatMessages.appendChild(button);
|
| 381 |
-
});
|
| 382 |
-
chatMessages.appendChild(document.createElement('br'));
|
| 383 |
-
const backButton = document.createElement('button');
|
| 384 |
-
backButton.textContent = 'Go Back';
|
| 385 |
-
backButton.className = 'option-button';
|
| 386 |
-
backButton.onclick = () => {
|
| 387 |
-
conversation.pop();
|
| 388 |
-
selectedIngredients = [];
|
| 389 |
-
selectedMenuItem = null;
|
| 390 |
-
chatMessages.innerHTML = '';
|
| 391 |
-
conversation.forEach(msg => addMessage(msg.role, msg.message));
|
| 392 |
-
setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
|
| 393 |
-
};
|
| 394 |
-
chatMessages.appendChild(backButton);
|
| 395 |
-
}
|
| 396 |
|
| 397 |
document.getElementById('userInput').addEventListener('keypress', function(e) {
|
| 398 |
if (e.key === 'Enter') {
|
|
|
|
| 102 |
});
|
| 103 |
}
|
| 104 |
|
| 105 |
+
// This will remain the same as Step 3
|
| 106 |
function displayIngredientsList(ingredients) {
|
| 107 |
const chatMessages = document.getElementById('chatMessages');
|
| 108 |
if (!chatMessages) {
|
|
|
|
| 168 |
});
|
| 169 |
|
| 170 |
if (selectedIngredients.length > 0) {
|
| 171 |
+
// New functionality after clicking "Yes" (Step 5 onward)
|
| 172 |
let instructionsArea = document.querySelector('.instructions-area');
|
| 173 |
if (!instructionsArea) {
|
| 174 |
instructionsArea = document.createElement('div');
|
|
|
|
| 200 |
}
|
| 201 |
}
|
| 202 |
|
| 203 |
+
function addToCart(item) {
|
| 204 |
+
cart.push(item);
|
| 205 |
+
console.log('Cart:', cart);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
function displayOptions(options) {
|
| 209 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 210 |
+
if (!chatMessages) {
|
| 211 |
+
console.error('Chat messages container not found for options!');
|
| 212 |
+
return;
|
| 213 |
+
}
|
| 214 |
+
options.forEach(opt => {
|
| 215 |
+
const button = document.createElement('button');
|
| 216 |
+
button.textContent = opt.text;
|
| 217 |
+
button.className = `option-button ${opt.class}`;
|
| 218 |
+
button.onclick = () => {
|
| 219 |
+
addMessage('user', opt.text);
|
| 220 |
+
conversation.push({ role: 'user', message: opt.text });
|
| 221 |
+
chatMessages.innerHTML = '';
|
| 222 |
+
conversation.forEach(msg => addMessage(msg.role, msg.message));
|
| 223 |
+
setTimeout(() => handleResponse(opt.text), 500);
|
| 224 |
+
};
|
| 225 |
+
chatMessages.appendChild(button);
|
| 226 |
+
});
|
| 227 |
+
chatMessages.appendChild(document.createElement('br'));
|
| 228 |
+
const backButton = document.createElement('button');
|
| 229 |
+
backButton.textContent = 'Go Back';
|
| 230 |
+
backButton.className = 'option-button';
|
| 231 |
+
backButton.onclick = () => {
|
| 232 |
+
conversation.pop();
|
| 233 |
+
selectedIngredients = [];
|
| 234 |
+
selectedMenuItem = null;
|
| 235 |
+
chatMessages.innerHTML = '';
|
| 236 |
+
conversation.forEach(msg => addMessage(msg.role, msg.message));
|
| 237 |
+
setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
|
| 238 |
+
};
|
| 239 |
+
chatMessages.appendChild(backButton);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
|
| 243 |
|
| 244 |
function fetchMenuItems(category) {
|
| 245 |
fetch('/get_menu_items', {
|
|
|
|
| 397 |
}
|
| 398 |
}
|
| 399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
|
| 402 |
document.getElementById('userInput').addEventListener('keypress', function(e) {
|
| 403 |
if (e.key === 'Enter') {
|