22
33import { Navigation } from '@/components/layout/navigation' ;
44import { ChatInput } from '@/components/chat/chat-input' ;
5- import { ChatMessage } from '@/components/chat/chat-message' ;
5+ // import { ChatMessage } from '@/components/chat/chat-message';
66import { SuggestedPrompts } from '@/components/chat/suggested-prompts' ;
77import { Icons } from '@/components/icons' ;
8- import { useState } from 'react' ;
8+ import { useState , memo } from 'react' ;
99import { useStream } from '@/hooks/use-stream' ;
1010import { motion , AnimatePresence } from 'framer-motion' ;
11+ import { MessageWindow } from '@/components/messages/message-window' ;
1112
1213const suggestedPrompts = [
1314 "What's the meaning of life?" ,
1415 'How do you define love?' ,
1516 "What's the meaning of AI?" ,
1617] ;
17-
18+ const MemoizedMessageWindow = memo ( MessageWindow ) ;
1819export default function Home ( ) {
1920 const [ input , setInput ] = useState ( '' ) ;
20- const { messages, streamMessage, isLoading } = useStream ( ) ;
21+ const { messages, isLoading , streamMessage, cancelGeneration } = useStream ( ) ;
2122
2223 const handleSubmit = async ( ) => {
24+ setInput ( '' ) ;
2325 if ( ! input . trim ( ) ) return ;
2426 await streamMessage ( input . trim ( ) , {
2527 temperature : 0.7 ,
2628 topP : 0.9 ,
2729 frequencyPenalty : 0 ,
2830 presencePenalty : 0 ,
2931 } ) ;
30- setInput ( '' ) ;
3132 } ;
3233
3334 return (
@@ -37,21 +38,22 @@ export default function Home() {
3738 className = "flex-1 flex flex-col p-4 md:p-8 max-h-screen overflow-y-auto"
3839 style = { { scrollbarWidth : 'none' , msOverflowStyle : 'none' } }
3940 >
40- < div className = "w-full max-w-2xl mx-auto space-y-8" >
41+ < div className = "w-full max-w-4xl mx-auto space-y-8 h-full " >
4142 < AnimatePresence >
4243 { messages . length === 0 ? (
4344 < motion . div
4445 initial = { { opacity : 0 , y : 20 } }
4546 animate = { { opacity : 1 , y : 0 } }
4647 exit = { { opacity : 0 , y : - 20 } }
47- className = "flex flex-col items-center justify-center flex-1 min- h-[60vh ]"
48+ className = "flex flex-col items-center justify-center flex-1 md:h-full h-[calc(100vh-6rem) ]"
4849 >
4950 < Icons . logo className = "h-12 w-12 mb-8 dark:invert" />
5051 < ChatInput
5152 value = { input }
5253 onChange = { setInput }
5354 onSubmit = { handleSubmit }
5455 isLoading = { isLoading }
56+ cancelGeneration = { cancelGeneration }
5557 />
5658 < SuggestedPrompts
5759 prompts = { suggestedPrompts }
@@ -62,21 +64,27 @@ export default function Home() {
6264 < motion . div
6365 initial = { { opacity : 0 } }
6466 animate = { { opacity : 1 } }
65- className = "space-y-4"
67+ className = "space-y-4 w-full "
6668 >
67- { messages . map ( ( message , index ) => (
69+ { /* { messages.map((message, index) => (
6870 <ChatMessage
6971 key={message.timestamp}
7072 message={message}
7173 isStreaming={isLoading && index === messages.length - 1}
7274 />
73- ) ) }
75+ ))} */ }
76+
77+ < MemoizedMessageWindow
78+ messages = { messages }
79+ isLoading = { isLoading }
80+ />
7481 < div className = "sticky bottom-[-15] p-4 bg-background" >
7582 < ChatInput
7683 value = { input }
7784 onChange = { setInput }
7885 onSubmit = { handleSubmit }
7986 isLoading = { isLoading }
87+ cancelGeneration = { cancelGeneration }
8088 />
8189 < div className = "text-xs text-zinc-400 text-center mt-2" >
8290 { ' ' }
0 commit comments