nagasurendra commited on
Commit
68917f8
·
verified ·
1 Parent(s): f070a0e

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +25 -3
templates/index.html CHANGED
@@ -994,18 +994,40 @@
994
  chatMessages.appendChild(button);
995
  });
996
  chatMessages.appendChild(document.createElement('br'));
 
 
997
  const backButton = document.createElement('button');
998
  backButton.textContent = 'Go Back';
999
  backButton.className = 'option-button';
1000
  backButton.onclick = () => {
 
1001
  conversation.pop();
1002
- selectedIngredients = [];
1003
- selectedMenuItem = null;
1004
- setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
1005
  };
1006
  chatMessages.appendChild(backButton);
1007
  chatMessages.scrollTop = chatMessages.scrollHeight;
1008
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1009
 
1010
  document.getElementById('userInput').addEventListener('keypress', function(e) {
1011
  if (e.key === 'Enter') {
 
994
  chatMessages.appendChild(button);
995
  });
996
  chatMessages.appendChild(document.createElement('br'));
997
+
998
+ // Back Button Logic
999
  const backButton = document.createElement('button');
1000
  backButton.textContent = 'Go Back';
1001
  backButton.className = 'option-button';
1002
  backButton.onclick = () => {
1003
+ // Remove last user message and reset currentStep
1004
  conversation.pop();
1005
+ resetToPreviousStep();
 
 
1006
  };
1007
  chatMessages.appendChild(backButton);
1008
  chatMessages.scrollTop = chatMessages.scrollHeight;
1009
  }
1010
+
1011
+ function resetToPreviousStep() {
1012
+ // Based on the currentStep, go back to the previous step
1013
+ if (currentStep === 'food_type') {
1014
+ currentStep = 'greeting';
1015
+ conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
1016
+ } else if (currentStep === 'select_ingredients') {
1017
+ currentStep = 'food_type';
1018
+ conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
1019
+ } else if (currentStep === 'customization') {
1020
+ currentStep = 'menu_display';
1021
+ // You can add logic here to show the menu items again if needed
1022
+ } else if (currentStep === 'post_cart') {
1023
+ currentStep = 'food_type';
1024
+ conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
1025
+ }
1026
+
1027
+ // Ensure the bot message is updated according to the previous step
1028
+ setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
1029
+ }
1030
+
1031
 
1032
  document.getElementById('userInput').addEventListener('keypress', function(e) {
1033
  if (e.key === 'Enter') {