Spaces:
Sleeping
Sleeping
Update templates/customdish.html
Browse files- templates/customdish.html +30 -23
templates/customdish.html
CHANGED
@@ -391,35 +391,30 @@
|
|
391 |
|
392 |
<script>
|
393 |
let currentStep = 'greeting'; // other possible values: 'food_type', 'select_ingredients', 'menu_display', 'customization', 'post_cart'
|
394 |
-
|
395 |
-
let conversation = [
|
396 |
-
{ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" }
|
397 |
-
];
|
398 |
let selectedIngredients = [];
|
399 |
let selectedMenuItem = null;
|
400 |
let cart = [];
|
401 |
-
|
402 |
window.onload = function() {
|
403 |
-
//
|
404 |
if (sessionStorage.getItem('user_name')) {
|
405 |
-
// If user is logged in and name exists in sessionStorage, greet the user
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
|
|
|
|
411 |
} else {
|
412 |
// If name is not in session, ask for the name
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
}, 500);
|
417 |
-
}
|
418 |
};
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
function addMessage(role, message) {
|
424 |
const chatMessages = document.getElementById('chatMessages');
|
425 |
if (!chatMessages) {
|
@@ -431,10 +426,22 @@
|
|
431 |
messageDiv.textContent = message;
|
432 |
chatMessages.appendChild(messageDiv);
|
433 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
434 |
-
console.log(`Added ${role} message: ${message}`);
|
435 |
}
|
436 |
|
437 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
438 |
function sendMessage() {
|
439 |
const userInput = document.getElementById('userInput').value.trim();
|
440 |
if (userInput) {
|
|
|
391 |
|
392 |
<script>
|
393 |
let currentStep = 'greeting'; // other possible values: 'food_type', 'select_ingredients', 'menu_display', 'customization', 'post_cart'
|
394 |
+
let conversation = [];
|
|
|
|
|
|
|
395 |
let selectedIngredients = [];
|
396 |
let selectedMenuItem = null;
|
397 |
let cart = [];
|
398 |
+
|
399 |
window.onload = function() {
|
400 |
+
// Check if the name is in sessionStorage
|
401 |
if (sessionStorage.getItem('user_name')) {
|
402 |
+
// If the user is logged in and name exists in sessionStorage, greet the user
|
403 |
+
const userName = sessionStorage.getItem('user_name'); // Get the user's name from session
|
404 |
+
conversation.push({ role: 'bot', message: `Nice to meet you, ${userName}! 😊 Let's create your perfect meal! What type of food would you prefer?` });
|
405 |
+
displayConversation(); // Function to display the conversation
|
406 |
+
displayOptions([
|
407 |
+
{ text: 'Vegetarian', class: 'green' },
|
408 |
+
{ text: 'Non-Vegetarian', class: 'red' }
|
409 |
+
]);
|
410 |
} else {
|
411 |
// If name is not in session, ask for the name
|
412 |
+
conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
|
413 |
+
displayConversation(); // Function to display the conversation
|
414 |
+
}
|
|
|
|
|
415 |
};
|
416 |
+
|
417 |
+
// Function to add messages to the chat
|
|
|
|
|
418 |
function addMessage(role, message) {
|
419 |
const chatMessages = document.getElementById('chatMessages');
|
420 |
if (!chatMessages) {
|
|
|
426 |
messageDiv.textContent = message;
|
427 |
chatMessages.appendChild(messageDiv);
|
428 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
|
|
429 |
}
|
430 |
|
431 |
+
// Function to display all conversation messages
|
432 |
+
function displayConversation() {
|
433 |
+
const chatMessages = document.getElementById('chatMessages');
|
434 |
+
chatMessages.innerHTML = ''; // Clear previous messages
|
435 |
+
conversation.forEach(msg => {
|
436 |
+
const messageDiv = document.createElement('div');
|
437 |
+
messageDiv.className = msg.role === 'bot' ? 'bot-message' : 'user-message';
|
438 |
+
messageDiv.textContent = msg.message;
|
439 |
+
chatMessages.appendChild(messageDiv);
|
440 |
+
});
|
441 |
+
chatMessages.scrollTop = chatMessages.scrollHeight; // Scroll to bottom
|
442 |
+
}
|
443 |
+
|
444 |
+
// Modified sendMessage function to be triggered automatically or by the user
|
445 |
function sendMessage() {
|
446 |
const userInput = document.getElementById('userInput').value.trim();
|
447 |
if (userInput) {
|