1
- import React , { memo , useCallback , useEffect } from 'react' ;
1
+ import React , { memo , useCallback , useEffect , useRef } from 'react' ;
2
2
import { useSelector , useDispatch } from 'react-redux' ;
3
3
import Modal from '../common/Modal' ;
4
4
import { Grid , makeStyles , IconButton , Tooltip } from '@material-ui/core' ;
@@ -33,6 +33,7 @@ const useStyles = makeStyles(theme => ({
33
33
export const TrackingModal = memo ( ( { openModal, onModalClose } ) => {
34
34
const classes = useStyles ( ) ;
35
35
const dispatch = useDispatch ( ) ;
36
+ const bottomRef = useRef ( ) ;
36
37
37
38
const actionList = useSelector ( state => state . trackingReducers . project_actions_list ) ;
38
39
const orderedActionList = ( actionList && actionList . sort ( ( a , b ) => a . timestamp - b . timestamp ) ) || [ ] ;
@@ -43,6 +44,16 @@ export const TrackingModal = memo(({ openModal, onModalClose }) => {
43
44
}
44
45
} , [ dispatch , openModal ] ) ;
45
46
47
+ const scrollToBottom = ( ) => {
48
+ if ( bottomRef . current != null ) {
49
+ bottomRef . current . scrollIntoView ( {
50
+ behavior : 'auto' ,
51
+ block : 'nearest' ,
52
+ inline : 'nearest'
53
+ } ) ;
54
+ }
55
+ } ;
56
+
46
57
useEffect ( ( ) => {
47
58
loadAllActions ( ) ;
48
59
} , [ loadAllActions ] ) ;
@@ -79,6 +90,12 @@ export const TrackingModal = memo(({ openModal, onModalClose }) => {
79
90
}
80
91
} ) }
81
92
</ Timeline >
93
+ < div
94
+ ref = { el => {
95
+ bottomRef . current = el ;
96
+ scrollToBottom ( ) ;
97
+ } }
98
+ > </ div >
82
99
</ div >
83
100
</ div >
84
101
</ Grid >
0 commit comments