nagasurendra commited on
Commit
f4f01e5
·
verified ·
1 Parent(s): 253a332

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +31 -5
static/script.js CHANGED
@@ -208,10 +208,6 @@ function displaySelectedIngredients() {
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: {
@@ -222,7 +218,21 @@ function submitIngredients(selectedIngredients) {
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
  }
@@ -232,6 +242,22 @@ function submitIngredients(selectedIngredients) {
232
  });
233
  }
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
  function displayOptions(options) {
237
  const chatMessages = document.getElementById('chatMessages');
 
208
  }
209
 
210
  function submitIngredients(selectedIngredients) {
 
 
 
 
211
  fetch('/submit_ingredients', {
212
  method: 'POST',
213
  headers: {
 
218
  .then(response => response.json())
219
  .then(data => {
220
  if (data.success) {
221
+ // Now fetch dish suggestions
222
+ fetch('/get_dish_suggestions', {
223
+ method: 'POST',
224
+ headers: {
225
+ 'Content-Type': 'application/json',
226
+ },
227
+ body: JSON.stringify({ ingredients: selectedIngredients })
228
+ })
229
+ .then(response => response.json())
230
+ .then(suggestionData => {
231
+ if (suggestionData.suggestions) {
232
+ // Display dish suggestions
233
+ displayDishSuggestions(suggestionData.suggestions);
234
+ }
235
+ });
236
  } else {
237
  addMessage('bot', 'There was an issue submitting your ingredients. Please try again.');
238
  }
 
242
  });
243
  }
244
 
245
+ function displayDishSuggestions(suggestions) {
246
+ const chatMessages = document.getElementById('chatMessages');
247
+ if (!chatMessages) {
248
+ console.error('Chat messages container not found for dish suggestions!');
249
+ return;
250
+ }
251
+ addMessage('bot', `Based on your ingredients, here are some dish suggestions:`);
252
+
253
+ // Create and display the suggestions
254
+ const suggestionDiv = document.createElement('div');
255
+ suggestionDiv.className = 'suggestions-list';
256
+ suggestionDiv.textContent = suggestions;
257
+ chatMessages.appendChild(suggestionDiv);
258
+ }
259
+
260
+
261
 
262
  function displayOptions(options) {
263
  const chatMessages = document.getElementById('chatMessages');