1
1
import RestartAltIcon from '@mui/icons-material/RestartAlt'
2
2
import HelpIcon from '@mui/icons-material/Help'
3
- import { Alert , Box , Drawer , FormControlLabel , Paper , Switch , Typography , useMediaQuery , useTheme } from '@mui/material'
4
- import { useContext , useEffect , useRef , useState } from 'react'
3
+ import { Alert , Box , Drawer , Fab , FormControlLabel , Paper , Switch , Typography , useMediaQuery , useTheme } from '@mui/material'
4
+ import React , { useContext , useEffect , useRef , useState } from 'react'
5
5
import { useTranslation } from 'react-i18next'
6
6
import { useParams , useSearchParams } from 'react-router-dom'
7
7
import { DEFAULT_ASSISTANT_INSTRUCTIONS , DEFAULT_MODEL , DEFAULT_MODEL_TEMPERATURE , FREE_MODEL , inProduction , validModels } from '../../../config'
@@ -31,7 +31,7 @@ import { useIsEmbedded } from '../../contexts/EmbeddedContext'
31
31
import { enqueueSnackbar } from 'notistack'
32
32
import { useAnalyticsDispatch } from '../../stores/analytics'
33
33
import EmailButton from './EmailButton'
34
- import { MenuBookTwoTone , Tune } from '@mui/icons-material'
34
+ import { ArrowDownward , MenuBookTwoTone , Tune } from '@mui/icons-material'
35
35
import { useChatScroll } from '../../hooks/useChatScroll'
36
36
import { TestUseInfoV2 } from './TestUseInfo'
37
37
import Footer from '../Footer'
@@ -115,16 +115,14 @@ export const ChatV2 = () => {
115
115
} , [ messages , courseId , ragIndexId , activeModel , dispatchAnalytics ] )
116
116
117
117
// Refs
118
- const appContainerRef = useContext ( AppContext )
119
118
const chatContainerRef = useRef < HTMLDivElement | null > ( null )
120
119
const conversationRef = useRef < HTMLElement | null > ( null )
121
120
const inputFieldRef = useRef < HTMLElement | null > ( null )
122
121
const fileInputRef = useRef < HTMLInputElement | null > ( null )
123
- const endOfConversationRef = useRef < HTMLDivElement | null > ( null )
124
122
const scrollRef = useRef < HTMLDivElement | null > ( null )
125
123
const [ setRetryTimeout , clearRetryTimeout ] = useRetryTimeout ( )
126
124
127
- const chatScroll = useChatScroll ( scrollRef , endOfConversationRef ) //removing this will break chat autoscroll behavior
125
+ const chatScroll = useChatScroll ( )
128
126
129
127
const { t, i18n } = useTranslation ( )
130
128
@@ -160,7 +158,6 @@ export const ChatV2 = () => {
160
158
161
159
const handleSubmit = async ( message : string , ignoreTokenUsageWarning : boolean ) => {
162
160
if ( ! userStatus ) return
163
- // chatScroll.autoScroll()
164
161
const { usage, limit } = userStatus
165
162
const tokenUsageExceeded = usage >= limit
166
163
@@ -196,6 +193,7 @@ export const ChatV2 = () => {
196
193
} , 5000 )
197
194
198
195
setIsStreaming ( true )
196
+ chatScroll . beginAutoscroll ( )
199
197
200
198
try {
201
199
const { tokenUsageAnalysis, stream } = await getCompletionStream ( {
@@ -354,8 +352,8 @@ export const ChatV2 = () => {
354
352
} }
355
353
>
356
354
{ /* Chat side panel column -------------------------------------------------------------------------------------------*/ }
357
- { ! isEmbeddedMode && (
358
- < >
355
+ { ! isEmbeddedMode &&
356
+ ( isMobile ? (
359
357
< Drawer
360
358
open = { chatLeftSidePanelOpen }
361
359
onClose = { ( ) => {
@@ -377,22 +375,25 @@ export const ChatV2 = () => {
377
375
messages = { messages }
378
376
/>
379
377
</ Drawer >
380
- < LeftMenu
381
- sx = { { display : { xs : 'none' , lg : 'flex' } , position : 'sticky' , top : 0 } }
382
- course = { course }
383
- handleReset = { handleReset }
384
- user = { user }
385
- t = { t }
386
- setSettingsModalOpen = { setSettingsModalOpen }
387
- setDisclaimerStatus = { setDisclaimerStatus }
388
- showRagSelector = { showRagSelector }
389
- ragIndex = { ragIndex }
390
- setRagIndexId = { setRagIndexId }
391
- ragIndices = { ragIndices }
392
- messages = { messages }
393
- />
394
- </ >
395
- ) }
378
+ ) : (
379
+ < >
380
+ < LeftMenu
381
+ sx = { { display : { xs : 'none' , lg : 'flex' } , position : 'fixed' , top : 0 } }
382
+ course = { course }
383
+ handleReset = { handleReset }
384
+ user = { user }
385
+ t = { t }
386
+ setSettingsModalOpen = { setSettingsModalOpen }
387
+ setDisclaimerStatus = { setDisclaimerStatus }
388
+ showRagSelector = { showRagSelector }
389
+ ragIndex = { ragIndex }
390
+ setRagIndexId = { setRagIndexId }
391
+ ragIndices = { ragIndices }
392
+ messages = { messages }
393
+ />
394
+ < Box width = { 400 } /> { /* Holds space for left menu */ }
395
+ </ >
396
+ ) ) }
396
397
397
398
{ /* Chat view column ------------------------------------------------------------------------------------------------ */ }
398
399
< Box
@@ -463,7 +464,6 @@ export const ChatV2 = () => {
463
464
isFileSearching = { isFileSearching }
464
465
setActiveFileSearchResult = { setActiveFileSearchResult }
465
466
setShowAnnotations = { setShowAnnotations }
466
- endOfConversationRef = { endOfConversationRef }
467
467
/>
468
468
</ Box >
469
469
@@ -510,16 +510,19 @@ export const ChatV2 = () => {
510
510
handleCancel = { handleCancel }
511
511
handleContinue = { ( newMessage ) => handleSubmit ( newMessage , true ) }
512
512
handleSubmit = { ( newMessage ) => {
513
- console . log ( 'handle submit called!' )
514
- chatScroll . shouldScroll . current = true
515
- chatScroll . autoScroll ( )
516
513
handleSubmit ( newMessage , false )
517
514
} }
518
515
handleReset = { handleReset }
519
516
/>
520
517
</ Box >
521
518
</ Box >
522
519
520
+ { ! chatScroll . isAutoScrolling && (
521
+ < Fab sx = { { position : 'fixed' , right : 32 , bottom : '12rem' } } onClick = { ( ) => chatScroll . beginAutoscroll ( ) } >
522
+ < ArrowDownward />
523
+ </ Fab >
524
+ ) }
525
+
523
526
{ /* Annotations columns ----------------------------------------------------------------------------------------------------- */ }
524
527
525
528
{ isMobile && (
@@ -612,7 +615,6 @@ const LeftMenu = ({
612
615
height : '100vh' ,
613
616
borderRight : '1px solid rgba(0, 0, 0, 0.12)' ,
614
617
paddingTop : '4rem' ,
615
-
616
618
display : 'flex' ,
617
619
flexDirection : 'column' ,
618
620
} ,
0 commit comments