From c9e76819e99aa773e137ee0f8e08efb282aae358 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 11 Mar 2025 09:38:49 -0600 Subject: [PATCH] initialize listing data --- .../api/buster_rest/chats/queryRequests.ts | 13 +++--------- web/src/api/buster_rest/metrics/requests.ts | 20 +++++++++---------- web/src/api/query_keys/chat.ts | 3 ++- .../useBusterChatListByFilter.tsx | 4 +--- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/web/src/api/buster_rest/chats/queryRequests.ts b/web/src/api/buster_rest/chats/queryRequests.ts index 57ca1e942..4e4d15412 100644 --- a/web/src/api/buster_rest/chats/queryRequests.ts +++ b/web/src/api/buster_rest/chats/queryRequests.ts @@ -8,25 +8,18 @@ import { updateChat, deleteChat } from './requests'; -import type { BusterChatListItem, IBusterChat } from '@/api/asset_interfaces/chat'; +import type { IBusterChat } from '@/api/asset_interfaces/chat'; import { queryKeys } from '@/api/query_keys'; import { updateChatToIChat } from '@/lib/chat'; import { RustApiError } from '@/api/buster_rest/errors'; export const useGetListChats = (params?: Parameters[0]) => { - const queryFn = useMemoizedFn((): Promise => { - return getListChats(params); - }); + const queryFn = useMemoizedFn(() => getListChats(params)); - const res = useQuery({ + return useQuery({ ...queryKeys.chatsGetList(params), queryFn }); - - return { - ...res, - data: res.data || [] - }; }; export const prefetchGetListChats = async ( diff --git a/web/src/api/buster_rest/metrics/requests.ts b/web/src/api/buster_rest/metrics/requests.ts index 7344fe519..0070a881e 100644 --- a/web/src/api/buster_rest/metrics/requests.ts +++ b/web/src/api/buster_rest/metrics/requests.ts @@ -29,26 +29,24 @@ export const listMetrics_server = async (params: ListMetricsParams) => { return await serverFetch('/metrics/list', { params }); }; -export const getMetricData = async (params: { id: string }) => { - return mainApi.get(`/metrics/data`, { params }).then((res) => res.data); +export const getMetricData = async ({ id }: { id: string }) => { + return mainApi.get(`/metrics/data/${id}`).then((res) => res.data); }; export const updateMetric = async (params: UpdateMetricParams) => { - return mainApi.put(`/metrics/update`, { params }).then((res) => res.data); -}; - -export const deleteMetrics = async (params: { ids: string[] }) => { return mainApi - .delete(`/metrics/delete`, { params }) + .put(`/metrics/update/${params.id}`, { params }) .then((res) => res.data); }; -export const duplicateMetrics = async (params: { +export const deleteMetrics = async (params: { ids: string[] }) => { + return mainApi.delete(`/metrics/delete`, { params }).then((res) => res.data); +}; + +export const duplicateMetric = async (params: { id: string; message_id: string; share_with_same_people: boolean; }) => { - return mainApi - .post(`/metrics/duplicate`, { params }) - .then((res) => res.data); + return mainApi.post(`/metrics/duplicate`, { params }).then((res) => res.data); }; diff --git a/web/src/api/query_keys/chat.ts b/web/src/api/query_keys/chat.ts index 38bfbfdb6..33cf91d8e 100644 --- a/web/src/api/query_keys/chat.ts +++ b/web/src/api/query_keys/chat.ts @@ -27,7 +27,8 @@ const chatsMessagesFetchingData = (messageId: string) => const chatsGetList = (filters?: GetChatListParams) => queryOptions({ queryKey: ['chats', 'list', filters] as const, - staleTime: 10 * 1000 + staleTime: 10 * 1000, + initialData: [] }); const chatsBlackBoxMessages = (messageId: string) => diff --git a/web/src/context/Chats/ChatListProvider/useBusterChatListByFilter.tsx b/web/src/context/Chats/ChatListProvider/useBusterChatListByFilter.tsx index d59690534..6af087310 100644 --- a/web/src/context/Chats/ChatListProvider/useBusterChatListByFilter.tsx +++ b/web/src/context/Chats/ChatListProvider/useBusterChatListByFilter.tsx @@ -12,10 +12,8 @@ export const useBusterChatListByFilter = ( const { data: chatsList, isFetched: isFetchedChatsList } = useGetListChats(filters); - //ACTIONS - return { - list: chatsList || [], + list: chatsList, isFetched: isFetchedChatsList }; };