mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-05 01:58:50 +01:00
♻️ refactor: Logout UX, Improved State Teardown, & Remove Unused Code (#5292)
* refactor: SearchBar and Nav components to streamline search functionality and improve state management * refactor: remove refresh conversations * chore: update useNewConvo calls to remove hardcoded default index * refactor: null check for submission in useSSE hook * refactor: remove useConversation hook and update useSearch to utilize useNewConvo * refactor: remove conversation and banner store files; consolidate state management into misc; improve typing of families and add messagesSiblingIdxFamily * refactor: more effectively clear all user/convo state without side effects on logout/delete user * refactor: replace useParams with useLocation in SearchBar to correctly load conversation * refactor: update SearchButtons to use button element and improve conversation ID handling * refactor: use named function for `newConversation` for better call stack tracing * refactor: enhance TermsAndConditionsModal to support array content and improve type definitions for terms of service * refactor: add SetConvoProvider and message invalidation when navigating from search results to prevent initial route rendering edge cases * refactor: rename getLocalStorageItems to localStorage and update imports for consistency * refactor: move clearLocalStorage function to utils and simplify localStorage clearing logic * refactor: migrate authentication mutations to a dedicated Auth data provider and update related tests
This commit is contained in:
parent
24beda3d69
commit
aa80e4594e
45 changed files with 378 additions and 434 deletions
1
client/src/data-provider/Auth/index.ts
Normal file
1
client/src/data-provider/Auth/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from './mutations';
|
||||
65
client/src/data-provider/Auth/mutations.ts
Normal file
65
client/src/data-provider/Auth/mutations.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import { useResetRecoilState } from 'recoil';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { MutationKeys, dataService } from 'librechat-data-provider';
|
||||
import type { UseMutationResult } from '@tanstack/react-query';
|
||||
import type * as t from 'librechat-data-provider';
|
||||
import useClearStates from '~/hooks/Config/useClearStates';
|
||||
import store from '~/store';
|
||||
|
||||
/* login/logout */
|
||||
export const useLogoutUserMutation = (
|
||||
options?: t.LogoutOptions,
|
||||
): UseMutationResult<unknown, unknown, undefined, unknown> => {
|
||||
const queryClient = useQueryClient();
|
||||
const clearStates = useClearStates();
|
||||
const resetDefaultPreset = useResetRecoilState(store.defaultPreset);
|
||||
|
||||
return useMutation([MutationKeys.logoutUser], {
|
||||
mutationFn: () => dataService.logout(),
|
||||
...(options || {}),
|
||||
onSuccess: (...args) => {
|
||||
resetDefaultPreset();
|
||||
clearStates();
|
||||
queryClient.removeQueries();
|
||||
options?.onSuccess?.(...args);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useLoginUserMutation = (): UseMutationResult<
|
||||
t.TLoginResponse,
|
||||
unknown,
|
||||
t.TLoginUser,
|
||||
unknown
|
||||
> => {
|
||||
const queryClient = useQueryClient();
|
||||
const clearStates = useClearStates();
|
||||
const resetDefaultPreset = useResetRecoilState(store.defaultPreset);
|
||||
return useMutation((payload: t.TLoginUser) => dataService.login(payload), {
|
||||
onMutate: () => {
|
||||
resetDefaultPreset();
|
||||
clearStates();
|
||||
queryClient.removeQueries();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/* User */
|
||||
export const useDeleteUserMutation = (
|
||||
options?: t.MutationOptions<unknown, undefined>,
|
||||
): UseMutationResult<unknown, unknown, undefined, unknown> => {
|
||||
const queryClient = useQueryClient();
|
||||
const clearStates = useClearStates();
|
||||
const resetDefaultPreset = useResetRecoilState(store.defaultPreset);
|
||||
|
||||
return useMutation([MutationKeys.deleteUser], {
|
||||
mutationFn: () => dataService.deleteUser(),
|
||||
...(options || {}),
|
||||
onSuccess: (...args) => {
|
||||
resetDefaultPreset();
|
||||
clearStates();
|
||||
queryClient.removeQueries();
|
||||
options?.onSuccess?.(...args);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export * from './Auth';
|
||||
export * from './Agents';
|
||||
export * from './Files';
|
||||
export * from './Tools';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
import {
|
||||
Constants,
|
||||
LocalStorageKeys,
|
||||
InfiniteCollections,
|
||||
defaultAssistantsVersion,
|
||||
ConversationListResponse,
|
||||
} from 'librechat-data-provider';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { dataService, MutationKeys, QueryKeys, defaultOrderQuery } from 'librechat-data-provider';
|
||||
import type * as t from 'librechat-data-provider';
|
||||
|
|
@ -13,7 +11,6 @@ import type { InfiniteData, UseMutationResult } from '@tanstack/react-query';
|
|||
import useUpdateTagsInConvo from '~/hooks/Conversations/useUpdateTagsInConvo';
|
||||
import { updateConversationTag } from '~/utils/conversationTags';
|
||||
import { normalizeData } from '~/utils/collection';
|
||||
import store from '~/store';
|
||||
import {
|
||||
useConversationTagsQuery,
|
||||
useConversationsInfiniteQuery,
|
||||
|
|
@ -692,34 +689,6 @@ export const useDeletePresetMutation = (
|
|||
});
|
||||
};
|
||||
|
||||
/* login/logout */
|
||||
export const useLogoutUserMutation = (
|
||||
options?: t.LogoutOptions,
|
||||
): UseMutationResult<unknown, unknown, undefined, unknown> => {
|
||||
const queryClient = useQueryClient();
|
||||
const setDefaultPreset = useSetRecoilState(store.defaultPreset);
|
||||
return useMutation([MutationKeys.logoutUser], {
|
||||
mutationFn: () => dataService.logout(),
|
||||
|
||||
...(options || {}),
|
||||
onSuccess: (...args) => {
|
||||
options?.onSuccess?.(...args);
|
||||
},
|
||||
onMutate: (...args) => {
|
||||
setDefaultPreset(null);
|
||||
queryClient.removeQueries();
|
||||
localStorage.removeItem(LocalStorageKeys.LAST_CONVO_SETUP);
|
||||
localStorage.removeItem(`${LocalStorageKeys.LAST_CONVO_SETUP}_0`);
|
||||
localStorage.removeItem(`${LocalStorageKeys.LAST_CONVO_SETUP}_1`);
|
||||
localStorage.removeItem(LocalStorageKeys.LAST_MODEL);
|
||||
localStorage.removeItem(LocalStorageKeys.LAST_TOOLS);
|
||||
localStorage.removeItem(LocalStorageKeys.FILES_TO_DELETE);
|
||||
// localStorage.removeItem('lastAssistant');
|
||||
options?.onMutate?.(...args);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/* Avatar upload */
|
||||
export const useUploadAvatarMutation = (
|
||||
options?: t.UploadAvatarOptions,
|
||||
|
|
@ -735,32 +704,6 @@ export const useUploadAvatarMutation = (
|
|||
});
|
||||
};
|
||||
|
||||
export const useDeleteUserMutation = (
|
||||
options?: t.MutationOptions<unknown, undefined>,
|
||||
): UseMutationResult<unknown, unknown, undefined, unknown> => {
|
||||
const queryClient = useQueryClient();
|
||||
const setDefaultPreset = useSetRecoilState(store.defaultPreset);
|
||||
return useMutation([MutationKeys.deleteUser], {
|
||||
mutationFn: () => dataService.deleteUser(),
|
||||
|
||||
...(options || {}),
|
||||
onSuccess: (...args) => {
|
||||
options?.onSuccess?.(...args);
|
||||
},
|
||||
onMutate: (...args) => {
|
||||
setDefaultPreset(null);
|
||||
queryClient.removeQueries();
|
||||
localStorage.removeItem(LocalStorageKeys.LAST_CONVO_SETUP);
|
||||
localStorage.removeItem(`${LocalStorageKeys.LAST_CONVO_SETUP}_0`);
|
||||
localStorage.removeItem(`${LocalStorageKeys.LAST_CONVO_SETUP}_1`);
|
||||
localStorage.removeItem(LocalStorageKeys.LAST_MODEL);
|
||||
localStorage.removeItem(LocalStorageKeys.LAST_TOOLS);
|
||||
localStorage.removeItem(LocalStorageKeys.FILES_TO_DELETE);
|
||||
options?.onMutate?.(...args);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/* Speech to text */
|
||||
export const useSpeechToTextMutation = (
|
||||
options?: t.SpeechToTextOptions,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue