refactor: enhance thread refetching by adding queryClient invalidation for improved data consistency

This commit is contained in:
Aj Wazzan
2025-05-08 23:46:46 -07:00
parent 7d850b9c35
commit e522c93243

View File

@@ -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 }),
}),
]);
},
});
},