@@ -4,14 +4,15 @@ import Dialog from '@material-ui/core/Dialog';
4
4
import DialogActions from '@material-ui/core/DialogActions' ;
5
5
import DialogContent from '@material-ui/core/DialogContent' ;
6
6
import DialogTitle from '@material-ui/core/DialogTitle' ;
7
+ import LinearProgress from '@material-ui/core/LinearProgress' ;
7
8
import { connect } from 'react-redux' ;
8
- import { setVisibleModalUploadFile , uploadFiles } from '../../../Actions/Actions.js' ;
9
+ import { resetFileUploader , uploadFiles , setFileUploadList } from '../../../Actions/Actions.js' ;
9
10
import FileUploader from '../../FileUploader/FileUploader.jsx' ;
10
11
11
12
class FormDialog extends Component {
12
13
13
14
render ( ) {
14
- const { handleClose, handleUpload, open, canUpload } = this . props ;
15
+ const { handleClose, handleReset , handleUpload, open, canUpload, fileUploadProgress , fileUploadList , handleSelectedFiles } = this . props ;
15
16
16
17
return (
17
18
< Dialog open = { open } onClose = { handleClose } aria-labelledby = "form-dialog-title" >
@@ -20,7 +21,8 @@ class FormDialog extends Component {
20
21
Upload files
21
22
</ DialogTitle >
22
23
< DialogContent >
23
- < FileUploader handleUpload = { handleUpload } />
24
+ < FileUploader handleUpload = { handleUpload } fileUploadList = { fileUploadList } handleSelectedFiles = { handleSelectedFiles } handleReset = { handleReset } />
25
+ < LinearProgress variant = "determinate" value = { fileUploadProgress } />
24
26
</ DialogContent >
25
27
< DialogActions >
26
28
< Button onClick = { handleClose } color = "primary" type = "button" >
@@ -37,21 +39,31 @@ class FormDialog extends Component {
37
39
}
38
40
39
41
const mapStateToProps = ( state ) => {
40
- // prevent moving to same folder
41
- const canMove = state . path . join ( '' ) !== state . pathSublist . join ( '' ) + ( state . selectedFolderSublist ? state . selectedFolderSublist . name : '' ) ;
42
-
43
42
return {
44
43
open : state . visibleModalUploadFile ,
45
- canUpload : true ,
44
+ canUpload : state . fileUploadList . length ,
45
+ fileUploadList : state . fileUploadList ,
46
+ fileUploadProgress : state . fileUploadProgress
46
47
} ;
47
48
} ;
48
49
49
50
const mapDispatchToProps = ( dispatch , ownProps ) => {
50
51
return {
51
52
handleClose : ( event ) => {
52
- dispatch ( setVisibleModalUploadFile ( false ) ) ;
53
+ dispatch ( resetFileUploader ( ) ) ;
54
+ } ,
55
+ handleUpload : ( event ) => {
56
+ event . preventDefault ( ) ;
57
+ const files = event . currentTarget . form . querySelector ( 'input[type=file]' ) . files ;
58
+ dispatch ( uploadFiles ( files ) ) ;
59
+ } ,
60
+ handleSelectedFiles : ( event ) => {
61
+ dispatch ( setFileUploadList (
62
+ [ ...event . target . files ] . map ( f => ( { name : f . name , size : f . size } ) )
63
+ ) ) ;
53
64
} ,
54
- handleUpload : ( event , selectedFiles ) => {
65
+ handleReset : ( event ) => {
66
+ dispatch ( setFileUploadList ( [ ] ) ) ;
55
67
}
56
68
} ;
57
69
} ;
0 commit comments