Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +13 -16
static/script.js
CHANGED
|
@@ -76,7 +76,6 @@ function handleResponse(userInput) {
|
|
| 76 |
}
|
| 77 |
}
|
| 78 |
|
| 79 |
-
// New function to fetch ingredients based on 'both' condition after clicking 'Yes'
|
| 80 |
function fetchNewStepIngredients() {
|
| 81 |
fetch('/get_ingredients', {
|
| 82 |
method: 'POST',
|
|
@@ -87,25 +86,22 @@ function fetchNewStepIngredients() {
|
|
| 87 |
})
|
| 88 |
.then(response => response.json())
|
| 89 |
.then(data => {
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
} else {
|
| 93 |
-
// Log the data to check its structure
|
| 94 |
-
console.log('Fetched ingredients data:', data);
|
| 95 |
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
if (ingredients.length === 0) {
|
| 98 |
addMessage('bot', 'No ingredients found. Please try again later.');
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
}
|
| 101 |
-
|
| 102 |
-
addMessage('bot', '
|
| 103 |
-
|
| 104 |
-
// Call the new function to display ingredients without the Submit button for the menu item
|
| 105 |
-
displayMenuItemIngredientsWithoutSubmit(selectedMenuItem); // Show ingredients for the selected menu item
|
| 106 |
-
|
| 107 |
-
// Optionally, you can display the selected ingredients or show the customization input
|
| 108 |
-
displayCustomizationInput(); // Show the customization input box below the ingredients
|
| 109 |
}
|
| 110 |
})
|
| 111 |
.catch(error => {
|
|
@@ -113,6 +109,7 @@ function fetchNewStepIngredients() {
|
|
| 113 |
});
|
| 114 |
}
|
| 115 |
|
|
|
|
| 116 |
function displayIngredientsWithoutSubmit(ingredients) {
|
| 117 |
const chatMessages = document.getElementById('chatMessages');
|
| 118 |
if (!chatMessages) {
|
|
|
|
| 76 |
}
|
| 77 |
}
|
| 78 |
|
|
|
|
| 79 |
function fetchNewStepIngredients() {
|
| 80 |
fetch('/get_ingredients', {
|
| 81 |
method: 'POST',
|
|
|
|
| 86 |
})
|
| 87 |
.then(response => response.json())
|
| 88 |
.then(data => {
|
| 89 |
+
// Log the whole response to inspect the structure
|
| 90 |
+
console.log('API Response:', data);
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
// Check if ingredients is present in the response
|
| 93 |
+
if (data && data.ingredients && Array.isArray(data.ingredients)) {
|
| 94 |
+
const ingredients = data.ingredients;
|
| 95 |
if (ingredients.length === 0) {
|
| 96 |
addMessage('bot', 'No ingredients found. Please try again later.');
|
| 97 |
+
} else {
|
| 98 |
+
addMessage('bot', 'Please select ingredients to add to your dish:');
|
| 99 |
+
// Display the ingredients without the submit button
|
| 100 |
+
displayMenuItemIngredientsWithoutSubmit(selectedMenuItem); // Show ingredients for the selected menu item
|
| 101 |
+
displayCustomizationInput(); // Show the customization input below the ingredients
|
| 102 |
}
|
| 103 |
+
} else {
|
| 104 |
+
addMessage('bot', 'Error: Ingredients not found in the response.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
}
|
| 106 |
})
|
| 107 |
.catch(error => {
|
|
|
|
| 109 |
});
|
| 110 |
}
|
| 111 |
|
| 112 |
+
|
| 113 |
function displayIngredientsWithoutSubmit(ingredients) {
|
| 114 |
const chatMessages = document.getElementById('chatMessages');
|
| 115 |
if (!chatMessages) {
|