@@ -6,6 +6,7 @@ import Checkbox from '@material-ui/core/Checkbox';
66import FormControlLabel from '@material-ui/core/FormControlLabel' ;
77
88import * as innerClasses from './student.styles' ;
9+ import { useAutoScroll } from '../../common/hooks/use-Auto-Scroll' ;
910
1011interface Props {
1112 room : string ;
@@ -15,24 +16,17 @@ interface Props {
1516export const StudentComponent : React . FC < Props > = props => {
1617 const { room, log } = props ;
1718
18- const [ isAutoScrollEnabled , setAutoScrollEnabled ] = React . useState ( true ) ;
19-
20- const textAreaRef = React . useRef ( null ) ;
19+ const { isAutoScrollEnabled, setIsAutoScrollEnabled, textAreaRef, doAutoScroll} = useAutoScroll ( ) ;
2120
2221 React . useEffect ( ( ) => {
23- if ( isAutoScrollEnabled && textAreaRef . current ) {
24- textAreaRef . current . scrollTop = textAreaRef . current . scrollHeight ;
25- }
22+ doAutoScroll ( ) ;
2623 } , [ log ] ) ;
2724
2825 return (
26+
2927 < >
3028 < main className = { innerClasses . root } >
31- < Typography
32- className = { innerClasses . sessionName }
33- variant = "body1"
34- role = "heading"
35- >
29+ < Typography className = { innerClasses . sessionName } variant = "body1" role = "heading" >
3630 Session name: { room ?? '' }
3731 </ Typography >
3832 < label className = { innerClasses . label } htmlFor = "session" >
@@ -51,7 +45,7 @@ export const StudentComponent: React.FC<Props> = props => {
5145 control = {
5246 < Checkbox
5347 checked = { isAutoScrollEnabled }
54- onChange = { e => setAutoScrollEnabled ( e . target . checked ) }
48+ onChange = { e => setIsAutoScrollEnabled ( e . target . checked ) }
5549 color = "primary"
5650 />
5751 }
0 commit comments