Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +44 -38
templates/index.html
CHANGED
@@ -500,45 +500,51 @@
|
|
500 |
displayCart();
|
501 |
}
|
502 |
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
|
|
541 |
}
|
|
|
|
|
|
|
|
|
|
|
542 |
|
543 |
|
544 |
function handleYesResponse() {
|
|
|
500 |
displayCart();
|
501 |
}
|
502 |
|
503 |
+
function resetToPreviousStep() {
|
504 |
+
console.log('Resetting to previous step. Current step:', currentStep);
|
505 |
+
|
506 |
+
// Clear selected ingredients and selected menu item, but not the cart
|
507 |
+
selectedIngredients = [];
|
508 |
+
selectedMenuItem = null;
|
509 |
+
cart = [];
|
510 |
+
|
511 |
+
// Based on the currentStep, go back to the previous step
|
512 |
+
if (currentStep === 'food_type') {
|
513 |
+
currentStep = 'greeting';
|
514 |
+
conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
|
515 |
+
console.log('Step changed to greeting. Conversation updated.');
|
516 |
+
} else if (currentStep === 'select_ingredients') {
|
517 |
+
currentStep = 'food_type';
|
518 |
+
conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
|
519 |
+
console.log('Step changed to food_type. Conversation updated.');
|
520 |
+
} else if (currentStep === 'customization') {
|
521 |
+
currentStep = 'menu_display';
|
522 |
+
console.log('Step changed to menu_display.');
|
523 |
+
// If needed, fetch the menu items again
|
524 |
+
//fetchMenuItems({ ingredient_names: ingredientNames });
|
525 |
+
} else if (currentStep === 'post_cart') {
|
526 |
+
currentStep = 'food_type';
|
527 |
+
conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
|
528 |
+
console.log('Step changed to food_type after post_cart. Conversation updated.');
|
529 |
+
} else {
|
530 |
+
console.error('Unexpected currentStep value:', currentStep);
|
531 |
+
}
|
532 |
+
|
533 |
+
// After going back to 'select_ingredients', trigger the fetchIngredients again
|
534 |
+
if (currentStep === 'select_ingredients') {
|
535 |
+
const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
|
536 |
+
if (lastMessage.includes('vegetarian')) {
|
537 |
+
console.log('Fetching vegetarian ingredients again after back.');
|
538 |
+
fetchIngredients('vegetarian');
|
539 |
+
} else if (lastMessage.includes('non-vegetarian')) {
|
540 |
+
console.log('Fetching non-vegetarian ingredients again after back.');
|
541 |
+
fetchIngredients('non-vegetarian');
|
542 |
}
|
543 |
+
}
|
544 |
+
|
545 |
+
// Ensure the bot message is updated according to the previous step
|
546 |
+
setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
|
547 |
+
}
|
548 |
|
549 |
|
550 |
function handleYesResponse() {
|