Commit c30f3c78 authored by Vũ Hoàng Anh's avatar Vũ Hoàng Anh

chore: update static/index.html - persist user id and auto-load history

parent 91a24d89
......@@ -441,7 +441,7 @@
<div class="header">
<h2>🤖 Canifa AI Chat</h2>
<div class="config-area">
<input type="text" id="userId" placeholder="User ID" value="test_user_009">
<input type="text" id="userId" placeholder="Enter User ID" value="" onblur="saveUserId()" onchange="saveUserId()">
<button onclick="loadHistory(true)">↻ History</button>
<button onclick="clearUI()" style="background: #d32f2f;">✗ Clear UI</button>
</div>
......@@ -590,13 +590,20 @@
async function sendMessage() {
const input = document.getElementById('userInput');
const userId = document.getElementById('userId').value;
const userIdInput = document.getElementById('userId');
const userId = userIdInput.value.trim();
const text = input.value.trim();
const sendBtn = document.getElementById('sendBtn');
const typingIndicator = document.getElementById('typingIndicator');
const chatBox = document.getElementById('chatBox');
if (!text || !userId) return;
if (!userId) {
alert('Please enter a User ID first!');
userIdInput.focus();
return;
}
if (!text) return;
// Disable input
input.disabled = true;
......@@ -613,6 +620,9 @@
input.value = '';
chatBox.scrollTop = chatBox.scrollHeight;
// Save user ID to localStorage
localStorage.setItem('canifa_user_id', userId);
// Track response time
const startTime = Date.now();
......@@ -819,6 +829,28 @@
function clearUI() {
document.getElementById('messagesArea').innerHTML = '';
}
// Save user ID to localStorage (called on input change/blur)
function saveUserId() {
const userIdInput = document.getElementById('userId');
const val = userIdInput.value.trim();
if (val) {
localStorage.setItem('canifa_user_id', val);
} else {
// If empty, remove saved id
localStorage.removeItem('canifa_user_id');
}
}
// Load user ID from localStorage on page load and auto-load history
window.onload = function() {
const savedUserId = localStorage.getItem('canifa_user_id');
if (savedUserId) {
document.getElementById('userId').value = savedUserId;
// Auto-load history for saved user id
setTimeout(() => loadHistory(true), 50);
}
};
</script>
</div> <!-- Close main-content -->
</body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment