Update useLayoutConfig.ts

This commit is contained in:
Nate Kelley 2025-03-27 16:03:55 -06:00
parent df1a685dde
commit bd18614e77
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 20 additions and 1 deletions

View File

@ -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<Record<string, FileConfig>>({});
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(() => {