mirror of https://github.com/buster-so/buster.git
mounted update
This commit is contained in:
parent
00801b9ad5
commit
7d65915d80
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useMemoizedFn } from '@/hooks';
|
import { useMemoizedFn, useMount } from '@/hooks';
|
||||||
import React, {
|
import React, {
|
||||||
useEffect,
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
|
@ -251,6 +251,11 @@ export const AppSplitter = React.memo(
|
||||||
// Add useImperativeHandle to expose the function
|
// Add useImperativeHandle to expose the function
|
||||||
useImperativeHandle(ref, imperativeHandleMethods);
|
useImperativeHandle(ref, imperativeHandleMethods);
|
||||||
|
|
||||||
|
const isNested = useMemo(() => {
|
||||||
|
console.log('ref', ref);
|
||||||
|
return !!ref;
|
||||||
|
}, [ref]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('flex h-full w-full flex-col', className)} ref={containerRef}>
|
<div className={cn('flex h-full w-full flex-col', className)} ref={containerRef}>
|
||||||
<SplitPane
|
<SplitPane
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { useMemo, useRef } from 'react';
|
import React, { useMemo, useRef, useState } from 'react';
|
||||||
import { AppSplitter, AppSplitterRef } from '@/components/ui/layouts/AppSplitter';
|
import { AppSplitter, AppSplitterRef } from '@/components/ui/layouts/AppSplitter';
|
||||||
import { ChatContainer } from '../ChatContainer';
|
import { ChatContainer } from '../ChatContainer';
|
||||||
import { FileContainer } from '../FileContainer';
|
import { FileContainer } from '../FileContainer';
|
||||||
import { ChatLayoutContextProvider, useChatLayoutContext } from '../ChatLayoutContext';
|
import { ChatLayoutContextProvider, useChatLayoutContext } from '../ChatLayoutContext';
|
||||||
import { ChatContextProvider } from '../ChatContext/ChatContext';
|
import { ChatContextProvider } from '../ChatContext/ChatContext';
|
||||||
import { DEFAULT_CHAT_OPTION_SIDEBAR_SIZE } from '../ChatLayoutContext/config';
|
import { DEFAULT_CHAT_OPTION_SIDEBAR_SIZE } from '../ChatLayoutContext/config';
|
||||||
|
import { useMount } from '@/hooks';
|
||||||
|
|
||||||
interface ChatSplitterProps {
|
interface ChatSplitterProps {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
@ -14,6 +15,8 @@ interface ChatSplitterProps {
|
||||||
|
|
||||||
export const ChatLayout: React.FC<ChatSplitterProps> = ({ children }) => {
|
export const ChatLayout: React.FC<ChatSplitterProps> = ({ children }) => {
|
||||||
const appSplitterRef = useRef<AppSplitterRef>(null);
|
const appSplitterRef = useRef<AppSplitterRef>(null);
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
|
||||||
const chatLayoutProps = useChatLayoutContext({ appSplitterRef });
|
const chatLayoutProps = useChatLayoutContext({ appSplitterRef });
|
||||||
const { selectedLayout, selectedFile } = chatLayoutProps;
|
const { selectedLayout, selectedFile } = chatLayoutProps;
|
||||||
|
|
||||||
|
@ -23,22 +26,19 @@ export const ChatLayout: React.FC<ChatSplitterProps> = ({ children }) => {
|
||||||
return ['380px', 'auto'];
|
return ['380px', 'auto'];
|
||||||
}, [selectedLayout]);
|
}, [selectedLayout]);
|
||||||
|
|
||||||
|
useMount(() => {
|
||||||
|
setMounted(true); //we need to wait for the app splitter to be mounted because this is nested in the app splitter
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ChatLayoutContextProvider chatLayoutProps={chatLayoutProps}>
|
<ChatLayoutContextProvider chatLayoutProps={chatLayoutProps}>
|
||||||
<ChatContextProvider>
|
<ChatContextProvider>
|
||||||
<AppSplitter
|
<AppSplitter
|
||||||
ref={appSplitterRef}
|
ref={appSplitterRef}
|
||||||
leftChildren={useMemo(
|
leftChildren={useMemo(() => mounted && <ChatContainer />, [mounted])}
|
||||||
() => (
|
|
||||||
<ChatContainer />
|
|
||||||
),
|
|
||||||
[]
|
|
||||||
)}
|
|
||||||
rightChildren={useMemo(
|
rightChildren={useMemo(
|
||||||
() => (
|
() => mounted && <FileContainer>{children}</FileContainer>,
|
||||||
<FileContainer>{children}</FileContainer>
|
[children, mounted]
|
||||||
),
|
|
||||||
[children]
|
|
||||||
)}
|
)}
|
||||||
autoSaveId="chat-splitter"
|
autoSaveId="chat-splitter"
|
||||||
defaultLayout={defaultSplitterLayout}
|
defaultLayout={defaultSplitterLayout}
|
||||||
|
|
Loading…
Reference in New Issue