mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
fix: prevent convo overwrite on convo refresh and combine with remote models handling (#1217)
This commit is contained in:
parent
ebe62ad250
commit
4dab094855
2 changed files with 15 additions and 11 deletions
|
|
@ -1,31 +1,37 @@
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { useGetConvoIdQuery } from 'librechat-data-provider';
|
import { useGetConvoIdQuery, useGetModelsQuery } from 'librechat-data-provider';
|
||||||
import ChatView from '~/components/Chat/ChatView';
|
import ChatView from '~/components/Chat/ChatView';
|
||||||
import useAuthRedirect from './useAuthRedirect';
|
import useAuthRedirect from './useAuthRedirect';
|
||||||
import { useSetStorage } from '~/hooks';
|
import { useNewConvo } from '~/hooks';
|
||||||
import store from '~/store';
|
import store from '~/store';
|
||||||
|
|
||||||
export default function ChatRoute() {
|
export default function ChatRoute() {
|
||||||
const index = 0;
|
const index = 0;
|
||||||
const setStorage = useSetStorage();
|
|
||||||
const { conversationId } = useParams();
|
const { conversationId } = useParams();
|
||||||
const { conversation, setConversation } = store.useCreateConversationAtom(index);
|
const { conversation } = store.useCreateConversationAtom(index);
|
||||||
const { isAuthenticated } = useAuthRedirect();
|
const { isAuthenticated } = useAuthRedirect();
|
||||||
|
const { newConversation } = useNewConvo();
|
||||||
const hasSetConversation = useRef(false);
|
const hasSetConversation = useRef(false);
|
||||||
|
|
||||||
|
const modelsQuery = useGetModelsQuery({ enabled: isAuthenticated });
|
||||||
const initialConvoQuery = useGetConvoIdQuery(conversationId ?? '', {
|
const initialConvoQuery = useGetConvoIdQuery(conversationId ?? '', {
|
||||||
enabled: isAuthenticated && conversationId !== 'new',
|
enabled: isAuthenticated && conversationId !== 'new',
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (initialConvoQuery.data && !hasSetConversation.current) {
|
if (conversationId === 'new' && modelsQuery.data && !hasSetConversation.current) {
|
||||||
setStorage(initialConvoQuery.data);
|
newConversation({ modelsData: modelsQuery.data });
|
||||||
setConversation(initialConvoQuery.data);
|
hasSetConversation.current = true;
|
||||||
|
} else if (initialConvoQuery.data && modelsQuery.data && !hasSetConversation.current) {
|
||||||
|
newConversation({
|
||||||
|
template: initialConvoQuery.data,
|
||||||
|
modelsData: modelsQuery.data,
|
||||||
|
});
|
||||||
hasSetConversation.current = true;
|
hasSetConversation.current = true;
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [initialConvoQuery.data]);
|
}, [initialConvoQuery.data, modelsQuery.data]);
|
||||||
|
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,12 @@ import {
|
||||||
} from 'librechat-data-provider';
|
} from 'librechat-data-provider';
|
||||||
import type { ContextType } from '~/common';
|
import type { ContextType } from '~/common';
|
||||||
import { Nav, MobileNav } from '~/components/Nav';
|
import { Nav, MobileNav } from '~/components/Nav';
|
||||||
import { useAuthContext, useServerStream, useConversation, useNewConvo } from '~/hooks';
|
import { useAuthContext, useServerStream, useConversation } from '~/hooks';
|
||||||
import store from '~/store';
|
import store from '~/store';
|
||||||
|
|
||||||
export default function Root() {
|
export default function Root() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { newConversation } = useConversation();
|
const { newConversation } = useConversation();
|
||||||
const { newConversation: newConvo } = useNewConvo();
|
|
||||||
const { user, isAuthenticated } = useAuthContext();
|
const { user, isAuthenticated } = useAuthContext();
|
||||||
const [navVisible, setNavVisible] = useState(() => {
|
const [navVisible, setNavVisible] = useState(() => {
|
||||||
const savedNavVisible = localStorage.getItem('navVisible');
|
const savedNavVisible = localStorage.getItem('navVisible');
|
||||||
|
|
@ -44,7 +43,6 @@ export default function Root() {
|
||||||
newConversation({}, undefined, modelsQuery.data);
|
newConversation({}, undefined, modelsQuery.data);
|
||||||
} else if (modelsQuery.data) {
|
} else if (modelsQuery.data) {
|
||||||
setModelsConfig(modelsQuery.data);
|
setModelsConfig(modelsQuery.data);
|
||||||
newConvo({ modelsData: modelsQuery.data });
|
|
||||||
} else if (modelsQuery.isError) {
|
} else if (modelsQuery.isError) {
|
||||||
console.error('Failed to get models', modelsQuery.error);
|
console.error('Failed to get models', modelsQuery.error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue