From 09e0e3ec847f1ffc23e1af67ca4d9722a2840215 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 24 Jul 2025 16:56:34 -0600 Subject: [PATCH] On success callback updated --- apps/web/src/api/buster_rest/chats/queryRequests.ts | 7 +++++-- .../context/BusterNotifications/useConfirmModal.ts | 3 ++- .../BusterReactQuery/BusterReactQueryAndApi.tsx | 6 ------ .../src/context/BusterReactQuery/getQueryClient.ts | 12 +++++++----- .../context/BusterReactQuery/queryClientConfig.ts | 4 ++++ .../CollectionIndividualHeader.tsx | 9 ++++++++- 6 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 apps/web/src/context/BusterReactQuery/queryClientConfig.ts diff --git a/apps/web/src/api/buster_rest/chats/queryRequests.ts b/apps/web/src/api/buster_rest/chats/queryRequests.ts index 9ddaf2feb..2e5ab6520 100644 --- a/apps/web/src/api/buster_rest/chats/queryRequests.ts +++ b/apps/web/src/api/buster_rest/chats/queryRequests.ts @@ -214,7 +214,9 @@ export const useDeleteChat = () => { data: Parameters[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' diff --git a/apps/web/src/context/BusterNotifications/useConfirmModal.ts b/apps/web/src/context/BusterNotifications/useConfirmModal.ts index faf3085fa..b7f285acf 100644 --- a/apps/web/src/context/BusterNotifications/useConfirmModal.ts +++ b/apps/web/src/context/BusterNotifications/useConfirmModal.ts @@ -3,6 +3,7 @@ import type { ConfirmProps as BaseConfirmProps, ConfirmModalProps } from '@/components/ui/modal/ConfirmModal'; +import { USER_CANCELLED_ERROR } from '../BusterReactQuery/queryClientConfig'; interface ConfirmProps extends Omit { title: string | React.ReactNode; @@ -15,7 +16,7 @@ const defaultConfirmModalProps: ConfirmProps = { title: '', content: '', onOk: () => undefined, - onCancel: async () => {} + onCancel: async () => Promise.reject(USER_CANCELLED_ERROR) }; interface QueuedModal extends Omit, 'onOk' | 'onCancel'> { diff --git a/apps/web/src/context/BusterReactQuery/BusterReactQueryAndApi.tsx b/apps/web/src/context/BusterReactQuery/BusterReactQueryAndApi.tsx index 6be95b15d..12cf80bee 100644 --- a/apps/web/src/context/BusterReactQuery/BusterReactQueryAndApi.tsx +++ b/apps/web/src/context/BusterReactQuery/BusterReactQueryAndApi.tsx @@ -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) => { diff --git a/apps/web/src/context/BusterReactQuery/getQueryClient.ts b/apps/web/src/context/BusterReactQuery/getQueryClient.ts index 2f851ccd6..31d62a6fc 100644 --- a/apps/web/src/context/BusterReactQuery/getQueryClient.ts +++ b/apps/web/src/context/BusterReactQuery/getQueryClient.ts @@ -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['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; diff --git a/apps/web/src/context/BusterReactQuery/queryClientConfig.ts b/apps/web/src/context/BusterReactQuery/queryClientConfig.ts new file mode 100644 index 000000000..e6414ac07 --- /dev/null +++ b/apps/web/src/context/BusterReactQuery/queryClientConfig.ts @@ -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'); diff --git a/apps/web/src/controllers/CollectionIndividualController/CollectionIndividualHeader.tsx b/apps/web/src/controllers/CollectionIndividualController/CollectionIndividualHeader.tsx index 5aba88b4d..83b5a1fba 100644 --- a/apps/web/src/controllers/CollectionIndividualController/CollectionIndividualHeader.tsx +++ b/apps/web/src/controllers/CollectionIndividualController/CollectionIndividualHeader.tsx @@ -112,7 +112,14 @@ const ThreeDotDropdown: React.FC<{ icon: , onClick: async () => { try { - await deleteCollection({ id }); + await deleteCollection( + { id }, + { + onSuccess: () => { + onChangePage({ route: BusterRoutes.APP_COLLECTIONS }); + } + } + ); onChangePage({ route: BusterRoutes.APP_COLLECTIONS }); } catch (error) { //