Skip to content

Commit af17278

Browse files
committed
Refactor Chat component to set saved messages on mount
1 parent 8198335 commit af17278

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

components/chat.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { CHAT_ID } from '@/lib/constants'
44
import { Message, useChat } from 'ai/react'
5+
import { useEffect } from 'react'
56
import { toast } from 'sonner'
67
import { ChatMessages } from './chat-messages'
78
import { ChatPanel } from './chat-panel'
@@ -38,6 +39,10 @@ export function Chat({
3839
}
3940
})
4041

42+
useEffect(() => {
43+
setMessages(savedMessages)
44+
}, [id])
45+
4146
const onQuerySelect = (query: string) => {
4247
append({
4348
role: 'user',
@@ -46,7 +51,7 @@ export function Chat({
4651
}
4752

4853
return (
49-
<div className="flex flex-col w-full max-w-3xl pt-10 pb-16 mx-auto stretch">
54+
<div className="flex flex-col w-full max-w-3xl pt-10 pb-20 mx-auto stretch">
5055
<ChatMessages
5156
messages={messages}
5257
onQuerySelect={onQuerySelect}

0 commit comments

Comments
 (0)