mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-29 14:48:51 +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
|
|
@ -5,7 +5,7 @@ import {
|
|||
isAgentsEndpoint,
|
||||
} from 'librechat-data-provider';
|
||||
import type { TConversation } from 'librechat-data-provider';
|
||||
import getLocalStorageItems from './getLocalStorageItems';
|
||||
import { getLocalStorageItems } from './localStorage';
|
||||
|
||||
const buildDefaultConvo = ({
|
||||
conversation,
|
||||
|
|
|
|||
|
|
@ -4,16 +4,20 @@ import type {
|
|||
TEndpointsConfig,
|
||||
EModelEndpoint,
|
||||
} from 'librechat-data-provider';
|
||||
import getLocalStorageItems from './getLocalStorageItems';
|
||||
import { getLocalStorageItems } from './localStorage';
|
||||
import { mapEndpoints } from './endpoints';
|
||||
|
||||
type TConvoSetup = Partial<TPreset> | Partial<TConversation>;
|
||||
|
||||
type TDefaultEndpoint = { convoSetup: TConvoSetup; endpointsConfig: TEndpointsConfig };
|
||||
|
||||
const getEndpointFromSetup = (convoSetup: TConvoSetup, endpointsConfig: TEndpointsConfig) => {
|
||||
const { endpoint: targetEndpoint } = convoSetup || {};
|
||||
if (targetEndpoint && endpointsConfig?.[targetEndpoint ?? '']) {
|
||||
const getEndpointFromSetup = (
|
||||
convoSetup: TConvoSetup | null,
|
||||
endpointsConfig: TEndpointsConfig,
|
||||
) => {
|
||||
let { endpoint: targetEndpoint = '' } = convoSetup || {};
|
||||
targetEndpoint = targetEndpoint ?? '';
|
||||
if (targetEndpoint && endpointsConfig?.[targetEndpoint]) {
|
||||
return targetEndpoint;
|
||||
} else if (targetEndpoint) {
|
||||
console.warn(`Illegal target endpoint ${targetEndpoint} ${endpointsConfig}`);
|
||||
|
|
@ -24,8 +28,8 @@ const getEndpointFromSetup = (convoSetup: TConvoSetup, endpointsConfig: TEndpoin
|
|||
const getEndpointFromLocalStorage = (endpointsConfig: TEndpointsConfig) => {
|
||||
try {
|
||||
const { lastConversationSetup } = getLocalStorageItems();
|
||||
const { endpoint } = lastConversationSetup;
|
||||
const isDefaultConfig = Object.values(endpointsConfig ?? {})?.every((value) => !value);
|
||||
const { endpoint } = lastConversationSetup ?? { endpoint: null };
|
||||
const isDefaultConfig = Object.values(endpointsConfig ?? {}).every((value) => !value);
|
||||
|
||||
if (isDefaultConfig && endpoint) {
|
||||
return endpoint;
|
||||
|
|
@ -35,7 +39,7 @@ const getEndpointFromLocalStorage = (endpointsConfig: TEndpointsConfig) => {
|
|||
return endpoint;
|
||||
}
|
||||
|
||||
return endpoint && endpointsConfig?.[endpoint ?? ''] ? endpoint : null;
|
||||
return endpoint && endpointsConfig?.[endpoint] != null ? endpoint : null;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return null;
|
||||
|
|
@ -47,9 +51,12 @@ const getDefinedEndpoint = (endpointsConfig: TEndpointsConfig) => {
|
|||
return endpoints.find((e) => Object.hasOwn(endpointsConfig ?? {}, e));
|
||||
};
|
||||
|
||||
const getDefaultEndpoint = ({ convoSetup, endpointsConfig }: TDefaultEndpoint): EModelEndpoint => {
|
||||
const getDefaultEndpoint = ({
|
||||
convoSetup,
|
||||
endpointsConfig,
|
||||
}: TDefaultEndpoint): EModelEndpoint | string | undefined => {
|
||||
return (
|
||||
getEndpointFromSetup(convoSetup, endpointsConfig) ||
|
||||
(getEndpointFromSetup(convoSetup, endpointsConfig) ?? '') ||
|
||||
getEndpointFromLocalStorage(endpointsConfig) ||
|
||||
getDefinedEndpoint(endpointsConfig)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export * from './messages';
|
|||
export * from './languages';
|
||||
export * from './endpoints';
|
||||
export * from './sharedLink';
|
||||
export * from './localStorage';
|
||||
export * from './promptGroups';
|
||||
export { default as cn } from './cn';
|
||||
export { default as logger } from './logger';
|
||||
|
|
@ -21,7 +22,6 @@ export { default as cleanupPreset } from './cleanupPreset';
|
|||
export { default as validateIframe } from './validateIframe';
|
||||
export { default as buildDefaultConvo } from './buildDefaultConvo';
|
||||
export { default as getDefaultEndpoint } from './getDefaultEndpoint';
|
||||
export { default as getLocalStorageItems } from './getLocalStorageItems';
|
||||
|
||||
export const languages = [
|
||||
'java',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { LocalStorageKeys, TConversation } from 'librechat-data-provider';
|
||||
|
||||
export default function getLocalStorageItems() {
|
||||
export function getLocalStorageItems() {
|
||||
const items = {
|
||||
lastSelectedModel: localStorage.getItem(LocalStorageKeys.LAST_MODEL) ?? '',
|
||||
lastSelectedTools: localStorage.getItem(LocalStorageKeys.LAST_TOOLS) ?? '',
|
||||
|
|
@ -23,3 +23,23 @@ export default function getLocalStorageItems() {
|
|||
lastConversationSetup,
|
||||
};
|
||||
}
|
||||
|
||||
export function clearLocalStorage(skipFirst?: boolean) {
|
||||
const keys = Object.keys(localStorage);
|
||||
keys.forEach((key) => {
|
||||
if (skipFirst === true && key.endsWith('0')) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
key.startsWith(LocalStorageKeys.ASST_ID_PREFIX) ||
|
||||
key.startsWith(LocalStorageKeys.AGENT_ID_PREFIX) ||
|
||||
key.startsWith(LocalStorageKeys.LAST_CONVO_SETUP) ||
|
||||
key === LocalStorageKeys.LAST_SPEC ||
|
||||
key === LocalStorageKeys.LAST_TOOLS ||
|
||||
key === LocalStorageKeys.LAST_MODEL ||
|
||||
key === LocalStorageKeys.FILES_TO_DELETE
|
||||
) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue