mirror of https://github.com/buster-so/buster.git
Additional render updates
This commit is contained in:
parent
165576b669
commit
8911e7954f
|
@ -7,6 +7,12 @@ export default function ChatLayout({ children }: { children: React.ReactNode })
|
||||||
export async function generateMetadata({ params }: { params: Promise<{ chatId: string }> }) {
|
export async function generateMetadata({ params }: { params: Promise<{ chatId: string }> }) {
|
||||||
const { chatId } = await params;
|
const { chatId } = await params;
|
||||||
|
|
||||||
|
if (!chatId) {
|
||||||
|
return {
|
||||||
|
title: 'Buster'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getTitle_server({
|
const response = await getTitle_server({
|
||||||
assetId: chatId,
|
assetId: chatId,
|
||||||
|
|
|
@ -22,10 +22,12 @@ export const AppPageLayout: React.FC<
|
||||||
headerClassName?: string;
|
headerClassName?: string;
|
||||||
mainClassName?: string;
|
mainClassName?: string;
|
||||||
contentContainerId?: string;
|
contentContainerId?: string;
|
||||||
|
id?: string;
|
||||||
}>
|
}>
|
||||||
> = ({
|
> = ({
|
||||||
children,
|
children,
|
||||||
header,
|
header,
|
||||||
|
id,
|
||||||
secondaryHeader,
|
secondaryHeader,
|
||||||
scrollable = false,
|
scrollable = false,
|
||||||
className = '',
|
className = '',
|
||||||
|
@ -37,6 +39,7 @@ export const AppPageLayout: React.FC<
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
id={id}
|
||||||
className={cn(
|
className={cn(
|
||||||
'app-page-layout flex h-full w-full flex-col overflow-hidden',
|
'app-page-layout flex h-full w-full flex-col overflow-hidden',
|
||||||
scrollable && 'overflow-y-auto',
|
scrollable && 'overflow-y-auto',
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { AppPageLayout } from '@/components/ui/layouts';
|
||||||
import { ChatContent } from './ChatContent';
|
import { ChatContent } from './ChatContent';
|
||||||
import { ChatHeader } from './ChatHeader';
|
import { ChatHeader } from './ChatHeader';
|
||||||
|
|
||||||
|
export const CHAT_CONTAINER_ID = 'chat-container-content';
|
||||||
|
|
||||||
export const ChatContainer = React.memo(() => {
|
export const ChatContainer = React.memo(() => {
|
||||||
return (
|
return (
|
||||||
<AppPageLayout
|
<AppPageLayout
|
||||||
|
@ -10,6 +12,7 @@ export const ChatContainer = React.memo(() => {
|
||||||
header={<ChatHeader />}
|
header={<ChatHeader />}
|
||||||
headerBorderVariant="ghost"
|
headerBorderVariant="ghost"
|
||||||
scrollable
|
scrollable
|
||||||
|
id={CHAT_CONTAINER_ID}
|
||||||
className="chat-container-content flex h-full w-full min-w-[295px] flex-col">
|
className="chat-container-content flex h-full w-full min-w-[295px] flex-col">
|
||||||
<ChatContent />
|
<ChatContent />
|
||||||
</AppPageLayout>
|
</AppPageLayout>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { useChatIndividualContextSelector } from '../../ChatContext';
|
||||||
import { ChatInput } from './ChatInput';
|
import { ChatInput } from './ChatInput';
|
||||||
import { ChatMessageBlock } from './ChatMessageBlock';
|
import { ChatMessageBlock } from './ChatMessageBlock';
|
||||||
import { ChatScrollToBottom } from './ChatScrollToBottom';
|
import { ChatScrollToBottom } from './ChatScrollToBottom';
|
||||||
|
import { CHAT_CONTAINER_ID } from '../ChatContainer';
|
||||||
|
|
||||||
const autoClass = 'mx-auto max-w-[600px] w-full';
|
const autoClass = 'mx-auto max-w-[600px] w-full';
|
||||||
|
|
||||||
|
@ -22,14 +23,16 @@ export const ChatContent: React.FC = React.memo(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
useMount(() => {
|
useMount(() => {
|
||||||
const container = document.querySelector(
|
const container = document
|
||||||
'.chat-container-content .scroll-area-viewport'
|
.getElementById(CHAT_CONTAINER_ID)
|
||||||
) as HTMLElement;
|
?.querySelector('.scroll-area-viewport') as HTMLElement;
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
containerRef.current = container;
|
containerRef.current = container;
|
||||||
enableAutoScroll();
|
enableAutoScroll();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('hit chat content');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="mb-48 flex h-full w-full flex-col">
|
<div className="mb-48 flex h-full w-full flex-col">
|
||||||
|
|
|
@ -4,6 +4,12 @@ import React from 'react';
|
||||||
import { useGetChatMessage } from '@/api/buster_rest/chats';
|
import { useGetChatMessage } from '@/api/buster_rest/chats';
|
||||||
import { ChatResponseMessages } from './ChatResponseMessages';
|
import { ChatResponseMessages } from './ChatResponseMessages';
|
||||||
import { ChatUserMessage } from './ChatUserMessage';
|
import { ChatUserMessage } from './ChatUserMessage';
|
||||||
|
import type { BusterChatMessage } from '@/api/asset_interfaces/chat';
|
||||||
|
|
||||||
|
// Stable selector functions to prevent unnecessary re-renders
|
||||||
|
const selectMessageExists = (message: BusterChatMessage | undefined) => !!message?.id;
|
||||||
|
const selectRequestMessage = (message: BusterChatMessage | undefined) => message?.request_message;
|
||||||
|
const selectIsCompleted = (message: BusterChatMessage | undefined) => message?.is_completed;
|
||||||
|
|
||||||
export const ChatMessageBlock: React.FC<{
|
export const ChatMessageBlock: React.FC<{
|
||||||
messageId: string;
|
messageId: string;
|
||||||
|
@ -11,15 +17,17 @@ export const ChatMessageBlock: React.FC<{
|
||||||
messageIndex: number;
|
messageIndex: number;
|
||||||
}> = React.memo(({ messageId, chatId, messageIndex }) => {
|
}> = React.memo(({ messageId, chatId, messageIndex }) => {
|
||||||
const { data: messageExists } = useGetChatMessage(messageId, {
|
const { data: messageExists } = useGetChatMessage(messageId, {
|
||||||
select: (message) => !!message?.id
|
select: selectMessageExists
|
||||||
});
|
});
|
||||||
const { data: requestMessage } = useGetChatMessage(messageId, {
|
const { data: requestMessage } = useGetChatMessage(messageId, {
|
||||||
select: (message) => message?.request_message
|
select: selectRequestMessage
|
||||||
});
|
});
|
||||||
const { data: isStreamFinished = true } = useGetChatMessage(messageId, {
|
const { data: isStreamFinished = true } = useGetChatMessage(messageId, {
|
||||||
select: (x) => x?.is_completed
|
select: selectIsCompleted
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('chat message block', messageId, messageIndex);
|
||||||
|
|
||||||
if (!messageExists) return null;
|
if (!messageExists) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -51,11 +51,8 @@ export const ChatLayout: React.FC<ChatSplitterProps> = ({ children }) => {
|
||||||
<ChatContextProvider>
|
<ChatContextProvider>
|
||||||
<AppSplitter
|
<AppSplitter
|
||||||
ref={appSplitterRef}
|
ref={appSplitterRef}
|
||||||
leftChildren={useMemo(() => mounted && <ChatContainer />, [mounted])}
|
leftChildren={mounted && <ChatContainer />}
|
||||||
rightChildren={useMemo(
|
rightChildren={mounted && <FileContainer>{children}</FileContainer>}
|
||||||
() => mounted && <FileContainer>{children}</FileContainer>,
|
|
||||||
[children, mounted]
|
|
||||||
)}
|
|
||||||
autoSaveId={autoSaveId}
|
autoSaveId={autoSaveId}
|
||||||
defaultLayout={defaultSplitterLayout}
|
defaultLayout={defaultSplitterLayout}
|
||||||
allowResize={selectedLayout === 'both'}
|
allowResize={selectedLayout === 'both'}
|
||||||
|
|
Loading…
Reference in New Issue