@@ -4,7 +4,6 @@ import type {
44 CreateMessage ,
55 Message ,
66} from 'ai' ;
7- import cx from 'classnames' ;
87import { formatDistance } from 'date-fns' ;
98import { AnimatePresence , motion } from 'framer-motion' ;
109import {
@@ -15,31 +14,22 @@ import {
1514 useEffect ,
1615 useState ,
1716} from 'react' ;
18- import { toast } from 'sonner' ;
1917import useSWR , { useSWRConfig } from 'swr' ;
20- import {
21- useCopyToClipboard ,
22- useDebounceCallback ,
23- useWindowSize ,
24- } from 'usehooks-ts' ;
18+ import { useDebounceCallback , useWindowSize } from 'usehooks-ts' ;
2519
2620import type { Document , Suggestion , Vote } from '@/lib/db/schema' ;
2721import { fetcher } from '@/lib/utils' ;
2822
2923import { DiffView } from './diffview' ;
3024import { DocumentSkeleton } from './document-skeleton' ;
3125import { Editor } from './editor' ;
32- import { CopyIcon , CrossIcon , DeltaIcon , RedoIcon , UndoIcon } from './icons' ;
33- import { PreviewMessage } from './message' ;
3426import { MultimodalInput } from './multimodal-input' ;
3527import { Toolbar } from './toolbar' ;
36- import { Button } from './ui/button' ;
37- import { Tooltip , TooltipContent , TooltipTrigger } from './ui/tooltip' ;
38- import { useScrollToBottom } from './use-scroll-to-bottom' ;
3928import { VersionFooter } from './version-footer' ;
40- import { Markdown } from './markdown' ;
4129import { BlockActions } from './block-actions' ;
4230import { BlockCloseButton } from './block-close-button' ;
31+ import { BlockMessages } from './block-messages' ;
32+
4333export interface UIBlock {
4434 title : string ;
4535 documentId : string ;
@@ -54,7 +44,7 @@ export interface UIBlock {
5444 } ;
5545}
5646
57- export function PureBlock ( {
47+ function PureBlock ( {
5848 chatId,
5949 input,
6050 setInput,
@@ -93,9 +83,6 @@ export function PureBlock({
9383 chatRequestOptions ?: ChatRequestOptions ,
9484 ) => void ;
9585} ) {
96- const [ messagesContainerRef , messagesEndRef ] =
97- useScrollToBottom < HTMLDivElement > ( ) ;
98-
9986 const {
10087 data : documents ,
10188 isLoading : isDocumentsFetching ,
@@ -292,31 +279,14 @@ export function PureBlock({
292279 </ AnimatePresence >
293280
294281 < div className = "flex flex-col h-full justify-between items-center gap-4" >
295- < div
296- ref = { messagesContainerRef }
297- className = "flex flex-col gap-4 h-full items-center overflow-y-scroll px-4 pt-20"
298- >
299- { messages . map ( ( message , index ) => (
300- < PreviewMessage
301- chatId = { chatId }
302- key = { message . id }
303- message = { message }
304- block = { block }
305- setBlock = { setBlock }
306- isLoading = { isLoading && index === messages . length - 1 }
307- vote = {
308- votes
309- ? votes . find ( ( vote ) => vote . messageId === message . id )
310- : undefined
311- }
312- />
313- ) ) }
314-
315- < div
316- ref = { messagesEndRef }
317- className = "shrink-0 min-w-[24px] min-h-[24px]"
318- />
319- </ div >
282+ < BlockMessages
283+ chatId = { chatId }
284+ block = { block }
285+ isLoading = { isLoading }
286+ setBlock = { setBlock }
287+ votes = { votes }
288+ messages = { messages }
289+ />
320290
321291 < form className = "flex flex-row gap-2 relative items-end w-full px-4 pb-4" >
322292 < MultimodalInput
0 commit comments