From 7efe811e5299bddb13e7e1a96ee38b31b0b999ef Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Wed, 12 Feb 2025 03:17:47 +0530 Subject: [PATCH] Fix: Avoid unnecessary upsertTags API calls on conversation changes. refactor: rename `LibreDesk` -> `Libredesk` --- frontend/README.md | 2 +- .../conversation/sidebar/ConversationInfo.vue | 3 ++- .../sidebar/ConversationSideBar.vue | 27 ++++++++++++++++--- .../sidebar/ConversationSideBarContact.vue | 2 +- frontend/src/router/index.js | 2 +- frontend/src/stores/conversation.js | 3 ++- frontend/src/views/login/UserLoginView.vue | 4 +-- .../src/views/outerapp/ResetPasswordView.vue | 2 +- .../src/views/outerapp/SetPasswordView.vue | 2 +- schema.sql | 4 +-- static/public/web-templates/index.html | 2 +- 11 files changed, 38 insertions(+), 15 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index b6d2e17..66a31e6 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,4 +1,4 @@ -# LibreDesk frontend +# Libredesk frontend This template should help get you started developing with Vue 3 in Vite. diff --git a/frontend/src/features/conversation/sidebar/ConversationInfo.vue b/frontend/src/features/conversation/sidebar/ConversationInfo.vue index 237acb2..09c558f 100644 --- a/frontend/src/features/conversation/sidebar/ConversationInfo.vue +++ b/frontend/src/features/conversation/sidebar/ConversationInfo.vue @@ -17,9 +17,10 @@

Initiated at

-

+

{{ format(conversation.created_at, 'PPpp') }}

+

-

diff --git a/frontend/src/features/conversation/sidebar/ConversationSideBar.vue b/frontend/src/features/conversation/sidebar/ConversationSideBar.vue index 10d0b43..5428ab2 100644 --- a/frontend/src/features/conversation/sidebar/ConversationSideBar.vue +++ b/frontend/src/features/conversation/sidebar/ConversationSideBar.vue @@ -115,6 +115,7 @@
@@ -206,15 +207,35 @@ const conversationStore = useConversationStore() const usersStore = useUsersStore() const teamsStore = useTeamStore() const tags = ref([]) +let isConversationChange = false + +// Watch for changes in the current conversation and set the flag +watch( + () => conversationStore.current, + (newConversation, oldConversation) => { + // Set the flag when the conversation changes + if (newConversation?.uuid !== oldConversation?.uuid) { + isConversationChange = true + } + }, + { immediate: true } +) onMounted(async () => { await fetchTags() }) +// Watch for changes in the tags and upsert the tags watch( () => conversationStore.current?.tags, (newTags, oldTags) => { - // Check if the tags are the same. + // Skip if the tags change is due to a conversation change. + if (isConversationChange) { + isConversationChange = false + return + } + + // Skip if the tags are the same (deep comparison) if ( Array.isArray(newTags) && Array.isArray(oldTags) && diff --git a/frontend/src/features/conversation/sidebar/ConversationSideBarContact.vue b/frontend/src/features/conversation/sidebar/ConversationSideBarContact.vue index 97d09e1..41fe2f2 100644 --- a/frontend/src/features/conversation/sidebar/ConversationSideBarContact.vue +++ b/frontend/src/features/conversation/sidebar/ConversationSideBarContact.vue @@ -31,7 +31,7 @@ - {{ conversation.contact.email }} + {{ conversation?.contact?.email }}

diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index 6c0b815..da05be9 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -437,7 +437,7 @@ const router = createRouter({ }) router.beforeEach((to, from, next) => { - document.title = to.meta.title + ' - LibreDesk' + document.title = to.meta.title + ' - Libredesk' next() }) diff --git a/frontend/src/stores/conversation.js b/frontend/src/stores/conversation.js index 204eed1..4723fd1 100644 --- a/frontend/src/stores/conversation.js +++ b/frontend/src/stores/conversation.js @@ -185,6 +185,7 @@ export const useConversationStore = defineStore('conversation', () => { const conversationsList = computed(() => { if (!conversations.data) return [] + // Sort conversations based on the selected sort field return [...conversations.data].sort((a, b) => { const field = sortFieldMap[conversations.sortField]?.field if (!a[field] && !b[field]) return 0 @@ -223,7 +224,7 @@ export const useConversationStore = defineStore('conversation', () => { } const current = computed(() => { - return conversation.data + return conversation.data || {} }) const currentBCC = computed(() => { diff --git a/frontend/src/views/login/UserLoginView.vue b/frontend/src/views/login/UserLoginView.vue index 0801f29..7eb0b84 100644 --- a/frontend/src/views/login/UserLoginView.vue +++ b/frontend/src/views/login/UserLoginView.vue @@ -1,7 +1,7 @@