Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +33 -16
templates/index.html
CHANGED
@@ -502,6 +502,7 @@
|
|
502 |
|
503 |
function resetToPreviousStep() {
|
504 |
console.log('Resetting to previous step. Current step:', currentStep);
|
|
|
505 |
// Based on the currentStep, go back to the previous step
|
506 |
if (currentStep === 'food_type') {
|
507 |
currentStep = 'greeting';
|
@@ -514,7 +515,7 @@ function resetToPreviousStep() {
|
|
514 |
} else if (currentStep === 'customization') {
|
515 |
currentStep = 'menu_display';
|
516 |
console.log('Step changed to menu_display.');
|
517 |
-
|
518 |
} else if (currentStep === 'post_cart') {
|
519 |
currentStep = 'food_type';
|
520 |
conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
|
@@ -523,6 +524,18 @@ function resetToPreviousStep() {
|
|
523 |
console.error('Unexpected currentStep value:', currentStep);
|
524 |
}
|
525 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
526 |
// Ensure the bot message is updated according to the previous step
|
527 |
setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
|
528 |
}
|
@@ -714,28 +727,32 @@ function resetToPreviousStep() {
|
|
714 |
});
|
715 |
}
|
716 |
|
717 |
-
|
|
|
718 |
fetch('/get_ingredients', {
|
719 |
method: 'POST',
|
720 |
headers: { 'Content-Type': 'application/json' },
|
721 |
body: JSON.stringify({ dietary_preference: foodPreference })
|
722 |
})
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
}
|
734 |
-
|
735 |
-
|
736 |
-
|
|
|
|
|
737 |
}
|
738 |
|
|
|
739 |
function fetchMenuItems(params) {
|
740 |
fetch('/get_menu_items', {
|
741 |
method: 'POST',
|
|
|
502 |
|
503 |
function resetToPreviousStep() {
|
504 |
console.log('Resetting to previous step. Current step:', currentStep);
|
505 |
+
|
506 |
// Based on the currentStep, go back to the previous step
|
507 |
if (currentStep === 'food_type') {
|
508 |
currentStep = 'greeting';
|
|
|
515 |
} else if (currentStep === 'customization') {
|
516 |
currentStep = 'menu_display';
|
517 |
console.log('Step changed to menu_display.');
|
518 |
+
fetchMenuItems({ ingredient_names: ingredientNames });
|
519 |
} else if (currentStep === 'post_cart') {
|
520 |
currentStep = 'food_type';
|
521 |
conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
|
|
|
524 |
console.error('Unexpected currentStep value:', currentStep);
|
525 |
}
|
526 |
|
527 |
+
// After going back to 'select_ingredients', trigger the fetchIngredients again
|
528 |
+
if (currentStep === 'select_ingredients') {
|
529 |
+
const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
|
530 |
+
if (lastMessage.includes('vegetarian')) {
|
531 |
+
console.log('Fetching vegetarian ingredients again after back.');
|
532 |
+
fetchIngredients('vegetarian');
|
533 |
+
} else if (lastMessage.includes('non-vegetarian')) {
|
534 |
+
console.log('Fetching non-vegetarian ingredients again after back.');
|
535 |
+
fetchIngredients('non-vegetarian');
|
536 |
+
}
|
537 |
+
}
|
538 |
+
|
539 |
// Ensure the bot message is updated according to the previous step
|
540 |
setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
|
541 |
}
|
|
|
727 |
});
|
728 |
}
|
729 |
|
730 |
+
function fetchIngredients(foodPreference) {
|
731 |
+
console.log('Fetching ingredients for preference:', foodPreference); // Log the request to ensure it's being called
|
732 |
fetch('/get_ingredients', {
|
733 |
method: 'POST',
|
734 |
headers: { 'Content-Type': 'application/json' },
|
735 |
body: JSON.stringify({ dietary_preference: foodPreference })
|
736 |
})
|
737 |
+
.then(response => response.json())
|
738 |
+
.then(data => {
|
739 |
+
console.log('Fetched ingredients:', data); // Log the response data
|
740 |
+
if (data.error) {
|
741 |
+
addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
|
742 |
+
} else {
|
743 |
+
const ingredients = data.ingredients || [];
|
744 |
+
addMessage('bot', 'Please select ingredients:');
|
745 |
+
displayIngredientsList(ingredients);
|
746 |
+
displaySelectedIngredients();
|
747 |
+
}
|
748 |
+
})
|
749 |
+
.catch(error => {
|
750 |
+
console.error('Error fetching ingredients:', error); // Log any errors in the fetch call
|
751 |
+
addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
|
752 |
+
});
|
753 |
}
|
754 |
|
755 |
+
|
756 |
function fetchMenuItems(params) {
|
757 |
fetch('/get_menu_items', {
|
758 |
method: 'POST',
|