mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +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
|
|
@ -427,6 +427,16 @@ export enum EImageOutputType {
|
|||
JPEG = 'jpeg',
|
||||
}
|
||||
|
||||
const termsOfServiceSchema = z.object({
|
||||
externalUrl: z.string().optional(),
|
||||
openNewTab: z.boolean().optional(),
|
||||
modalAcceptance: z.boolean().optional(),
|
||||
modalTitle: z.string().optional(),
|
||||
modalContent: z.string().or(z.array(z.string())).optional(),
|
||||
});
|
||||
|
||||
export type TTermsOfService = z.infer<typeof termsOfServiceSchema>;
|
||||
|
||||
export const intefaceSchema = z
|
||||
.object({
|
||||
privacyPolicy: z
|
||||
|
|
@ -435,15 +445,7 @@ export const intefaceSchema = z
|
|||
openNewTab: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
termsOfService: z
|
||||
.object({
|
||||
externalUrl: z.string().optional(),
|
||||
openNewTab: z.boolean().optional(),
|
||||
modalAcceptance: z.boolean().optional(),
|
||||
modalTitle: z.string().optional(),
|
||||
modalContent: z.string().or(z.array(z.string())).optional(),
|
||||
})
|
||||
.optional(),
|
||||
termsOfService: termsOfServiceSchema.optional(),
|
||||
endpointsMenu: z.boolean().optional(),
|
||||
modelSelect: z.boolean().optional(),
|
||||
parameters: z.boolean().optional(),
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ export const parseConvo = ({
|
|||
possibleValues,
|
||||
}: {
|
||||
endpoint: EModelEndpoint;
|
||||
endpointType?: EModelEndpoint;
|
||||
endpointType?: EModelEndpoint | null;
|
||||
conversation: Partial<s.TConversation | s.TPreset> | null;
|
||||
possibleValues?: TPossibleValues;
|
||||
// TODO: POC for default schema
|
||||
|
|
@ -338,7 +338,7 @@ export const parseCompactConvo = ({
|
|||
possibleValues,
|
||||
}: {
|
||||
endpoint?: EModelEndpoint;
|
||||
endpointType?: EModelEndpoint;
|
||||
endpointType?: EModelEndpoint | null;
|
||||
conversation: Partial<s.TConversation | s.TPreset>;
|
||||
possibleValues?: TPossibleValues;
|
||||
// TODO: POC for default schema
|
||||
|
|
@ -348,7 +348,7 @@ export const parseCompactConvo = ({
|
|||
throw new Error(`undefined endpoint: ${endpoint}`);
|
||||
}
|
||||
|
||||
let schema = compactEndpointSchemas[endpoint];
|
||||
let schema = compactEndpointSchemas[endpoint] as CompactEndpointSchema | undefined;
|
||||
|
||||
if (!schema && !endpointType) {
|
||||
throw new Error(`Unknown endpoint: ${endpoint}`);
|
||||
|
|
@ -356,7 +356,11 @@ export const parseCompactConvo = ({
|
|||
schema = compactEndpointSchemas[endpointType];
|
||||
}
|
||||
|
||||
const convo = schema.parse(conversation) as s.TConversation;
|
||||
if (!schema) {
|
||||
throw new Error(`Unknown endpointType: ${endpointType}`);
|
||||
}
|
||||
|
||||
const convo = schema.parse(conversation) as s.TConversation | null;
|
||||
// const { models, secondaryModels } = possibleValues ?? {};
|
||||
const { models } = possibleValues ?? {};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import type {
|
|||
UseMutationResult,
|
||||
QueryObserverResult,
|
||||
} from '@tanstack/react-query';
|
||||
import { initialModelsConfig, LocalStorageKeys } from '../config';
|
||||
import { initialModelsConfig } from '../config';
|
||||
import type { TStartupConfig } from '../config';
|
||||
import { defaultOrderQuery } from '../types/assistants';
|
||||
import * as dataService from '../data-service';
|
||||
|
|
@ -302,27 +302,6 @@ export const useUpdateTokenCountMutation = (): UseMutationResult<
|
|||
});
|
||||
};
|
||||
|
||||
export const useLoginUserMutation = (): UseMutationResult<
|
||||
t.TLoginResponse,
|
||||
unknown,
|
||||
t.TLoginUser,
|
||||
unknown
|
||||
> => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation((payload: t.TLoginUser) => dataService.login(payload), {
|
||||
onMutate: () => {
|
||||
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');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useRegisterUserMutation = (
|
||||
options?: m.RegistrationOptions,
|
||||
): UseMutationResult<t.TError, unknown, t.TRegisterUser, unknown> => {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ export * from './schemas';
|
|||
|
||||
export type TMessages = TMessage[];
|
||||
|
||||
export type TMessagesAtom = TMessages | null;
|
||||
|
||||
/* TODO: Cleanup EndpointOption types */
|
||||
export type TEndpointOption = {
|
||||
endpoint: EModelEndpoint;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue