From bd18614e77bca3aede7024393ff03f72ea4c6735 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 27 Mar 2025 16:03:55 -0600 Subject: [PATCH] Update useLayoutConfig.ts --- .../useLayoutConfig/useLayoutConfig.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/web/src/layouts/ChatLayout/ChatLayoutContext/useLayoutConfig/useLayoutConfig.ts b/web/src/layouts/ChatLayout/ChatLayoutContext/useLayoutConfig/useLayoutConfig.ts index a409d2587..bf0cdc54a 100644 --- a/web/src/layouts/ChatLayout/ChatLayoutContext/useLayoutConfig/useLayoutConfig.ts +++ b/web/src/layouts/ChatLayout/ChatLayoutContext/useLayoutConfig/useLayoutConfig.ts @@ -8,6 +8,8 @@ import { create } from 'mutative'; import { ChatLayoutView } from '../../interfaces'; import type { SelectedFile } from '../../interfaces'; import { timeout } from '@/lib'; +import { useRouter } from 'next/navigation'; +import { BusterRoutes, createBusterRoute } from '@/routes'; export const useLayoutConfig = ({ selectedFile, @@ -22,6 +24,7 @@ export const useLayoutConfig = ({ animateOpenSplitter: (side: 'left' | 'right' | 'both') => void; onSetSelectedFile: (file: SelectedFile | null) => void; }) => { + const router = useRouter(); const [fileViews, setFileViews] = useState>({}); const selectedFileId = selectedFile?.id; @@ -118,9 +121,25 @@ export const useLayoutConfig = ({ }); }); - const onCollapseFileClick = useMemoizedFn(() => { + const onCollapseFileClick = useMemoizedFn((navigateToChat: boolean = true) => { onSetSelectedFile(null); closeSecondaryView(); + if (navigateToChat && chatId) { + router.prefetch( + createBusterRoute({ + route: BusterRoutes.APP_CHAT_ID, + chatId + }) + ); + setTimeout(() => { + router.push( + createBusterRoute({ + route: BusterRoutes.APP_CHAT_ID, + chatId + }) + ); + }, 250); //wait for the panel to close before navigating + } }); const selectedLayout: ChatLayoutView = useMemo(() => {