|
1 | | -import { memo, useCallback } from 'react'; |
| 1 | +import { memo, useCallback, useEffect } from 'react'; |
2 | 2 | import { useRecoilValue } from 'recoil'; |
3 | 3 | import { useForm } from 'react-hook-form'; |
4 | 4 | import { useParams, useSearchParams } 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'; |
8 | 8 | import { ChatContext, AddedChatContext, useFileMapContext, ChatFormProvider } from '~/Providers'; |
9 | | -import { useChatHelpers, useAddedResponse, useSSE } from '~/hooks'; |
| 9 | +import { useChatHelpers, useAddedResponse, useSSE, usePresets } from '~/hooks'; |
10 | 10 | import ConversationStarters from './Input/ConversationStarters'; |
11 | 11 | //import { useGetMessagesByConvoId } from 'librechat-data-provider/react-query'; |
12 | 12 | import { useGetMessagesByConvoId } from '~/data-provider'; |
@@ -36,10 +36,22 @@ 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 | 40 |
|
40 | 41 | const fileMap = useFileMapContext(); |
41 | 42 | const initialMessage = searchParams.get('initialMessage'); |
| 43 | + const usePresetId = searchParams.get('usePresetId'); |
42 | 44 |
|
| 45 | + useEffect(() => { |
| 46 | + if (usePresetId) { |
| 47 | + const preset = (presetsQuery.data ?? []).find(p => p.presetId == usePresetId) |
| 48 | + if (preset) { |
| 49 | + onSelectPreset(preset); |
| 50 | + searchParams.delete('usePresetId'); |
| 51 | + } |
| 52 | + } |
| 53 | + }, [usePresetId, presetsQuery.data, onSelectPreset]) |
| 54 | + |
43 | 55 | const { data: messagesTree = null, isLoading } = useGetMessagesByConvoId(conversationId ?? '', { |
44 | 56 | select: useCallback( |
45 | 57 | (data: TMessage[]) => { |
|
0 commit comments