Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +41 -0
static/script.js
CHANGED
@@ -190,8 +190,49 @@ function displaySelectedIngredients() {
|
|
190 |
div.textContent = ingredient.name;
|
191 |
selectedArea.appendChild(div);
|
192 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
}
|
194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
function displayOptions(options) {
|
196 |
const chatMessages = document.getElementById('chatMessages');
|
197 |
if (!chatMessages) {
|
|
|
190 |
div.textContent = ingredient.name;
|
191 |
selectedArea.appendChild(div);
|
192 |
});
|
193 |
+
|
194 |
+
// Check if there are selected ingredients
|
195 |
+
if (selectedIngredients.length > 0) {
|
196 |
+
// Create and display the Submit button
|
197 |
+
let submitButton = document.querySelector('.submit-button');
|
198 |
+
if (!submitButton) {
|
199 |
+
submitButton = document.createElement('button');
|
200 |
+
submitButton.className = 'submit-button';
|
201 |
+
submitButton.textContent = 'Submit Ingredients';
|
202 |
+
submitButton.onclick = () => {
|
203 |
+
submitIngredients(selectedIngredients);
|
204 |
+
};
|
205 |
+
chatMessages.appendChild(submitButton);
|
206 |
+
}
|
207 |
+
}
|
208 |
}
|
209 |
|
210 |
+
function submitIngredients(selectedIngredients) {
|
211 |
+
// Here, you can send the selected ingredients to the backend or perform any other action
|
212 |
+
console.log("Submitting ingredients: ", selectedIngredients);
|
213 |
+
|
214 |
+
// Example: Send to the backend (this is just an example, adjust according to your backend)
|
215 |
+
fetch('/submit_ingredients', {
|
216 |
+
method: 'POST',
|
217 |
+
headers: {
|
218 |
+
'Content-Type': 'application/json',
|
219 |
+
},
|
220 |
+
body: JSON.stringify({ ingredients: selectedIngredients })
|
221 |
+
})
|
222 |
+
.then(response => response.json())
|
223 |
+
.then(data => {
|
224 |
+
if (data.success) {
|
225 |
+
addMessage('bot', 'Your ingredients have been successfully submitted!');
|
226 |
+
} else {
|
227 |
+
addMessage('bot', 'There was an issue submitting your ingredients. Please try again.');
|
228 |
+
}
|
229 |
+
})
|
230 |
+
.catch(error => {
|
231 |
+
addMessage('bot', `Error: ${error.message}`);
|
232 |
+
});
|
233 |
+
}
|
234 |
+
|
235 |
+
|
236 |
function displayOptions(options) {
|
237 |
const chatMessages = document.getElementById('chatMessages');
|
238 |
if (!chatMessages) {
|