checkpoint chat
This commit is contained in:
parent
8044002c06
commit
9750ba524a
@ -33,8 +33,8 @@ function createNewChat() {
|
|||||||
const newChatId = chatCount++;
|
const newChatId = chatCount++;
|
||||||
localStorage.setItem(`chatHistory-${newChatId}`, JSON.stringify([])); // Leeren Chat speichern
|
localStorage.setItem(`chatHistory-${newChatId}`, JSON.stringify([])); // Leeren Chat speichern
|
||||||
createChatSessionButton(newChatId); // Button für den neuen Chat erstellen
|
createChatSessionButton(newChatId); // Button für den neuen Chat erstellen
|
||||||
loadChatHistory(newChatId); // Lade den neuen Chat
|
|
||||||
currentChatId = newChatId; // Setze die aktuelle Chat-ID
|
currentChatId = newChatId; // Setze die aktuelle Chat-ID
|
||||||
|
loadChatHistory(currentChatId); // Lade den neuen Chat
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveMessage(chatId, message) {
|
function saveMessage(chatId, message) {
|
||||||
@ -80,6 +80,7 @@ function createChatSessionButton(chatId) {
|
|||||||
deleteButton.addEventListener('click', (event) => {
|
deleteButton.addEventListener('click', (event) => {
|
||||||
event.stopPropagation(); // Verhindert, dass der Chat geladen wird, wenn auf Löschen geklickt wird
|
event.stopPropagation(); // Verhindert, dass der Chat geladen wird, wenn auf Löschen geklickt wird
|
||||||
deleteChat(chatId, buttonContainer);
|
deleteChat(chatId, buttonContainer);
|
||||||
|
clearChat();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Elemente hinzufügen
|
// Elemente hinzufügen
|
||||||
@ -88,10 +89,19 @@ function createChatSessionButton(chatId) {
|
|||||||
chatList.appendChild(buttonContainer);
|
chatList.appendChild(buttonContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearChat(){
|
||||||
|
const chatBox = document.getElementById('chatBox');
|
||||||
|
chatBox.innerHTML = ''; // Aktuellen Chat leeren
|
||||||
|
}
|
||||||
|
|
||||||
function loadChatHistory(chatId) {
|
function loadChatHistory(chatId) {
|
||||||
const chatBox = document.getElementById('chatBox');
|
const chatBox = document.getElementById('chatBox');
|
||||||
chatBox.innerHTML = ''; // Aktuellen Chat leeren
|
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}`)) || [];
|
const chatHistory = JSON.parse(localStorage.getItem(`chatHistory-${chatId}`)) || [];
|
||||||
chatHistory.forEach(entry => {
|
chatHistory.forEach(entry => {
|
||||||
const messageElement = document.createElement('div');
|
const messageElement = document.createElement('div');
|
||||||
@ -99,8 +109,6 @@ function loadChatHistory(chatId) {
|
|||||||
messageElement.innerText = entry.text;
|
messageElement.innerText = entry.text;
|
||||||
chatBox.prepend(messageElement);
|
chatBox.prepend(messageElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
currentChatId = chatId; // Setze die aktuelle Chat-ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteChat(chatId, buttonContainer) {
|
function deleteChat(chatId, buttonContainer) {
|
||||||
@ -110,6 +118,7 @@ function deleteChat(chatId, buttonContainer) {
|
|||||||
buttonContainer.remove();
|
buttonContainer.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lade alle Chat-Sitzungen beim Start
|
||||||
function loadAllChatSessions() {
|
function loadAllChatSessions() {
|
||||||
Object.keys(localStorage).forEach((key) => {
|
Object.keys(localStorage).forEach((key) => {
|
||||||
if (key.startsWith('chatHistory-')) {
|
if (key.startsWith('chatHistory-')) {
|
||||||
@ -122,6 +131,10 @@ function loadAllChatSessions() {
|
|||||||
// Lade den neuesten Chat-Verlauf
|
// Lade den neuesten Chat-Verlauf
|
||||||
if (chatCount > 0) {
|
if (chatCount > 0) {
|
||||||
loadChatHistory(chatCount - 1);
|
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