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 './useSocketQueryMutation';
export * from './useSocketQueryOn'; export * from './useSocketQueryOn';
export * from './useSocketQueryEmitAndOnce'; export * from './useSocketQueryEmitAndOnce';
export * from './useSocketQueryEmitOn';

View File

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

View File

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

View File

@ -15,7 +15,7 @@ import type {
} from '@/api/buster_socket'; } from '@/api/buster_socket';
import { useBusterWebSocket } from '@/context/BusterWebSocket'; import { useBusterWebSocket } from '@/context/BusterWebSocket';
import { useMemoizedFn } from 'ahooks'; import { useMemoizedFn } from 'ahooks';
import { queryOptionsConfig } from './queryKeyConfig'; import { queryKeys } from '../asset_interfaces';
import type { import type {
BusterSocketRequestConfig, BusterSocketRequestConfig,
BusterSocketRequestRoute, BusterSocketRequestRoute,
@ -86,28 +86,28 @@ export function useSocketQueryMutation<
}); });
} }
const ExampleComponent = () => { // const ExampleComponent = () => {
const queryClient = useQueryClient(); // const queryClient = useQueryClient();
const options = queryOptionsConfig['/chats/list:getChatsList'](); // const options = queryKeys['/chats/list:getChatsList']();
const data = queryClient.getQueryData(options.queryKey); // const data = queryClient.getQueryData(options.queryKey);
data?.[0].created_by_avatar; // data?.[0].created_by_avatar;
const { mutate } = useSocketQueryMutation< // const { mutate } = useSocketQueryMutation<
'/chats/delete', // '/chats/delete',
'/chats/delete:deleteChat', // '/chats/delete:deleteChat',
unknown, // unknown,
{ id: string }[], // { id: string }[],
{ id: string }[], // { id: string }[],
BusterChatListItem[] // BusterChatListItem[]
>( // >(
{ route: '/chats/delete' }, // { route: '/chats/delete' },
{ route: '/chats/delete:deleteChat' }, // { route: '/chats/delete:deleteChat' },
options, // options,
(currentData, newData) => { // (currentData, newData) => {
currentData?.[0].created_by_avatar; // This should now be properly typed // currentData?.[0].created_by_avatar; // This should now be properly typed
return currentData ?? []; // 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 { useMemo, useRef, useTransition } from 'react';
import type { InferBusterSocketResponseData } from './types'; import type { InferBusterSocketResponseData } from './types';
import { useMemoizedFn, useMount, useUnmount } from 'ahooks'; 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>; type UseSocketQueryOnResult<TData, TError> = UseQueryResult<TData, TError>;
@ -79,23 +82,23 @@ const defaultCallback = <TData, TRoute extends BusterSocketResponseRoute>(
d: InferBusterSocketResponseData<TRoute> d: InferBusterSocketResponseData<TRoute>
) => d as TData; ) => d as TData;
const _ExampleComponent = () => { // const _ExampleComponent = () => {
const options = queryOptionsConfig['/chats/get:getChat']('123'); // const options = queryKeys['/chats/get:getChat']('123');
const { data } = useSocketQueryOn('/chats/get:getChat', options); // const { data } = useSocketQueryOn('/chats/get:getChat', options);
const options2 = queryOptionsConfig['/chats/list:getChatsList'](); // const options2 = queryKeys['/chats/list:getChatsList']();
const { data: data2 } = useSocketQueryOn('/chats/list:getChatsList', options2); // 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 // // Create fresh options for delete chat that match the expected BusterChat type
const deleteChatInitialData = { // const deleteChatInitialData = {
id: '123' // id: '123'
} as unknown as BusterChat; // } as unknown as BusterChat;
const { data: data3 } = useSocketQueryOn('/chats/delete:deleteChat', options3, (d, x) => { // const { data: data3 } = useSocketQueryOn('/chats/delete:deleteChat', options3, (d, x) => {
d?.[0].is_favorited; // d?.[0].is_favorited;
x[0].id; // x[0].id;
return []; // return [];
}); // });
}; // };

View File

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

View File

@ -1,6 +1,6 @@
'use client'; 'use client';
import { useGetPermissionGroupUsers } from '@/api'; import { useGetPermissionGroupUsers } from '@/api/buster_rest';
import { AppMaterialIcons } from '@/components/icons'; import { AppMaterialIcons } from '@/components/icons';
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout'; import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
import { useDebounceSearch } from '@/hooks/useDebounceSearch'; 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 { PermissionAssignedButton } from '@/app/app/_components/PermissionComponents';
import { BusterListSelectedOptionPopupContainer } from '@/components/list'; import { BusterListSelectedOptionPopupContainer } from '@/components/list';
import React from 'react'; import React from 'react';

View File

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