mirror of https://github.com/buster-so/buster.git
rip out duplicate filters thing
This commit is contained in:
parent
e8081b0df1
commit
d0a32dad5d
|
@ -12,12 +12,20 @@ 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';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export const useGetListChats = (params?: Parameters<typeof getListChats>[0]) => {
|
||||
const queryFn = useMemoizedFn(() => getListChats(params));
|
||||
export const useGetListChats = (
|
||||
filters?: Omit<Parameters<typeof getListChats>[0], 'page_token' | 'page_size'>
|
||||
) => {
|
||||
const filtersCompiled: Parameters<typeof getListChats>[0] = useMemo(
|
||||
() => ({ admin_view: false, page_token: 0, page_size: 3000, ...filters }),
|
||||
[filters]
|
||||
);
|
||||
|
||||
const queryFn = useMemoizedFn(() => getListChats(filtersCompiled));
|
||||
|
||||
return useQuery({
|
||||
...queryKeys.chatsGetList(params),
|
||||
...queryKeys.chatsGetList(filtersCompiled),
|
||||
queryFn
|
||||
});
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ const CHATS_BASE = '/chats';
|
|||
export const getListChats = async (params?: GetChatListParams): Promise<BusterChatListItem[]> => {
|
||||
const { page_token = 0, page_size = 1000, admin_view = false } = params || {};
|
||||
return mainApi
|
||||
.get<BusterChatListItem[]>(`${CHATS_BASE}/list`, {
|
||||
.get<BusterChatListItem[]>(`${CHATS_BASE}`, {
|
||||
params: { page_token, page_size, admin_view }
|
||||
})
|
||||
.then((res) => res.data);
|
||||
|
@ -24,7 +24,7 @@ export const getListChats_server = async (
|
|||
params?: GetChatListParams
|
||||
): Promise<BusterChatListItem[]> => {
|
||||
const { page_token = 0, page_size = 1000, admin_view = false } = params || {};
|
||||
return await serverFetch<BusterChatListItem[]>(`${CHATS_BASE}/list`, {
|
||||
return await serverFetch<BusterChatListItem[]>(`${CHATS_BASE}`, {
|
||||
params: { page_token, page_size, admin_view }
|
||||
});
|
||||
};
|
||||
|
|
|
@ -16,8 +16,7 @@ export const useGetOrganizationUsers = (organizationId: string) => {
|
|||
queryKey,
|
||||
staleTime: 10 * 1000,
|
||||
queryFn,
|
||||
enabled: !!organizationId,
|
||||
initialData: []
|
||||
enabled: !!organizationId
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ const chatsMessagesFetchingData = (messageId: string) =>
|
|||
const chatsGetList = (filters?: GetChatListParams) =>
|
||||
queryOptions<BusterChatListItem[]>({
|
||||
queryKey: ['chats', 'list', filters] as const,
|
||||
staleTime: 10 * 1000,
|
||||
staleTime: 0,
|
||||
initialData: []
|
||||
});
|
||||
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useBusterChatListByFilter } from '@/context/Chats';
|
||||
import { ChatItemsContainer } from './ChatItemsContainer';
|
||||
import { useGetListChats } from '@/api/buster_rest/chats';
|
||||
import { GetChatListParams } from '@/api/request_interfaces/chats';
|
||||
|
||||
export const ChatListContainer: React.FC<{}> = ({}) => {
|
||||
const [filters, setFilters] = useState<Parameters<typeof useBusterChatListByFilter>[0]>({
|
||||
const [filters, setFilters] = useState<Partial<GetChatListParams>>({
|
||||
admin_view: false
|
||||
});
|
||||
|
||||
const { list, isFetched } = useBusterChatListByFilter(filters);
|
||||
const { data: list, isFetched } = useGetListChats(filters);
|
||||
|
||||
return <ChatItemsContainer chats={list} loading={!isFetched} />;
|
||||
};
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export * from './useBusterChatListByFilter';
|
|
@ -1,19 +0,0 @@
|
|||
import { useGetListChats } from '@/api/buster_rest/chats';
|
||||
import { GetChatListParams } from '@/api/request_interfaces/chats';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export const useBusterChatListByFilter = (
|
||||
filtersProp: Omit<GetChatListParams, 'page_token' | 'page_size'>
|
||||
) => {
|
||||
const filters = useMemo(
|
||||
() => ({ ...filtersProp, page_token: 0, page_size: 3000 }),
|
||||
[filtersProp]
|
||||
);
|
||||
|
||||
const { data: chatsList, isFetched: isFetchedChatsList } = useGetListChats(filters);
|
||||
|
||||
return {
|
||||
list: chatsList,
|
||||
isFetched: isFetchedChatsList
|
||||
};
|
||||
};
|
|
@ -1,12 +1,6 @@
|
|||
import { useBusterNewChatContextSelector } from './NewChatProvider';
|
||||
import { useBusterChatContextSelector, useMessageIndividual } from './ChatProvider';
|
||||
import { useBusterChatListByFilter } from './ChatListProvider';
|
||||
|
||||
export * from './BusterChatProvider';
|
||||
|
||||
export {
|
||||
useBusterNewChatContextSelector,
|
||||
useBusterChatContextSelector,
|
||||
useBusterChatListByFilter,
|
||||
useMessageIndividual
|
||||
};
|
||||
export { useBusterNewChatContextSelector, useBusterChatContextSelector, useMessageIndividual };
|
||||
|
|
|
@ -18,7 +18,7 @@ export const ChatInput: React.FC<{}> = React.memo(({}) => {
|
|||
return !inputHasText(inputValue);
|
||||
}, [inputValue]);
|
||||
|
||||
const { onSubmitPreflight } = useChatInputFlow({
|
||||
const { onSubmitPreflight, onStopChat } = useChatInputFlow({
|
||||
disableSubmit,
|
||||
inputValue,
|
||||
setInputValue,
|
||||
|
@ -30,10 +30,6 @@ export const ChatInput: React.FC<{}> = React.memo(({}) => {
|
|||
setInputValue(e.target.value);
|
||||
});
|
||||
|
||||
const onStop = useMemoizedFn(() => {
|
||||
// setInputValue('');
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
|
@ -45,7 +41,7 @@ export const ChatInput: React.FC<{}> = React.memo(({}) => {
|
|||
autoResize={autoResizeConfig}
|
||||
onSubmit={onSubmitPreflight}
|
||||
onChange={onChange}
|
||||
onStop={onStop}
|
||||
onStop={onStopChat}
|
||||
loading={loading}
|
||||
disabledSubmit={disableSubmit}
|
||||
autoFocus
|
||||
|
|
|
@ -25,7 +25,7 @@ export const useChatInputFlow = ({
|
|||
const onStartNewChat = useBusterNewChatContextSelector((state) => state.onStartNewChat);
|
||||
const onFollowUpChat = useBusterNewChatContextSelector((state) => state.onFollowUpChat);
|
||||
const onStartChatFromFile = useBusterNewChatContextSelector((state) => state.onStartChatFromFile);
|
||||
const onStopChat = useBusterNewChatContextSelector((state) => state.onStopChat);
|
||||
const onStopChatContext = useBusterNewChatContextSelector((state) => state.onStopChat);
|
||||
const currentMessageId = useChatIndividualContextSelector((x) => x.currentMessageId);
|
||||
|
||||
const flow: FlowType = useMemo(() => {
|
||||
|
@ -39,7 +39,7 @@ export const useChatInputFlow = ({
|
|||
if (disableSubmit || !chatId || !currentMessageId) return;
|
||||
|
||||
if (loading) {
|
||||
onStopChat({ chatId: chatId!, messageId: currentMessageId });
|
||||
onStopChat();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -79,5 +79,11 @@ export const useChatInputFlow = ({
|
|||
}, 50);
|
||||
});
|
||||
|
||||
return { onSubmitPreflight };
|
||||
const onStopChat = useMemoizedFn(() => {
|
||||
onStopChatContext({ chatId: chatId!, messageId: currentMessageId });
|
||||
textAreaRef.current?.focus();
|
||||
textAreaRef.current?.select();
|
||||
});
|
||||
|
||||
return { onSubmitPreflight, onStopChat };
|
||||
};
|
||||
|
|
|
@ -3,7 +3,6 @@ import { createContext, useContextSelector } from 'use-context-selector';
|
|||
import type { SelectedFile } from '../interfaces';
|
||||
import { useAutoChangeLayout } from './useAutoChangeLayout';
|
||||
import { useGetChat } from '@/api/buster_rest/chats';
|
||||
import { useMessageIndividual } from '@/context/Chats';
|
||||
import { useQueries } from '@tanstack/react-query';
|
||||
import { queryKeys } from '@/api/query_keys';
|
||||
import { IBusterChatMessage } from '@/api/asset_interfaces/chat';
|
||||
|
@ -40,10 +39,9 @@ const useChatIndividualContext = ({
|
|||
select: (data: IBusterChatMessage | undefined) => !data?.isCompletedStream,
|
||||
enabled: false
|
||||
};
|
||||
})
|
||||
}).some((query) => query.data);
|
||||
|
||||
console.log('isCompletedStreamQueries', isStreamingMessage);
|
||||
}),
|
||||
combine: (result) => result.some((res) => res.data)
|
||||
});
|
||||
|
||||
useAutoChangeLayout({
|
||||
lastMessageId: currentMessageId,
|
||||
|
|
Loading…
Reference in New Issue