Skip to content

Commit 8c0550d

Browse files
author
Brian Genisio
committed
Fixing a bug with redirection and making the preset ID sticky
1 parent 83288da commit 8c0550d

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

client/src/components/Chat/ChatView.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { memo, useCallback, useEffect } from 'react';
22
import { useRecoilValue } from 'recoil';
33
import { useForm } from 'react-hook-form';
4-
import { useParams, useSearchParams } from 'react-router-dom';
4+
import { useParams, useSearchParams, useLocation } from 'react-router-dom';
55
import { Constants } from 'librechat-data-provider';
66
import type { TMessage } from 'librechat-data-provider';
77
import type { ChatFormValues } from '~/common';
@@ -36,21 +36,21 @@ function ChatView({ index = 0 }: { index?: number }) {
3636
const rootSubmission = useRecoilValue(store.submissionByIndex(index));
3737
const addedSubmission = useRecoilValue(store.submissionByIndex(index + 1));
3838
const centerFormOnLanding = useRecoilValue(store.centerFormOnLanding);
39-
const {presetsQuery, onSelectPreset} = usePresets();
39+
const {presetsQuery, onSetDefaultPreset} = usePresets();
4040

4141
const fileMap = useFileMapContext();
4242
const initialMessageFromUrl = searchParams.get('initialMessage');
4343
const usePresetId = searchParams.get('usePresetId');
44-
44+
4545
useEffect(() => {
46-
if (usePresetId) {
47-
const preset = (presetsQuery.data ?? []).find(p => p.presetId == usePresetId)
46+
if (usePresetId && presetsQuery?.data) {
47+
const preset = (presetsQuery?.data ?? []).find(p => p.presetId == usePresetId)
4848
if (preset) {
49-
onSelectPreset(preset);
49+
onSetDefaultPreset(preset);
5050
searchParams.delete('usePresetId');
5151
}
5252
}
53-
}, [usePresetId, presetsQuery.data, onSelectPreset]);
53+
}, [usePresetId, presetsQuery?.data ?? [], onSetDefaultPreset]);
5454

5555
useEffect(() => {
5656
if (initialMessageFromUrl) {

client/src/hooks/AuthContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const AuthContextProvider = ({
9999
}
100100
setError(undefined);
101101

102-
const redirect = document.location.search ? document.location.search.split('redirect=')[1] : '/c/new';
102+
const redirect = document.location.search.includes('redirect=') ? document.location.search.split('redirect=')[1] : '/c/new';
103103
setUserContext({ token, isAuthenticated: true, user, redirect: decodeURIComponent(redirect) });
104104
},
105105
onError: (error: TResError | unknown) => {

0 commit comments

Comments
 (0)