From e522c93243da90d3e2fcbdeae87e3c4e9bb445d2 Mon Sep 17 00:00:00 2001 From: Aj Wazzan Date: Thu, 8 May 2025 23:46:46 -0700 Subject: [PATCH] refactor: enhance thread refetching by adding queryClient invalidation for improved data consistency --- apps/mail/components/mail/mail-list.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/mail/components/mail/mail-list.tsx b/apps/mail/components/mail/mail-list.tsx index 414aea11a..3c70c3b50 100644 --- a/apps/mail/components/mail/mail-list.tsx +++ b/apps/mail/components/mail/mail-list.tsx @@ -178,12 +178,10 @@ const Thread = memo( const { refetch: refetchStats } = useStats(); const { data: getThreadData, isLoading, isGroupThread } = useThread(demo ? null : message.id); const [isStarred, setIsStarred] = useState(false); - const queryClient = useQueryClient(); const trpc = useTRPC(); - + const queryClient = useQueryClient(); const { mutateAsync: toggleStar } = useMutation(trpc.mail.toggleStar.mutationOptions()); - // Set initial star state based on email data useEffect(() => { if (getThreadData?.latest?.tags) { setIsStarred(getThreadData.latest.tags.some((tag) => tag.name === 'STARRED')); @@ -230,7 +228,13 @@ const Thread = memo( toast.promise(promise, { error: t('common.actions.failedToMove'), finally: async () => { - await Promise.all([refetchStats(), refetchThreads()]); + await Promise.all([ + refetchStats(), + refetchThreads(), + queryClient.invalidateQueries({ + queryKey: trpc.mail.get.queryKey({ id: message.id }), + }), + ]); }, }); },