Skip to content

Commit 4af72aa

Browse files
mawburndanny-avila
andauthored
✨ feat: implement search parameter updates (danny-avila#7151)
* feat: implement search parameter updates * Update url params when values change reset params on new chat move logic to families.ts revert unchanged files --------- Co-authored-by: Danny Avila <[email protected]>
1 parent f7777a2 commit 4af72aa

File tree

5 files changed

+481
-4
lines changed

5 files changed

+481
-4
lines changed

client/src/hooks/Input/useQueryParams.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default function useQueryParams({
9595
const settingsTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
9696

9797
const methods = useChatFormContext();
98-
const [searchParams] = useSearchParams();
98+
const [searchParams, setSearchParams] = useSearchParams();
9999
const getDefaultConversation = useDefaultConvo();
100100
const modularChat = useRecoilValue(store.modularChat);
101101
const availableTools = useRecoilValue(store.availableTools);
@@ -332,6 +332,12 @@ export default function useQueryParams({
332332

333333
/** Mark processing as complete and clean up as needed */
334334
const success = () => {
335+
const currentParams = new URLSearchParams(searchParams.toString());
336+
currentParams.delete('prompt');
337+
currentParams.delete('q');
338+
currentParams.delete('submit');
339+
340+
setSearchParams(currentParams, { replace: true });
335341
processedRef.current = true;
336342
console.log('Parameters processed successfully');
337343
clearInterval(intervalId);
@@ -407,6 +413,7 @@ export default function useQueryParams({
407413
newQueryConvo,
408414
newConversation,
409415
submitMessage,
416+
setSearchParams,
410417
queryClient,
411418
processSubmission,
412419
]);

client/src/store/families.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { LocalStorageKeys, Constants } from 'librechat-data-provider';
1414
import type { TMessage, TPreset, TConversation, TSubmission } from 'librechat-data-provider';
1515
import type { TOptionSettings, ExtendedFile } from '~/common';
1616
import { useSetConvoContext } from '~/Providers/SetConvoContext';
17-
import { storeEndpointSettings, logger } from '~/utils';
17+
import { storeEndpointSettings, logger, createChatSearchParams } from '~/utils';
18+
import { createSearchParams } from 'react-router-dom';
1819

1920
const latestMessageKeysAtom = atom<(string | number)[]>({
2021
key: 'latestMessageKeys',
@@ -73,9 +74,9 @@ const conversationByIndex = atomFamily<TConversation | null, string | number>({
7374
default: null,
7475
effects: [
7576
({ onSet, node }) => {
76-
onSet(async (newValue) => {
77+
onSet(async (newValue, oldValue) => {
7778
const index = Number(node.key.split('__')[1]);
78-
logger.log('conversation', 'Setting conversation:', { index, newValue });
79+
logger.log('conversation', 'Setting conversation:', { index, newValue, oldValue });
7980
if (newValue?.assistant_id != null && newValue.assistant_id) {
8081
localStorage.setItem(
8182
`${LocalStorageKeys.ASST_ID_PREFIX}${index}${newValue.endpoint}`,
@@ -104,6 +105,18 @@ const conversationByIndex = atomFamily<TConversation | null, string | number>({
104105
`${LocalStorageKeys.LAST_CONVO_SETUP}_${index}`,
105106
JSON.stringify(newValue),
106107
);
108+
109+
const shouldUpdateParams =
110+
newValue.createdAt === '' &&
111+
JSON.stringify(newValue) !== JSON.stringify(oldValue) &&
112+
(oldValue as TConversation)?.conversationId === 'new';
113+
114+
if (shouldUpdateParams) {
115+
const newParams = createChatSearchParams(newValue);
116+
const searchParams = createSearchParams(newParams);
117+
const url = `${window.location.pathname}?${searchParams.toString()}`;
118+
window.history.pushState({}, '', url);
119+
}
107120
});
108121
},
109122
] as const,

0 commit comments

Comments
 (0)