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

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +14 -0
templates/index.html CHANGED
@@ -982,6 +982,7 @@
982
  console.error('Chat messages container not found for options!');
983
  return;
984
  }
 
985
  options.forEach(opt => {
986
  const button = document.createElement('button');
987
  button.textContent = opt.text;
@@ -989,6 +990,7 @@
989
  button.onclick = () => {
990
  addMessage('user', opt.text);
991
  conversation.push({ role: 'user', message: opt.text });
 
992
  setTimeout(() => handleResponse(opt.text), 500);
993
  };
994
  chatMessages.appendChild(button);
@@ -1000,35 +1002,47 @@
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') {
1034
  sendMessage();
 
982
  console.error('Chat messages container not found for options!');
983
  return;
984
  }
985
+ console.log('Displaying options:', options);
986
  options.forEach(opt => {
987
  const button = document.createElement('button');
988
  button.textContent = opt.text;
 
990
  button.onclick = () => {
991
  addMessage('user', opt.text);
992
  conversation.push({ role: 'user', message: opt.text });
993
+ console.log(`User selected option: ${opt.text}`);
994
  setTimeout(() => handleResponse(opt.text), 500);
995
  };
996
  chatMessages.appendChild(button);
 
1002
  backButton.textContent = 'Go Back';
1003
  backButton.className = 'option-button';
1004
  backButton.onclick = () => {
1005
+ console.log('Back button clicked');
1006
  // Remove last user message and reset currentStep
1007
  conversation.pop();
1008
+ console.log('Removed last user message, conversation length:', conversation.length);
1009
  resetToPreviousStep();
1010
  };
1011
  chatMessages.appendChild(backButton);
1012
  chatMessages.scrollTop = chatMessages.scrollHeight;
1013
+ console.log('Back button added');
1014
  }
1015
 
1016
  function resetToPreviousStep() {
1017
+ console.log('Resetting to previous step. Current step:', currentStep);
1018
  // Based on the currentStep, go back to the previous step
1019
  if (currentStep === 'food_type') {
1020
  currentStep = 'greeting';
1021
  conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
1022
+ console.log('Step changed to greeting. Conversation updated.');
1023
  } else if (currentStep === 'select_ingredients') {
1024
  currentStep = 'food_type';
1025
  conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
1026
+ console.log('Step changed to food_type. Conversation updated.');
1027
  } else if (currentStep === 'customization') {
1028
  currentStep = 'menu_display';
1029
+ console.log('Step changed to menu_display.');
1030
  // You can add logic here to show the menu items again if needed
1031
  } else if (currentStep === 'post_cart') {
1032
  currentStep = 'food_type';
1033
  conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
1034
+ console.log('Step changed to food_type after post_cart. Conversation updated.');
1035
+ } else {
1036
+ console.error('Unexpected currentStep value:', currentStep);
1037
  }
1038
 
1039
  // Ensure the bot message is updated according to the previous step
1040
+ console.log('Updating bot message based on previous step');
1041
  setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
1042
  }
1043
 
1044
 
1045
+
1046
  document.getElementById('userInput').addEventListener('keypress', function(e) {
1047
  if (e.key === 'Enter') {
1048
  sendMessage();