nagasurendra commited on
Commit
ccd555a
·
verified ·
1 Parent(s): 053e585

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +21 -10
static/script.js CHANGED
@@ -87,27 +87,38 @@ function handleResponse(userInput) {
87
  }
88
  }
89
 
90
- function fetchIngredients(foodPreference) {
91
- fetch('/get_ingredients', {
 
 
 
 
 
 
 
 
 
 
92
  method: 'POST',
93
  headers: {
94
  'Content-Type': 'application/json',
95
  },
96
- body: JSON.stringify({ dietary_preference: foodPreference })
97
  })
98
  .then(response => response.json())
99
  .then(data => {
100
- if (data.error) {
101
- addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
 
 
 
 
102
  } else {
103
- const ingredients = data.ingredients || [];
104
- addMessage('bot', 'Please select ingredients:');
105
- displayIngredientsList(ingredients);
106
- displaySelectedIngredients();
107
  }
108
  })
109
  .catch(error => {
110
- addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
111
  });
112
  }
113
 
 
87
  }
88
  }
89
 
90
+ let selectedIngredient = ''; // Store the selected ingredient
91
+
92
+ // Function to handle ingredient selection (example)
93
+ function selectIngredient(ingredient) {
94
+ selectedIngredient = ingredient; // Store the selected ingredient
95
+ console.log(`Selected ingredient: ${selectedIngredient}`);
96
+ // Fetch menu items related to the selected ingredient
97
+ fetchMenuItems(selectedIngredient);
98
+ }
99
+
100
+ function submitIngredients() {
101
+ fetch('/submit_ingredients', {
102
  method: 'POST',
103
  headers: {
104
  'Content-Type': 'application/json',
105
  },
106
+ body: JSON.stringify({ ingredients: selectedIngredients })
107
  })
108
  .then(response => response.json())
109
  .then(data => {
110
+ if (data.success) {
111
+ addMessage('bot', 'Great choice! Now, let\'s see some menu items you can select.');
112
+
113
+ // Fetch the menu items dynamically based on the selected ingredient
114
+ fetchMenuItems(selectedIngredient); // Use dynamically passed selectedIngredient
115
+
116
  } else {
117
+ addMessage('bot', 'There was an issue submitting your ingredients. Please try again.');
 
 
 
118
  }
119
  })
120
  .catch(error => {
121
+ addMessage('bot', `Error: ${error.message}`);
122
  });
123
  }
124