Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +55 -0
static/script.js
CHANGED
|
@@ -94,6 +94,7 @@ function fetchNewStepIngredients() {
|
|
| 94 |
addMessage('bot', 'Please select ingredients to add to your dish:');
|
| 95 |
// Call the new function to display ingredients without the Submit button
|
| 96 |
displayIngredientsWithoutSubmit(ingredients); // Show ingredients here without the submit button
|
|
|
|
| 97 |
//displaySelectedIngredients(); // Optionally display the selected ingredients in a different area
|
| 98 |
// Then show the customization box for instructions
|
| 99 |
//displayCustomizationInput(); // Show the customization input below
|
|
@@ -155,6 +156,60 @@ function displayIngredientsWithoutSubmit(ingredients) {
|
|
| 155 |
ingredientsList.appendChild(item);
|
| 156 |
});
|
| 157 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
// Display the fetched ingredients
|
| 160 |
function displayIngredientsList(ingredients) {
|
|
|
|
| 94 |
addMessage('bot', 'Please select ingredients to add to your dish:');
|
| 95 |
// Call the new function to display ingredients without the Submit button
|
| 96 |
displayIngredientsWithoutSubmit(ingredients); // Show ingredients here without the submit button
|
| 97 |
+
displayMenuItemIngredientsWithoutSubmit(selectedMenuItem);
|
| 98 |
//displaySelectedIngredients(); // Optionally display the selected ingredients in a different area
|
| 99 |
// Then show the customization box for instructions
|
| 100 |
//displayCustomizationInput(); // Show the customization input below
|
|
|
|
| 156 |
ingredientsList.appendChild(item);
|
| 157 |
});
|
| 158 |
}
|
| 159 |
+
// Display selected ingredients for a menu item (without submit button)
|
| 160 |
+
function displayMenuItemIngredientsWithoutSubmit(menuItem) {
|
| 161 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 162 |
+
if (!chatMessages) {
|
| 163 |
+
console.error('Chat messages container not found for ingredients!');
|
| 164 |
+
return;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
// Create or find the menu item ingredients list container
|
| 168 |
+
let ingredientsList = document.querySelector(`.ingredients-list-for-${menuItem.name}`);
|
| 169 |
+
if (!ingredientsList) {
|
| 170 |
+
ingredientsList = document.createElement('div');
|
| 171 |
+
ingredientsList.className = `ingredients-list-for-${menuItem.name}`;
|
| 172 |
+
ingredientsList.style.overflowX = 'auto'; // Enable horizontal scrolling
|
| 173 |
+
ingredientsList.style.whiteSpace = 'nowrap'; // Prevent line breaks to make it horizontal scroll
|
| 174 |
+
chatMessages.appendChild(ingredientsList);
|
| 175 |
+
} else {
|
| 176 |
+
ingredientsList.innerHTML = ''; // Clear previous content
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
// Loop through each selected ingredient and display it with the "Add" button
|
| 180 |
+
menuItem.ingredients.forEach(ingredient => {
|
| 181 |
+
const item = document.createElement('div');
|
| 182 |
+
item.className = 'ingredient-item';
|
| 183 |
+
item.style.display = 'inline-block'; // Align items horizontally
|
| 184 |
+
item.style.marginRight = '10px'; // Add some space between items
|
| 185 |
+
item.style.textAlign = 'center'; // Center align the ingredient name and button
|
| 186 |
+
|
| 187 |
+
const img = document.createElement('img');
|
| 188 |
+
img.src = ingredient.image_url || 'https://via.placeholder.com/80';
|
| 189 |
+
img.alt = ingredient.name;
|
| 190 |
+
img.style.width = '80px'; // Set the image size
|
| 191 |
+
img.style.height = '80px'; // Set the image size
|
| 192 |
+
|
| 193 |
+
const name = document.createElement('div');
|
| 194 |
+
name.textContent = ingredient.name;
|
| 195 |
+
name.style.marginTop = '5px';
|
| 196 |
+
name.style.fontSize = '12px'; // Adjust the font size of the name
|
| 197 |
+
|
| 198 |
+
const button = document.createElement('button');
|
| 199 |
+
button.textContent = 'Add';
|
| 200 |
+
button.onclick = () => {
|
| 201 |
+
if (!selectedIngredients.some(item => item.name === ingredient.name)) {
|
| 202 |
+
selectedIngredients.push(ingredient); // Add ingredient to the selected list
|
| 203 |
+
displayMenuItemIngredientsWithoutSubmit(menuItem); // Update the list of selected ingredients
|
| 204 |
+
}
|
| 205 |
+
};
|
| 206 |
+
|
| 207 |
+
item.appendChild(img);
|
| 208 |
+
item.appendChild(name);
|
| 209 |
+
item.appendChild(button);
|
| 210 |
+
ingredientsList.appendChild(item);
|
| 211 |
+
});
|
| 212 |
+
}
|
| 213 |
|
| 214 |
// Display the fetched ingredients
|
| 215 |
function displayIngredientsList(ingredients) {
|