diff --git a/apps/web/src/api/buster-electric/messages/hooks.ts b/apps/web/src/api/buster-electric/messages/hooks.ts index 935ac8f83..97d96deb3 100644 --- a/apps/web/src/api/buster-electric/messages/hooks.ts +++ b/apps/web/src/api/buster-electric/messages/hooks.ts @@ -4,13 +4,12 @@ import { useShape, useShapeStream } from '../instances'; import { useChatUpdate } from '@/context/Chats/useChatUpdate'; import { updateMessageShapeToIChatMessage } from './helpers'; import { useMemoizedFn } from '@/hooks'; -import { prefetchGetListChats, useGetChatMemoized } from '@/api/buster_rest/chats'; +import { prefetchGetChatsList, useGetChatMemoized } from '@/api/buster_rest/chats'; import uniq from 'lodash/uniq'; import type { ChatMessageResponseMessage_File } from '@buster/server-shared/chats'; import type { BusterChatMessage } from '../../asset_interfaces/chat'; import { useQueryClient } from '@tanstack/react-query'; import { dashboardQueryKeys } from '../../query_keys/dashboard'; -import last from 'lodash/last'; import isEmpty from 'lodash/isEmpty'; import { metricsQueryKeys } from '../../query_keys/metric'; @@ -77,7 +76,7 @@ export const useTrackAndUpdateMessageChanges = ( ); }); if (hasFiles) { - prefetchGetListChats(); + prefetchGetChatsList(); } if (!isEmpty(iChatMessage.response_message_ids)) { @@ -85,7 +84,7 @@ export const useTrackAndUpdateMessageChanges = ( } if (iChatMessage.is_completed) { - prefetchGetListChats(); + prefetchGetChatsList(); } } callback?.(iChatMessage); diff --git a/apps/web/src/api/buster_rest/chats/queryRequests.ts b/apps/web/src/api/buster_rest/chats/queryRequests.ts index f4d560daf..a8d5c3805 100644 --- a/apps/web/src/api/buster_rest/chats/queryRequests.ts +++ b/apps/web/src/api/buster_rest/chats/queryRequests.ts @@ -50,9 +50,9 @@ export const useGetListChats = ( }); }; -export const prefetchGetListChats = async ( - params?: Parameters[0], - queryClientProp?: QueryClient +export const prefetchGetChatsList = async ( + queryClientProp?: QueryClient, + params?: Parameters[0] ) => { const queryClient = queryClientProp || new QueryClient(); diff --git a/apps/web/src/context/RoutePrefetcher.tsx b/apps/web/src/context/RoutePrefetcher.tsx index b37f6b55c..e62128f84 100644 --- a/apps/web/src/context/RoutePrefetcher.tsx +++ b/apps/web/src/context/RoutePrefetcher.tsx @@ -6,6 +6,7 @@ import React, { useRef } from 'react'; import { prefetchGetCollectionsList } from '@/api/buster_rest/collections'; import { prefetchGetDashboardsList } from '@/api/buster_rest/dashboards'; import { prefetchGetMetricsList } from '@/api/buster_rest/metrics'; +import { prefetchGetChatsList } from '@/api/buster_rest/chats'; import { useAsyncEffect } from '@/hooks'; import { timeout } from '@/lib'; import { BusterRoutes, createBusterRoute } from '@/routes'; @@ -32,6 +33,7 @@ const LOW_PRIORITY_ROUTES = [ ]; const LOW_PRIORITY_PREFETCH: ((queryClient: QueryClient) => Promise)[] = [ + (queryClient) => prefetchGetChatsList(queryClient), (queryClient) => prefetchGetMetricsList(queryClient), (queryClient) => prefetchGetDashboardsList(queryClient), (queryClient) => prefetchGetCollectionsList(queryClient) @@ -45,7 +47,7 @@ export const RoutePrefetcher: React.FC = React.memo(() => { const isPreFetchedLowPriorityRef = useRef(false); useAsyncEffect(async () => { - const prefetchRoutes = ( + const prefetchRoutes = async ( routes: BusterRoutes[], prefetchFns: typeof LOW_PRIORITY_PREFETCH, priority: 'high' | 'low' @@ -58,8 +60,8 @@ export const RoutePrefetcher: React.FC = React.memo(() => { router.prefetch(path); } - for (const prefetchFn of prefetchFns) { - prefetchFn(queryClient); + for await (const prefetchFn of prefetchFns) { + await prefetchFn(queryClient); } if (priority === 'high') {