mirror of https://github.com/buster-so/buster.git
Merge pull request #625 from buster-so/big-nate/bus-1523-when-i-click-cancel-on-the-delete-chat-confirmation-modal-it
bug: on success callback updated
This commit is contained in:
commit
8c49417e40
|
@ -213,7 +213,7 @@ describe('handleExistingChat', () => {
|
|||
|
||||
it('should prepend new message to maintain descending order (newest first)', async () => {
|
||||
const baseTime = new Date('2024-01-01T10:00:00Z');
|
||||
|
||||
|
||||
const mockChat = {
|
||||
id: 'chat-1',
|
||||
title: 'Test Chat',
|
||||
|
@ -292,35 +292,40 @@ describe('handleExistingChat', () => {
|
|||
// getMessagesForChat returns existing messages in descending order (newest first)
|
||||
vi.mocked(database.getMessagesForChat).mockResolvedValue([existingMessage1, existingMessage2]);
|
||||
|
||||
const result = await handleExistingChat('chat-1', 'message-3', 'Third message (newest)', mockUser);
|
||||
const result = await handleExistingChat(
|
||||
'chat-1',
|
||||
'message-3',
|
||||
'Third message (newest)',
|
||||
mockUser
|
||||
);
|
||||
|
||||
expect(result.chat.messages['message-3']).toBeDefined();
|
||||
expect(result.chat.messages['message-1']).toBeDefined();
|
||||
expect(result.chat.messages['message-2']).toBeDefined();
|
||||
|
||||
expect(result.chat.message_ids).toEqual(['message-3', 'message-1', 'message-2']);
|
||||
|
||||
|
||||
expect(result.chat.message_ids[0]).toBe('message-3');
|
||||
|
||||
|
||||
const message3 = result.chat.messages['message-3'];
|
||||
const message1 = result.chat.messages['message-1'];
|
||||
const message2 = result.chat.messages['message-2'];
|
||||
|
||||
|
||||
expect(message3).toBeDefined();
|
||||
expect(message1).toBeDefined();
|
||||
expect(message2).toBeDefined();
|
||||
|
||||
|
||||
const message3Time = new Date(message3!.created_at).getTime();
|
||||
const message1Time = new Date(message1!.created_at).getTime();
|
||||
const message2Time = new Date(message2!.created_at).getTime();
|
||||
|
||||
|
||||
expect(message3Time).toBeGreaterThan(message1Time);
|
||||
expect(message1Time).toBeGreaterThan(message2Time);
|
||||
});
|
||||
|
||||
it('should handle single existing message with new message correctly', async () => {
|
||||
const baseTime = new Date('2024-01-01T10:00:00Z');
|
||||
|
||||
|
||||
const mockChat = {
|
||||
id: 'chat-1',
|
||||
title: 'Test Chat',
|
||||
|
@ -387,13 +392,13 @@ describe('handleExistingChat', () => {
|
|||
expect(result.chat.messages['message-2']).toBeDefined();
|
||||
|
||||
expect(result.chat.message_ids).toEqual(['message-2', 'message-1']);
|
||||
|
||||
|
||||
expect(result.chat.message_ids[0]).toBe('message-2');
|
||||
});
|
||||
|
||||
it('should handle empty existing messages with new message', async () => {
|
||||
const baseTime = new Date('2024-01-01T10:00:00Z');
|
||||
|
||||
|
||||
const mockChat = {
|
||||
id: 'chat-1',
|
||||
title: 'Test Chat',
|
||||
|
|
|
@ -214,7 +214,9 @@ export const useDeleteChat = () => {
|
|||
data: Parameters<typeof deleteChat>[0];
|
||||
useConfirmModal?: boolean;
|
||||
}) => {
|
||||
const method = () => deleteChat(data);
|
||||
const method = async () => {
|
||||
await deleteChat(data);
|
||||
};
|
||||
if (useConfirmModal) {
|
||||
return await openConfirmModal({
|
||||
title: 'Delete Chat',
|
||||
|
@ -228,7 +230,8 @@ export const useDeleteChat = () => {
|
|||
|
||||
return useMutation({
|
||||
mutationFn,
|
||||
onSuccess() {
|
||||
retry: false,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: chatQueryKeys.chatsGetList().queryKey,
|
||||
refetchType: 'all'
|
||||
|
|
|
@ -3,6 +3,7 @@ import type {
|
|||
ConfirmProps as BaseConfirmProps,
|
||||
ConfirmModalProps
|
||||
} from '@/components/ui/modal/ConfirmModal';
|
||||
import { USER_CANCELLED_ERROR } from '../BusterReactQuery/queryClientConfig';
|
||||
|
||||
interface ConfirmProps<T = unknown> extends Omit<BaseConfirmProps, 'onOk'> {
|
||||
title: string | React.ReactNode;
|
||||
|
@ -15,7 +16,7 @@ const defaultConfirmModalProps: ConfirmProps<unknown> = {
|
|||
title: '',
|
||||
content: '',
|
||||
onOk: () => undefined,
|
||||
onCancel: async () => {}
|
||||
onCancel: async () => Promise.reject(USER_CANCELLED_ERROR)
|
||||
};
|
||||
|
||||
interface QueuedModal<T = unknown> extends Omit<ConfirmProps<T>, 'onOk' | 'onCancel'> {
|
||||
|
|
|
@ -57,12 +57,6 @@ export const BusterReactQueryProvider = ({ children }: { children: React.ReactNo
|
|||
);
|
||||
}, []);
|
||||
|
||||
// const busterApiContext = useMemo(() => {
|
||||
// return {
|
||||
// honoInstance: createHonoInstance(BASE_API_URL_V2, checkTokenValidity)
|
||||
// };
|
||||
// }, [checkTokenValidity]);
|
||||
|
||||
useHotkeys(
|
||||
'meta+shift+i',
|
||||
(e) => {
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
import { isServer, QueryClient } from '@tanstack/react-query';
|
||||
import type { useBusterNotifications } from '../BusterNotifications';
|
||||
import { openErrorNotification as openErrorNotificationMethod } from '../BusterNotifications';
|
||||
import {
|
||||
ERROR_RETRY_DELAY,
|
||||
GC_TIME,
|
||||
PREFETCH_STALE_TIME,
|
||||
USER_CANCELLED_ERROR
|
||||
} from './queryClientConfig';
|
||||
|
||||
type OpenErrorNotification = ReturnType<typeof useBusterNotifications>['openErrorNotification'];
|
||||
|
||||
const PREFETCH_STALE_TIME = 1000 * 10; // 10 seconds
|
||||
const ERROR_RETRY_DELAY = 1 * 1000; // 1 second delay after error
|
||||
const GC_TIME = 1000 * 60 * 60 * 24 * 3; // 24 hours - matches persistence duration
|
||||
|
||||
function makeQueryClient(params?: {
|
||||
openErrorNotification?: OpenErrorNotification;
|
||||
enabled?: boolean;
|
||||
|
@ -34,7 +36,7 @@ function makeQueryClient(params?: {
|
|||
},
|
||||
mutations: {
|
||||
retry: (failureCount, error) => {
|
||||
if (params?.openErrorNotification) {
|
||||
if (params?.openErrorNotification && error !== USER_CANCELLED_ERROR) {
|
||||
params.openErrorNotification(error);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export const PREFETCH_STALE_TIME = 1000 * 10; // 10 seconds
|
||||
export const ERROR_RETRY_DELAY = 1 * 1000; // 1 second delay after error
|
||||
export const GC_TIME = 1000 * 60 * 60 * 24 * 3; // 24 hours - matches persistence duration
|
||||
export const USER_CANCELLED_ERROR = new Error('User cancelled');
|
|
@ -112,7 +112,14 @@ const ThreeDotDropdown: React.FC<{
|
|||
icon: <Trash />,
|
||||
onClick: async () => {
|
||||
try {
|
||||
await deleteCollection({ id });
|
||||
await deleteCollection(
|
||||
{ id },
|
||||
{
|
||||
onSuccess: () => {
|
||||
onChangePage({ route: BusterRoutes.APP_COLLECTIONS });
|
||||
}
|
||||
}
|
||||
);
|
||||
onChangePage({ route: BusterRoutes.APP_COLLECTIONS });
|
||||
} catch (error) {
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue