optimistically grab new chats

This commit is contained in:
Nate Kelley 2025-07-13 08:17:16 -06:00
parent fa42592b95
commit d7142b838c
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 8 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import { useShape, useShapeStream } from '../instances';
import { useChatUpdate } from '@/context/Chats/useChatUpdate'; import { useChatUpdate } from '@/context/Chats/useChatUpdate';
import { updateMessageShapeToIChatMessage } from './helpers'; import { updateMessageShapeToIChatMessage } from './helpers';
import { useMemoizedFn } from '@/hooks'; import { useMemoizedFn } from '@/hooks';
import { useGetChatMemoized } from '@/api/buster_rest/chats'; import { prefetchGetListChats, useGetChatMemoized } from '@/api/buster_rest/chats';
import uniq from 'lodash/uniq'; import uniq from 'lodash/uniq';
export const useGetMessage = ({ chatId, messageId }: { chatId: string; messageId: string }) => { export const useGetMessage = ({ chatId, messageId }: { chatId: string; messageId: string }) => {
@ -33,6 +33,7 @@ export const useTrackAndUpdateMessageChanges = (
) => { ) => {
const { onUpdateChatMessage, onUpdateChat } = useChatUpdate(); const { onUpdateChatMessage, onUpdateChat } = useChatUpdate();
const getChatMemoized = useGetChatMemoized(); const getChatMemoized = useGetChatMemoized();
const shape = useMemo( const shape = useMemo(
() => messageShape({ chatId: chatId || '', messageId }), () => messageShape({ chatId: chatId || '', messageId }),
[chatId, messageId] [chatId, messageId]
@ -58,6 +59,10 @@ export const useTrackAndUpdateMessageChanges = (
message_ids: allMessageIds message_ids: allMessageIds
}); });
} }
if(iChatMessage.is_completed){
prefetchGetListChats()
}
} }
callback?.(iChatMessage); callback?.(iChatMessage);
onUpdateChatMessage(iChatMessage); onUpdateChatMessage(iChatMessage);

View File

@ -38,7 +38,7 @@ export const useGetListChats = (
filters?: Omit<Parameters<typeof getListChats>[0], 'page_token' | 'page_size'> filters?: Omit<Parameters<typeof getListChats>[0], 'page_token' | 'page_size'>
) => { ) => {
const filtersCompiled: Parameters<typeof getListChats>[0] = useMemo( const filtersCompiled: Parameters<typeof getListChats>[0] = useMemo(
() => ({ admin_view: false, page_token: 0, page_size: 3500, ...filters }), () => ({ admin_view: false, page_token: 0, page_size: 5000, ...filters }),
[filters] [filters]
); );

View File

@ -29,7 +29,7 @@ const chatsGetList = (
filters?: Omit<Parameters<typeof getListChats>[0], 'page_token' | 'page_size'> filters?: Omit<Parameters<typeof getListChats>[0], 'page_token' | 'page_size'>
) => ) =>
queryOptions<ChatListItem[]>({ queryOptions<ChatListItem[]>({
queryKey: ['chats', 'list', filters || { page_token: 0, page_size: 3500 }] as const, queryKey: ['chats', 'list', filters || { page_token: 0, page_size: 5000, admin_view: false }] as const,
staleTime: 60 * 1000, // 1 minute staleTime: 60 * 1000, // 1 minute
initialData: [], initialData: [],
initialDataUpdatedAt: 0 initialDataUpdatedAt: 0