initialize listing data

This commit is contained in:
Nate Kelley 2025-03-11 09:38:49 -06:00
parent ea7ca17b16
commit c9e76819e9
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 15 additions and 25 deletions

View File

@ -8,25 +8,18 @@ import {
updateChat, updateChat,
deleteChat deleteChat
} from './requests'; } 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 { queryKeys } from '@/api/query_keys';
import { updateChatToIChat } from '@/lib/chat'; import { updateChatToIChat } from '@/lib/chat';
import { RustApiError } from '@/api/buster_rest/errors'; import { RustApiError } from '@/api/buster_rest/errors';
export const useGetListChats = (params?: Parameters<typeof getListChats>[0]) => { export const useGetListChats = (params?: Parameters<typeof getListChats>[0]) => {
const queryFn = useMemoizedFn((): Promise<BusterChatListItem[]> => { const queryFn = useMemoizedFn(() => getListChats(params));
return getListChats(params);
});
const res = useQuery({ return useQuery({
...queryKeys.chatsGetList(params), ...queryKeys.chatsGetList(params),
queryFn queryFn
}); });
return {
...res,
data: res.data || []
};
}; };
export const prefetchGetListChats = async ( export const prefetchGetListChats = async (

View File

@ -29,26 +29,24 @@ export const listMetrics_server = async (params: ListMetricsParams) => {
return await serverFetch<BusterMetricListItem[]>('/metrics/list', { params }); return await serverFetch<BusterMetricListItem[]>('/metrics/list', { params });
}; };
export const getMetricData = async (params: { id: string }) => { export const getMetricData = async ({ id }: { id: string }) => {
return mainApi.get<BusterMetricData>(`/metrics/data`, { params }).then((res) => res.data); return mainApi.get<BusterMetricData>(`/metrics/data/${id}`).then((res) => res.data);
}; };
export const updateMetric = async (params: UpdateMetricParams) => { export const updateMetric = async (params: UpdateMetricParams) => {
return mainApi.put<BusterMetric>(`/metrics/update`, { params }).then((res) => res.data);
};
export const deleteMetrics = async (params: { ids: string[] }) => {
return mainApi return mainApi
.delete<BusterMetricListItem[]>(`/metrics/delete`, { params }) .put<BusterMetric>(`/metrics/update/${params.id}`, { params })
.then((res) => res.data); .then((res) => res.data);
}; };
export const duplicateMetrics = async (params: { export const deleteMetrics = async (params: { ids: string[] }) => {
return mainApi.delete<null>(`/metrics/delete`, { params }).then((res) => res.data);
};
export const duplicateMetric = async (params: {
id: string; id: string;
message_id: string; message_id: string;
share_with_same_people: boolean; share_with_same_people: boolean;
}) => { }) => {
return mainApi return mainApi.post<BusterMetric>(`/metrics/duplicate`, { params }).then((res) => res.data);
.post<BusterMetricListItem[]>(`/metrics/duplicate`, { params })
.then((res) => res.data);
}; };

View File

@ -27,7 +27,8 @@ const chatsMessagesFetchingData = (messageId: string) =>
const chatsGetList = (filters?: GetChatListParams) => const chatsGetList = (filters?: GetChatListParams) =>
queryOptions<BusterChatListItem[]>({ queryOptions<BusterChatListItem[]>({
queryKey: ['chats', 'list', filters] as const, queryKey: ['chats', 'list', filters] as const,
staleTime: 10 * 1000 staleTime: 10 * 1000,
initialData: []
}); });
const chatsBlackBoxMessages = (messageId: string) => const chatsBlackBoxMessages = (messageId: string) =>

View File

@ -12,10 +12,8 @@ export const useBusterChatListByFilter = (
const { data: chatsList, isFetched: isFetchedChatsList } = useGetListChats(filters); const { data: chatsList, isFetched: isFetchedChatsList } = useGetListChats(filters);
//ACTIONS
return { return {
list: chatsList || [], list: chatsList,
isFetched: isFetchedChatsList isFetched: isFetchedChatsList
}; };
}; };