|
1 | 1 | import { memo, useCallback, useEffect } from 'react'; |
2 | 2 | import { useRecoilValue } from 'recoil'; |
3 | 3 | import { useForm } from 'react-hook-form'; |
4 | | -import { useParams, useSearchParams } from 'react-router-dom'; |
| 4 | +import { useParams, useSearchParams, useLocation } from 'react-router-dom'; |
5 | 5 | import { Constants } from 'librechat-data-provider'; |
6 | 6 | import type { TMessage } from 'librechat-data-provider'; |
7 | 7 | import type { ChatFormValues } from '~/common'; |
@@ -36,21 +36,21 @@ function ChatView({ index = 0 }: { index?: number }) { |
36 | 36 | const rootSubmission = useRecoilValue(store.submissionByIndex(index)); |
37 | 37 | const addedSubmission = useRecoilValue(store.submissionByIndex(index + 1)); |
38 | 38 | const centerFormOnLanding = useRecoilValue(store.centerFormOnLanding); |
39 | | - const {presetsQuery, onSelectPreset} = usePresets(); |
| 39 | + const {presetsQuery, onSetDefaultPreset} = usePresets(); |
40 | 40 |
|
41 | 41 | const fileMap = useFileMapContext(); |
42 | 42 | const initialMessageFromUrl = searchParams.get('initialMessage'); |
43 | 43 | const usePresetId = searchParams.get('usePresetId'); |
44 | | - |
| 44 | + |
45 | 45 | 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) |
48 | 48 | if (preset) { |
49 | | - onSelectPreset(preset); |
| 49 | + onSetDefaultPreset(preset); |
50 | 50 | searchParams.delete('usePresetId'); |
51 | 51 | } |
52 | 52 | } |
53 | | - }, [usePresetId, presetsQuery.data, onSelectPreset]); |
| 53 | + }, [usePresetId, presetsQuery?.data ?? [], onSetDefaultPreset]); |
54 | 54 |
|
55 | 55 | useEffect(() => { |
56 | 56 | if (initialMessageFromUrl) { |
|
0 commit comments