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`)