Spaces:
Build error
Build error
Update static/script.js
Browse files- static/script.js +36 -35
static/script.js
CHANGED
|
@@ -87,12 +87,16 @@ function handleResponse(userInput) {
|
|
| 87 |
}
|
| 88 |
}
|
| 89 |
function handleYesResponse() {
|
| 90 |
-
const botResponse = 'Here
|
| 91 |
addMessage('bot', botResponse);
|
| 92 |
|
| 93 |
-
//
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
|
|
|
| 96 |
function fetchIngredientsForCustomization(foodPreference) {
|
| 97 |
fetch('/get_ingredients_for_customization', {
|
| 98 |
method: 'POST',
|
|
@@ -123,55 +127,51 @@ function displayCustomizationIngredients(ingredients) {
|
|
| 123 |
return;
|
| 124 |
}
|
| 125 |
|
|
|
|
| 126 |
let ingredientsList = document.querySelector('.customization-ingredients-list');
|
| 127 |
if (!ingredientsList) {
|
| 128 |
ingredientsList = document.createElement('div');
|
| 129 |
ingredientsList.className = 'customization-ingredients-list';
|
| 130 |
chatMessages.appendChild(ingredientsList);
|
| 131 |
} else {
|
| 132 |
-
ingredientsList.innerHTML = '';
|
| 133 |
}
|
| 134 |
|
| 135 |
-
//
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
ingredients.forEach(ingredient => {
|
| 143 |
const item = document.createElement('div');
|
| 144 |
item.className = 'ingredient-item';
|
| 145 |
-
|
| 146 |
-
// Styling for each item (flex and width)
|
| 147 |
-
item.style.flexShrink = '0'; // Prevent shrinking
|
| 148 |
-
item.style.marginRight = '10px'; // Space between items
|
| 149 |
-
item.style.width = '20%'; // Adjust width for responsiveness
|
| 150 |
-
|
| 151 |
-
// Create and append image
|
| 152 |
const img = document.createElement('img');
|
| 153 |
img.src = ingredient.image_url || 'https://via.placeholder.com/80';
|
| 154 |
img.alt = ingredient.name;
|
| 155 |
-
img.style.width = '100%'; // Make image fill the container
|
| 156 |
-
img.style.height = 'auto'; // Maintain aspect ratio
|
| 157 |
-
item.appendChild(img);
|
| 158 |
-
|
| 159 |
-
// Create and append name
|
| 160 |
const name = document.createElement('div');
|
| 161 |
name.textContent = ingredient.name;
|
| 162 |
name.style.textAlign = 'center';
|
| 163 |
name.style.marginTop = '5px';
|
| 164 |
name.style.fontSize = '12px';
|
| 165 |
-
item.appendChild(name);
|
| 166 |
-
|
| 167 |
-
// Create and append the text box (input)
|
| 168 |
-
const inputBox = document.createElement('input');
|
| 169 |
-
inputBox.type = 'text';
|
| 170 |
-
inputBox.placeholder = 'Enter details';
|
| 171 |
-
inputBox.style.marginTop = '5px';
|
| 172 |
-
item.appendChild(inputBox);
|
| 173 |
-
|
| 174 |
-
// Create and append button
|
| 175 |
const button = document.createElement('button');
|
| 176 |
button.textContent = 'Add';
|
| 177 |
button.onclick = () => {
|
|
@@ -180,15 +180,16 @@ function displayCustomizationIngredients(ingredients) {
|
|
| 180 |
displaySelectedCustomizationIngredients();
|
| 181 |
}
|
| 182 |
};
|
|
|
|
|
|
|
| 183 |
item.appendChild(button);
|
| 184 |
-
|
| 185 |
-
// Append the item to the list
|
| 186 |
ingredientsList.appendChild(item);
|
| 187 |
});
|
| 188 |
}
|
| 189 |
|
| 190 |
|
| 191 |
|
|
|
|
| 192 |
function displaySelectedCustomizationIngredients() {
|
| 193 |
const chatMessages = document.getElementById('chatMessages');
|
| 194 |
if (!chatMessages) {
|
|
|
|
| 87 |
}
|
| 88 |
}
|
| 89 |
function handleYesResponse() {
|
| 90 |
+
const botResponse = 'Here is your selected dish:';
|
| 91 |
addMessage('bot', botResponse);
|
| 92 |
|
| 93 |
+
// Display the selected menu item (Name, Image, etc.)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
// Fetch ingredients for customization (both veg and non-veg)
|
| 97 |
+
fetchIngredientsForCustomization('both');
|
| 98 |
}
|
| 99 |
+
|
| 100 |
function fetchIngredientsForCustomization(foodPreference) {
|
| 101 |
fetch('/get_ingredients_for_customization', {
|
| 102 |
method: 'POST',
|
|
|
|
| 127 |
return;
|
| 128 |
}
|
| 129 |
|
| 130 |
+
// Clear previous ingredient lists
|
| 131 |
let ingredientsList = document.querySelector('.customization-ingredients-list');
|
| 132 |
if (!ingredientsList) {
|
| 133 |
ingredientsList = document.createElement('div');
|
| 134 |
ingredientsList.className = 'customization-ingredients-list';
|
| 135 |
chatMessages.appendChild(ingredientsList);
|
| 136 |
} else {
|
| 137 |
+
ingredientsList.innerHTML = ''; // Clear previous list
|
| 138 |
}
|
| 139 |
|
| 140 |
+
// **Display Selected Menu Item First** (inside this function)
|
| 141 |
+
const selectedItemDiv = document.createElement('div');
|
| 142 |
+
selectedItemDiv.className = 'selected-menu-item';
|
| 143 |
+
|
| 144 |
+
// Show the selected menu item
|
| 145 |
+
const itemName = document.createElement('div');
|
| 146 |
+
itemName.className = 'menu-item-name';
|
| 147 |
+
itemName.textContent = selectedMenuItem.name;
|
| 148 |
+
selectedItemDiv.appendChild(itemName);
|
| 149 |
+
|
| 150 |
+
const itemImage = document.createElement('img');
|
| 151 |
+
itemImage.src = selectedMenuItem.image_url || 'https://via.placeholder.com/150';
|
| 152 |
+
itemImage.alt = selectedMenuItem.name;
|
| 153 |
+
selectedItemDiv.appendChild(itemImage);
|
| 154 |
+
|
| 155 |
+
const itemDescription = document.createElement('div');
|
| 156 |
+
itemDescription.className = 'menu-item-description';
|
| 157 |
+
itemDescription.textContent = selectedMenuItem.description || 'No description available.';
|
| 158 |
+
selectedItemDiv.appendChild(itemDescription);
|
| 159 |
+
|
| 160 |
+
// Append selected menu item to the ingredient list container
|
| 161 |
+
ingredientsList.appendChild(selectedItemDiv);
|
| 162 |
+
|
| 163 |
+
// **Display New Ingredients Below the Menu Item**
|
| 164 |
ingredients.forEach(ingredient => {
|
| 165 |
const item = document.createElement('div');
|
| 166 |
item.className = 'ingredient-item';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
const img = document.createElement('img');
|
| 168 |
img.src = ingredient.image_url || 'https://via.placeholder.com/80';
|
| 169 |
img.alt = ingredient.name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
const name = document.createElement('div');
|
| 171 |
name.textContent = ingredient.name;
|
| 172 |
name.style.textAlign = 'center';
|
| 173 |
name.style.marginTop = '5px';
|
| 174 |
name.style.fontSize = '12px';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
const button = document.createElement('button');
|
| 176 |
button.textContent = 'Add';
|
| 177 |
button.onclick = () => {
|
|
|
|
| 180 |
displaySelectedCustomizationIngredients();
|
| 181 |
}
|
| 182 |
};
|
| 183 |
+
item.appendChild(img);
|
| 184 |
+
item.appendChild(name);
|
| 185 |
item.appendChild(button);
|
|
|
|
|
|
|
| 186 |
ingredientsList.appendChild(item);
|
| 187 |
});
|
| 188 |
}
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
+
|
| 193 |
function displaySelectedCustomizationIngredients() {
|
| 194 |
const chatMessages = document.getElementById('chatMessages');
|
| 195 |
if (!chatMessages) {
|