1- import React , { useCallback , useState , useEffect , useRef } from "react" ;
1+ import React , { useState , useEffect , useRef } from "react" ;
22import {
33 Button ,
44 CircularProgress ,
55 Dialog ,
66 DialogActions ,
77 DialogContent ,
8- DialogContentText ,
98 DialogTitle ,
109 makeStyles ,
11- FormControl ,
1210 FormControlLabel ,
1311 Checkbox ,
1412} from "@material-ui/core" ;
15- import { useDispatch } from "react-redux" ;
1613import TextField from "@material-ui/core/TextField" ;
1714import { useTranslation } from "react-i18next" ;
18- import { useInterval } from "ahooks" ;
15+ import { useInterval , usePrevious , useGetState } from "ahooks" ;
1916import { cancelDirectoryDownload } from "../../redux/explorer/action" ;
17+ import Auth from "../../middleware/Auth" ;
2018
2119const useStyles = makeStyles ( ( theme ) => ( {
2220 contentFix : {
@@ -39,13 +37,25 @@ export default function DirectoryDownloadDialog(props) {
3937 const classes = useStyles ( ) ;
4038
4139 const logRef = useRef ( ) ;
42- const autoScroll = useRef ( true ) ;
40+ const [ autoScroll , setAutoScroll ] = useState (
41+ Auth . GetPreferenceWithDefault ( "autoScroll" , true )
42+ ) ;
43+ const previousLog = usePrevious ( props . log , ( prev , next ) => true ) ;
44+ const [ timer , setTimer ] = useState ( - 1 ) ;
4345
4446 useInterval ( ( ) => {
45- if ( autoScroll . current && ! props . done && logRef . current ) {
47+ if ( autoScroll && logRef . current && previousLog !== props . log ) {
4648 logRef . current . scrollIntoView ( { behavior : "smooth" , block : "end" } ) ;
4749 }
48- } , 1000 ) ;
50+ } , timer ) ;
51+
52+ useEffect ( ( ) => {
53+ if ( props . done ) {
54+ setTimer ( - 1 ) ;
55+ } else if ( props . open ) {
56+ setTimer ( 1000 ) ;
57+ }
58+ } , [ props . done , props . open ] ) ;
4959
5060 return (
5161 < Dialog
@@ -65,24 +75,25 @@ export default function DirectoryDownloadDialog(props) {
6575 ref = { logRef }
6676 multiline
6777 fullWidth
68- autoFocus
6978 id = "standard-basic"
7079 />
7180 </ DialogContent >
7281 < DialogActions >
7382 < FormControlLabel
74- control = {
75- < Checkbox
76- checked = { autoScroll . current }
77- onChange = { ( ) =>
78- ( autoScroll . current = ! autoScroll . current )
79- }
80- />
83+ control = { < Checkbox /> }
84+ checked = { autoScroll }
85+ onChange = { ( ) =>
86+ setAutoScroll ( ( previous ) => {
87+ Auth . SetPreference ( " autoScroll" , ! previous ) ;
88+ return ! previous ;
89+ } )
8190 }
8291 label = { t ( "modals.directoryDownloadAutoscroll" ) }
8392 />
8493 < Button
85- onClick = { props . done ? props . onClose : cancelDirectoryDownload }
94+ onClick = {
95+ props . done ? props . onClose : cancelDirectoryDownload
96+ }
8697 >
8798 { t ( "cancel" , { ns : "common" } ) }
8899 </ Button >
0 commit comments