Update templates/index.html
Browse files- templates/index.html +43 -21
templates/index.html
CHANGED
|
@@ -106,31 +106,53 @@
|
|
| 106 |
});
|
| 107 |
}
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
|
|
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
const innerDiv = document.createElement('div');
|
| 124 |
-
innerDiv.className = `max-w-3/4 p-3 rounded-lg ${msg.isUser ? 'bg-blue-500 text-white' : 'bg-gray-200'}`;
|
| 125 |
-
innerDiv.innerHTML = marked.parse(msg.content);
|
| 126 |
-
|
| 127 |
-
messageDiv.appendChild(innerDiv);
|
| 128 |
-
chatMessages.appendChild(messageDiv);
|
| 129 |
-
});
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
function clearChatMessages() {
|
| 136 |
chatMessages.innerHTML = '';
|
|
|
|
| 106 |
});
|
| 107 |
}
|
| 108 |
|
| 109 |
+
// Modifiez la fonction loadConversation :
|
| 110 |
+
async function loadConversation(conversationId) {
|
| 111 |
+
if (conversationId === currentConversationId) return;
|
| 112 |
+
|
| 113 |
+
try {
|
| 114 |
+
// Informer le backend du changement de conversation
|
| 115 |
+
const response = await fetch('/switch_conversation', {
|
| 116 |
+
method: 'POST',
|
| 117 |
+
headers: {
|
| 118 |
+
'Content-Type': 'application/json'
|
| 119 |
+
},
|
| 120 |
+
body: JSON.stringify({
|
| 121 |
+
conversation_id: conversationId
|
| 122 |
+
})
|
| 123 |
+
});
|
| 124 |
+
|
| 125 |
+
const data = await response.json();
|
| 126 |
+
if (data.error) {
|
| 127 |
+
alert(`Erreur: ${data.error}`);
|
| 128 |
+
return;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
currentConversationId = conversationId;
|
| 132 |
+
const conversation = conversations.find(c => c.id === conversationId);
|
| 133 |
+
updateConversationsList();
|
| 134 |
+
|
| 135 |
+
if (conversation) {
|
| 136 |
+
clearChatMessages();
|
| 137 |
|
| 138 |
+
conversation.messages.forEach(msg => {
|
| 139 |
+
const messageDiv = document.createElement('div');
|
| 140 |
+
messageDiv.className = `flex ${msg.isUser ? 'justify-end' : ''}`;
|
| 141 |
|
| 142 |
+
const innerDiv = document.createElement('div');
|
| 143 |
+
innerDiv.className = `max-w-3/4 p-3 rounded-lg ${msg.isUser ? 'bg-blue-500 text-white' : 'bg-gray-200'}`;
|
| 144 |
+
innerDiv.innerHTML = marked.parse(msg.content);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
+
messageDiv.appendChild(innerDiv);
|
| 147 |
+
chatMessages.appendChild(messageDiv);
|
| 148 |
+
});
|
| 149 |
+
|
| 150 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 151 |
}
|
| 152 |
+
} catch (error) {
|
| 153 |
+
alert(`Erreur lors du changement de conversation: ${error.message}`);
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
|
| 157 |
function clearChatMessages() {
|
| 158 |
chatMessages.innerHTML = '';
|