♻️ 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:
Danny Avila 2025-01-12 12:57:10 -05:00 committed by GitHub
parent 24beda3d69
commit aa80e4594e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 378 additions and 434 deletions

View file

@ -1 +1,2 @@
export { default as useAppStartup } from './useAppStartup';
export { default as useClearStates } from './useClearStates';

View file

@ -0,0 +1,52 @@
import { useRecoilCallback } from 'recoil';
import { clearLocalStorage } from '~/utils/localStorage';
import store from '~/store';
export default function useClearStates() {
const clearConversations = store.useClearConvoState();
const clearSubmissions = store.useClearSubmissionState();
const clearLatestMessages = store.useClearLatestMessages();
const clearStates = useRecoilCallback(
({ reset, snapshot }) =>
async (skipFirst?: boolean) => {
await clearSubmissions(skipFirst);
await clearConversations(skipFirst);
await clearLatestMessages(skipFirst);
const keys = await snapshot.getPromise(store.conversationKeysAtom);
for (const key of keys) {
if (skipFirst === true && key === 0) {
continue;
}
reset(store.filesByIndex(key));
reset(store.presetByIndex(key));
reset(store.textByIndex(key));
reset(store.showStopButtonByIndex(key));
reset(store.abortScrollFamily(key));
reset(store.isSubmittingFamily(key));
reset(store.optionSettingsFamily(key));
reset(store.showAgentSettingsFamily(key));
reset(store.showBingToneSettingFamily(key));
reset(store.showPopoverFamily(key));
reset(store.showMentionPopoverFamily(key));
reset(store.showPlusPopoverFamily(key));
reset(store.showPromptsPopoverFamily(key));
reset(store.activePromptByIndex(key));
reset(store.globalAudioURLFamily(key));
reset(store.globalAudioFetchingFamily(key));
reset(store.globalAudioPlayingFamily(key));
reset(store.activeRunFamily(key));
reset(store.audioRunFamily(key));
reset(store.messagesSiblingIdxFamily(key.toString()));
}
clearLocalStorage(skipFirst);
},
[],
);
return clearStates;
}

View file

@ -8,7 +8,7 @@ import store from '~/store';
type TempOverrideType = Record<string, unknown> & {
endpointsConfig: TEndpointsConfig;
modelsConfig: TModelsConfig;
modelsConfig?: TModelsConfig;
combinedOptions: unknown[];
combined: boolean;
};
@ -38,7 +38,7 @@ export default function useConfigOverride() {
);
useEffect(() => {
if (overrideQuery.data) {
if (overrideQuery.data != null) {
handleOverride(overrideQuery.data);
}
}, [overrideQuery.data, handleOverride]);