fix some types issues

This commit is contained in:
Nate Kelley 2025-02-13 13:25:41 -07:00
parent d6a5e684b6
commit 01382338b1
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
9 changed files with 65 additions and 62 deletions

View File

@ -1,3 +1,4 @@
export * from './useSocketQueryMutation';
export * from './useSocketQueryOn';
export * from './useSocketQueryEmitAndOnce';
export * from './useSocketQueryEmitOn';

View File

@ -14,7 +14,6 @@ import type {
} from '@/api/buster_socket';
import { useBusterWebSocket } from '@/context/BusterWebSocket';
import { useMemoizedFn } from 'ahooks';
import { queryOptionsConfig } from './queryKeyConfig';
import type { BusterChat } from '@/api/asset_interfaces';
import { InferBusterSocketResponseData } from './types';
@ -63,19 +62,19 @@ export function useSocketQueryEmitAndOnce<
});
}
const ExampleComponent = () => {
const options = queryOptionsConfig['/chats/get:getChat']('123');
// const ExampleComponent = () => {
// const options = queryOptionsConfig['/chats/get:getChat']('123');
const deleteChatInitialData = {
id: '123'
} as unknown as BusterChat;
// const deleteChatInitialData = {
// id: '123'
// } as unknown as BusterChat;
const { data } = useSocketQueryEmitAndOnce(
{ route: '/chats/get', payload: { id: '123' } },
'/chats/get:getChat',
options,
(d, x) => {
return deleteChatInitialData;
}
);
};
// const { data } = useSocketQueryEmitAndOnce(
// { route: '/chats/get', payload: { id: '123' } },
// '/chats/get:getChat',
// options,
// (d, x) => {
// return deleteChatInitialData;
// }
// );
// };

View File

@ -6,7 +6,7 @@ import { useEffect } from 'react';
import { useMemoizedFn } from 'ahooks';
import { useSocketQueryOn } from './useSocketQueryOn';
export const useSocketEmitOn = <
export const useSocketQueryEmitOn = <
TRoute extends BusterSocketResponseRoute,
TError = unknown,
TData = InferBusterSocketResponseData<TRoute>,

View File

@ -15,7 +15,7 @@ import type {
} from '@/api/buster_socket';
import { useBusterWebSocket } from '@/context/BusterWebSocket';
import { useMemoizedFn } from 'ahooks';
import { queryOptionsConfig } from './queryKeyConfig';
import { queryKeys } from '../asset_interfaces';
import type {
BusterSocketRequestConfig,
BusterSocketRequestRoute,
@ -86,28 +86,28 @@ export function useSocketQueryMutation<
});
}
const ExampleComponent = () => {
const queryClient = useQueryClient();
const options = queryOptionsConfig['/chats/list:getChatsList']();
const data = queryClient.getQueryData(options.queryKey);
data?.[0].created_by_avatar;
// const ExampleComponent = () => {
// const queryClient = useQueryClient();
// const options = queryKeys['/chats/list:getChatsList']();
// const data = queryClient.getQueryData(options.queryKey);
// data?.[0].created_by_avatar;
const { mutate } = useSocketQueryMutation<
'/chats/delete',
'/chats/delete:deleteChat',
unknown,
{ id: string }[],
{ id: string }[],
BusterChatListItem[]
>(
{ route: '/chats/delete' },
{ route: '/chats/delete:deleteChat' },
options,
(currentData, newData) => {
currentData?.[0].created_by_avatar; // This should now be properly typed
return currentData ?? [];
}
);
// const { mutate } = useSocketQueryMutation<
// '/chats/delete',
// '/chats/delete:deleteChat',
// unknown,
// { id: string }[],
// { id: string }[],
// BusterChatListItem[]
// >(
// { route: '/chats/delete' },
// { route: '/chats/delete:deleteChat' },
// options,
// (currentData, newData) => {
// currentData?.[0].created_by_avatar; // This should now be properly typed
// return currentData ?? [];
// }
// );
mutate([{ id: '123' }]);
};
// mutate([{ id: '123' }]);
// };

View File

@ -12,8 +12,11 @@ import { useBusterWebSocket } from '@/context/BusterWebSocket';
import { useMemo, useRef, useTransition } from 'react';
import type { InferBusterSocketResponseData } from './types';
import { useMemoizedFn, useMount, useUnmount } from 'ahooks';
import { queryOptionsConfig } from './queryKeyConfig';
import { BusterChat } from '@/api/asset_interfaces';
import { queryKeys } from '../asset_interfaces';
//TEST
import type { BusterChat } from '@/api/asset_interfaces';
type UseSocketQueryOnResult<TData, TError> = UseQueryResult<TData, TError>;
@ -79,23 +82,23 @@ const defaultCallback = <TData, TRoute extends BusterSocketResponseRoute>(
d: InferBusterSocketResponseData<TRoute>
) => d as TData;
const _ExampleComponent = () => {
const options = queryOptionsConfig['/chats/get:getChat']('123');
const { data } = useSocketQueryOn('/chats/get:getChat', options);
// const _ExampleComponent = () => {
// const options = queryKeys['/chats/get:getChat']('123');
// const { data } = useSocketQueryOn('/chats/get:getChat', options);
const options2 = queryOptionsConfig['/chats/list:getChatsList']();
const { data: data2 } = useSocketQueryOn('/chats/list:getChatsList', options2);
// const options2 = queryKeys['/chats/list:getChatsList']();
// const { data: data2 } = useSocketQueryOn('/chats/list:getChatsList', options2);
const options3 = queryOptionsConfig['/chats/delete:deleteChat']('123');
// const options3 = queryKeys['/chats/delete:deleteChat']('123');
// Create fresh options for delete chat that match the expected BusterChat type
const deleteChatInitialData = {
id: '123'
} as unknown as BusterChat;
// // Create fresh options for delete chat that match the expected BusterChat type
// const deleteChatInitialData = {
// id: '123'
// } as unknown as BusterChat;
const { data: data3 } = useSocketQueryOn('/chats/delete:deleteChat', options3, (d, x) => {
d?.[0].is_favorited;
x[0].id;
return [];
});
};
// const { data: data3 } = useSocketQueryOn('/chats/delete:deleteChat', options3, (d, x) => {
// d?.[0].is_favorited;
// x[0].id;
// return [];
// });
// };

View File

@ -1,6 +1,6 @@
'use client';
import { useGetDatasetGroupUsers, useGetPermissionGroupUsers } from '@/api';
import { useGetDatasetGroupUsers } from '@/api/buster_rest';
import { AppMaterialIcons } from '@/components/icons';
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
import { useDebounceSearch } from '@/hooks/useDebounceSearch';

View File

@ -1,6 +1,6 @@
'use client';
import { useGetPermissionGroupUsers } from '@/api';
import { useGetPermissionGroupUsers } from '@/api/buster_rest';
import { AppMaterialIcons } from '@/components/icons';
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
import { useDebounceSearch } from '@/hooks/useDebounceSearch';

View File

@ -1,4 +1,4 @@
import { useUpdateUserPermissionGroups } from '@/api';
import { useUpdateUserPermissionGroups } from '@/api/buster_rest';
import { PermissionAssignedButton } from '@/app/app/_components/PermissionComponents';
import { BusterListSelectedOptionPopupContainer } from '@/components/list';
import React from 'react';

View File

@ -1,4 +1,4 @@
export * from './react';
export * from './dom';
export * from './useDebounceSearch';
export * from './useSocketQuery';
export * from './useWebSocket';