33import { ChatMessage } from '@/components/routes/chat/chat-message'
44import { SharedAccordion } from '@/components/shared/shared-accordion'
55import { ShortMessage } from '@/components/shared/short-message'
6- import { useMBChat } from '@/lib/hooks/use-mb-chat'
76import { useScroll } from '@/lib/hooks/use-scroll'
87import { useThread } from '@/lib/hooks/use-thread'
98import { cn , createMessagePairs } from '@/lib/utils'
@@ -47,7 +46,8 @@ export function ChatList({
4746 const { isNewResponse, activeThread } = useThread ( )
4847 const localContainerRef = useRef < HTMLDivElement > ( null )
4948 const effectiveContainerRef = containerRef || localContainerRef
50- const chatMessages = ( messages || activeThread ?. messages || [ ] ) . sort ( ( a , b ) => a . createdAt - b . createdAt )
49+ const chatMessages = ( messages || activeThread ?. messages || [ ] )
50+ // .sort((a, b) => a.createdAt - b.createdAt)
5151
5252 useScroll ( {
5353 containerRef : effectiveContainerRef ,
@@ -118,7 +118,7 @@ function MessagePairs({
118118 < >
119119 { pairs . map ( ( pair : MessagePair , key : number ) => (
120120 < SharedAccordion
121- key = { `${ pair . userMessage . id } -${ pair . chatGptMessage [ 0 ] ?. id ?? 'pending' } ` }
121+ key = { `${ pair . userMessage . createdAt } -${ pair . chatGptMessage [ 0 ] ?. id ?? 'pending' } ` }
122122 defaultState = { key === 0 || ( key === pairs . length - 1 && isNewResponse ) }
123123 className = { cn ( { 'relative' : isThread } ) }
124124 triggerClass = { cn (
@@ -188,10 +188,17 @@ function MessagePairs({
188188}
189189
190190export function ChatLoadingState ( ) {
191- const { activeTool } = useThread ( )
192- const [ { isLoadingMessages } ] = useMBChat ( )
191+ const { activeTool, loadingState } = useThread ( )
193192
194- if ( ! isLoadingMessages && ! activeTool ?. toolName ) return null
193+ if ( ! loadingState || ! activeTool ?. toolName ) return null
194+
195+ if ( loadingState ?. match ( / ^ ( p r o c e s s i n g | d i g e s t i n g | p o l i s h i n g ) / ) ) {
196+ return (
197+ < div className = "flex items-center justify-center w-full h-20" >
198+ < div className = "w-8 h-8 border-4 border-t-4 border-gray-200 rounded-full animate-ping" />
199+ </ div >
200+ )
201+ }
195202
196203 switch ( activeTool ?. toolName ) {
197204 case 'webSearch' :
@@ -219,7 +226,9 @@ export function ChatLoadingState() {
219226 )
220227 default :
221228 return (
222- < div className = "transition-all size-6 border-2 border-t-[2px] rounded-full border-x-gray-300 animate-spin" />
229+ < div className = "flex items-center justify-center w-full h-20" >
230+ < div className = "w-8 h-8 border-4 border-t-4 border-gray-200 rounded-full animate-ping" />
231+ </ div >
223232 )
224233 }
225234}
0 commit comments