@@ -20,6 +20,7 @@ import { AppContext } from '../../util/context'
20
20
import { Close , Settings } from '@mui/icons-material'
21
21
import { SettingsModal } from './SettingsModal'
22
22
import { Link } from 'react-router-dom'
23
+ import { useScrollToBottom } from './useScrollToBottom'
23
24
24
25
export const ChatV2 = ( ) => {
25
26
const { courseId } = useParams ( )
@@ -36,11 +37,11 @@ export const ChatV2 = () => {
36
37
const [ prevResponse , setPrevResponse ] = useLocalStorageState < {
37
38
id : string
38
39
} > ( 'general-prev-response' , { id : '' } )
39
-
40
+
40
41
const appContainerRef = useContext ( AppContext )
41
42
const chatContainerRef = useRef < HTMLDivElement > ( null )
42
43
const inputFileRef = useRef < HTMLInputElement > ( null )
43
-
44
+
44
45
const [ settingsModalOpen , setSettingsModalOpen ] = useState ( false )
45
46
const [ activePromptId , setActivePromptId ] = useState ( '' )
46
47
const [ fileName , setFileName ] = useState < string > ( '' )
@@ -52,7 +53,7 @@ export const ChatV2 = () => {
52
53
const [ tokenWarningVisible , setTokenWarningVisible ] = useState ( false )
53
54
const [ modelTemperature , setModelTemperature ] = useState ( 0.5 )
54
55
const [ saveConsent , setSaveConsent ] = useState ( true )
55
-
56
+
56
57
const [ setRetryTimeout , clearRetryTimeout ] = useRetryTimeout ( )
57
58
58
59
const { t, i18n } = useTranslation ( )
@@ -169,27 +170,7 @@ export const ChatV2 = () => {
169
170
clearRetryTimeout ( )
170
171
}
171
172
172
- useEffect ( ( ) => {
173
- const chatContainer = chatContainerRef . current
174
- const appContainer = appContainerRef . current
175
-
176
- if ( ! chatContainer || ! appContainer || ! messages . length ) return
177
-
178
- const scrollToBottom = ( ) => {
179
- appContainer . scrollIntoView ( {
180
- behavior : 'smooth' ,
181
- block : 'end' ,
182
- } )
183
- }
184
-
185
- const resizeObserver = new ResizeObserver ( ( ) => {
186
- scrollToBottom ( )
187
- } )
188
-
189
- resizeObserver . observe ( chatContainer )
190
-
191
- return ( ) => resizeObserver . disconnect ( )
192
- } , [ ] )
173
+ useScrollToBottom ( chatContainerRef , appContainerRef , messages )
193
174
194
175
return (
195
176
< Box
@@ -199,20 +180,17 @@ export const ChatV2 = () => {
199
180
flexDirection : 'column' ,
200
181
} }
201
182
>
202
- < SettingsModal open = { settingsModalOpen } setOpen = { setSettingsModalOpen } > </ SettingsModal >
203
- < Box sx = { { display : 'flex' , justifyContent : 'space-between' , alignItems : 'center' } } >
204
-
205
- < Box sx = { { display : 'flex' , gap : '1rem' } } >
206
- { disclaimerInfo && < Disclaimer disclaimer = { disclaimerInfo } /> }
207
- < SystemPrompt content = { system . content } setContent = { ( content ) => setSystem ( { content } ) } />
208
- < Button onClick = { handleReset } > Reset</ Button >
209
- < IconButton onClick = { ( ) => setSettingsModalOpen ( true ) } title = "Settings" >
210
- < Settings > </ Settings >
211
- </ IconButton >
212
- </ Box >
213
- {
214
- courseId ? < Link to = { '/v2' } > CurreChat</ Link > : < Link to = { '/v2/sandbox' } > Ohtu Sandbox</ Link >
215
- }
183
+ < SettingsModal open = { settingsModalOpen } setOpen = { setSettingsModalOpen } model = { model . name } setModel = { ( name ) => setModel ( { name } ) } > </ SettingsModal >
184
+ < Box sx = { { display : 'flex' , justifyContent : 'space-between' , alignItems : 'center' } } >
185
+ < Box sx = { { display : 'flex' , gap : '1rem' } } >
186
+ { disclaimerInfo && < Disclaimer disclaimer = { disclaimerInfo } /> }
187
+ < SystemPrompt content = { system . content } setContent = { ( content ) => setSystem ( { content } ) } />
188
+ < Button onClick = { handleReset } > Reset</ Button >
189
+ < IconButton onClick = { ( ) => setSettingsModalOpen ( true ) } title = "Settings" >
190
+ < Settings > </ Settings >
191
+ </ IconButton >
192
+ </ Box >
193
+ { courseId ? < Link to = { '/v2' } > CurreChat</ Link > : < Link to = { '/v2/sandbox' } > Ohtu Sandbox</ Link > }
216
194
</ Box >
217
195
< Box ref = { chatContainerRef } >
218
196
< Conversation messages = { messages } completion = { completion } />
0 commit comments