checkpoint chat
This commit is contained in:
parent
8044002c06
commit
9750ba524a
@ -33,8 +33,8 @@ function createNewChat() {
|
||||
const newChatId = chatCount++;
|
||||
localStorage.setItem(`chatHistory-${newChatId}`, JSON.stringify([])); // Leeren Chat speichern
|
||||
createChatSessionButton(newChatId); // Button für den neuen Chat erstellen
|
||||
loadChatHistory(newChatId); // Lade den neuen Chat
|
||||
currentChatId = newChatId; // Setze die aktuelle Chat-ID
|
||||
loadChatHistory(currentChatId); // Lade den neuen Chat
|
||||
}
|
||||
|
||||
function saveMessage(chatId, message) {
|
||||
@ -80,6 +80,7 @@ function createChatSessionButton(chatId) {
|
||||
deleteButton.addEventListener('click', (event) => {
|
||||
event.stopPropagation(); // Verhindert, dass der Chat geladen wird, wenn auf Löschen geklickt wird
|
||||
deleteChat(chatId, buttonContainer);
|
||||
clearChat();
|
||||
});
|
||||
|
||||
// Elemente hinzufügen
|
||||
@ -88,10 +89,19 @@ function createChatSessionButton(chatId) {
|
||||
chatList.appendChild(buttonContainer);
|
||||
}
|
||||
|
||||
function clearChat(){
|
||||
const chatBox = document.getElementById('chatBox');
|
||||
chatBox.innerHTML = ''; // Aktuellen Chat leeren
|
||||
}
|
||||
|
||||
function loadChatHistory(chatId) {
|
||||
const chatBox = document.getElementById('chatBox');
|
||||
chatBox.innerHTML = ''; // Aktuellen Chat leeren
|
||||
|
||||
if (currentChatId === null) {
|
||||
return; // Wenn kein Chat ausgewählt ist, nichts laden
|
||||
}
|
||||
|
||||
const chatHistory = JSON.parse(localStorage.getItem(`chatHistory-${chatId}`)) || [];
|
||||
chatHistory.forEach(entry => {
|
||||
const messageElement = document.createElement('div');
|
||||
@ -99,8 +109,6 @@ function loadChatHistory(chatId) {
|
||||
messageElement.innerText = entry.text;
|
||||
chatBox.prepend(messageElement);
|
||||
});
|
||||
|
||||
currentChatId = chatId; // Setze die aktuelle Chat-ID
|
||||
}
|
||||
|
||||
function deleteChat(chatId, buttonContainer) {
|
||||
@ -110,6 +118,7 @@ function deleteChat(chatId, buttonContainer) {
|
||||
buttonContainer.remove();
|
||||
}
|
||||
|
||||
// Lade alle Chat-Sitzungen beim Start
|
||||
function loadAllChatSessions() {
|
||||
Object.keys(localStorage).forEach((key) => {
|
||||
if (key.startsWith('chatHistory-')) {
|
||||
@ -122,6 +131,10 @@ function loadAllChatSessions() {
|
||||
// Lade den neuesten Chat-Verlauf
|
||||
if (chatCount > 0) {
|
||||
loadChatHistory(chatCount - 1);
|
||||
currentChatId = chatCount - 1; // Setze die aktuelle Chat-ID
|
||||
} else {
|
||||
const chatBox = document.getElementById('chatBox');
|
||||
chatBox.innerHTML = ''; // Chat-Box leer, wenn keine Chats existieren
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,4 +172,3 @@ chatInput.addEventListener('keydown', (event) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user