From 8e27487cbba052edcb344b57459aabaedfbce856 Mon Sep 17 00:00:00 2001 From: Rafi Date: Tue, 7 Mar 2023 17:39:49 +0800 Subject: [PATCH] feat: Conversation editing and deletion --- lang/en-US.json | 1 + lang/zh-CN.json | 1 + layouts/default.vue | 179 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 165 insertions(+), 16 deletions(-) diff --git a/lang/en-US.json b/lang/en-US.json index de0d5f0..60f8780 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -16,6 +16,7 @@ "followSystem": "Follow system", "themeMode": "Theme Mode", "feedback": "Feedback", + "clearConversations": "Clear conversations", "roles": { "me": "Me", "ai": "AI" diff --git a/lang/zh-CN.json b/lang/zh-CN.json index 62845f9..2ed23d3 100644 --- a/lang/zh-CN.json +++ b/lang/zh-CN.json @@ -16,6 +16,7 @@ "followSystem": "跟随系统", "themeMode": "主题模式", "feedback": "反馈", + "clearConversations": "清除会话", "roles": { "me": "我", "ai": "AI" diff --git a/layouts/default.vue b/layouts/default.vue index 2a87f8d..0a9006e 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -25,8 +25,62 @@ const setLang = (lang) => { const conversations = useConversions() -onNuxtReady(async () => { +const editingConversation = ref(null) +const deletingConversationIndex = ref(null) + +const editConversation = (index) => { + editingConversation.value = conversations.value[index] +} + +const updateConversation = async (index) => { + editingConversation.value.updating = true + const { data, error } = await useAuthFetch(`/api/chat/conversations/${editingConversation.value.id}/`, { + method: 'PUT', + body: JSON.stringify({ + topic: editingConversation.value.topic + }) + }) + if (!error.value) { + conversations.value[index] = editingConversation.value + } + editingConversation.value = null +} + +const deleteConversation = async (index) => { + deletingConversationIndex.value = index + const { data, error } = await useAuthFetch(`/api/chat/conversations/${conversations.value[index].id}/`, { + method: 'DELETE' + }) + deletingConversationIndex.value = null + if (!error.value) { + conversations.value.splice(index, 1) + } +} + +const clearConversations = async () => { + deletingConversations.value = true + const { data, error } = await useAuthFetch(`/api/chat/conversations/delete_all`, { + method: 'DELETE' + }) + if (!error.value) { + loadConversations() + clearConfirmDialog.value = false + } + deletingConversations.value = false +} + +const clearConfirmDialog = ref(false) +const deletingConversations = ref(false) +const loadingConversations = ref(false) + +const loadConversations = async () => { + loadingConversations.value = true conversations.value = await getConversions() + loadingConversations.value = false +} + +onNuxtReady(async () => { + loadConversations() }) @@ -39,23 +93,75 @@ onNuxtReady(async () => { v-model="drawer" >
- - New conversation - - + + New conversation + + + + + + + + + + +
@@ -64,6 +170,47 @@ onNuxtReady(async () => { + + + + + Are you sure you want to delete all conversations? + + This will be a permanent deletion and cannot be retrieved once deleted. Please proceed with caution. + + + + Cancel deletion + + + Confirm deletion + + + + +