From c5e72d5708f6e16c5188e528b4e44da1e26e56a8 Mon Sep 17 00:00:00 2001 From: Pablo de la Torre Jamardo Date: Sun, 20 Jul 2025 19:54:10 +0200 Subject: [PATCH] Implement delete chat with confirmation dialog --- chat-web-client/src/components/ChatLayout.vue | 16 +++ .../src/components/ChatSidebar.vue | 93 +++++++++++++++- .../src/components/ConfirmDialog.vue | 105 ++++++++++++++++++ chat-web-client/src/services/chatService.ts | 16 +++ 4 files changed, 226 insertions(+), 4 deletions(-) create mode 100644 chat-web-client/src/components/ConfirmDialog.vue diff --git a/chat-web-client/src/components/ChatLayout.vue b/chat-web-client/src/components/ChatLayout.vue index 39063e4..820a03e 100644 --- a/chat-web-client/src/components/ChatLayout.vue +++ b/chat-web-client/src/components/ChatLayout.vue @@ -6,6 +6,7 @@ :current-chat-id="chatUuid" @select-chat="selectChat" @create-chat="createNewChat" + @delete-chat="deleteChat" /> @@ -48,6 +49,9 @@ const loadHistory = async () => { // Cargar mensajes de un chat específico const loadMessages = async (selectedChatId) => { + if (!chatUuid.value) { + return; + } try { const data = await chatService.getChatMessages(selectedChatId) messages.value = data @@ -76,6 +80,18 @@ const createNewChat = async () => { } } +// Eliminar un chat +const deleteChat = async () => { + try { + await chatService.deleteChat(chatUuid.value) + chatUuid.value = null; + await loadHistory() + await loadMessages(chatUuid.value) + } catch (error) { + console.error("Error al crear nuevo chat:", error) + } +} + // Enviar mensaje const sendMessage = async (prompt) => { // Crear nuevo chat si no existe diff --git a/chat-web-client/src/components/ChatSidebar.vue b/chat-web-client/src/components/ChatSidebar.vue index 3545a72..53b7262 100644 --- a/chat-web-client/src/components/ChatSidebar.vue +++ b/chat-web-client/src/components/ChatSidebar.vue @@ -9,15 +9,31 @@ v-for="chat in chats" :key="chat.conversationId" :class="{ active: chat.conversationId === currentChatId }" - @click="$emit('select-chat', chat.conversationId)" - > - {{ chat.title }} + @click="$emit('select-chat', chat.conversationId)"> + {{ chat.title }} + + diff --git a/chat-web-client/src/components/ConfirmDialog.vue b/chat-web-client/src/components/ConfirmDialog.vue new file mode 100644 index 0000000..16177cc --- /dev/null +++ b/chat-web-client/src/components/ConfirmDialog.vue @@ -0,0 +1,105 @@ + + + + + \ No newline at end of file diff --git a/chat-web-client/src/services/chatService.ts b/chat-web-client/src/services/chatService.ts index 9c8bcea..3bfc834 100644 --- a/chat-web-client/src/services/chatService.ts +++ b/chat-web-client/src/services/chatService.ts @@ -39,6 +39,22 @@ class ChatService { } } + async deleteChat(chatId) { + try { + const response = await fetch(`/api/v1/conversations/${chatId}`, { + method: "DELETE", + }) + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + return true + } catch (error) { + console.error("Error removing chat:", error) + toast.error("Could not removing chat") + throw error + } + } + async getChatMessages(chatId) { try { const response = await fetch(`/api/v1/conversations/${chatId}/messages`)