1
- import React , { Component } from " react" ;
2
- import fileSaver from " file-saver" ;
3
- import LoadingIcon from " ../shared-components/LoadingIcon.jsx" ;
4
- import Alert from " ../shared-components/Alert.jsx" ;
5
- import Header from " ../shared-components/Header.jsx" ;
6
- import runFetch from " ./runFetch.js" ;
1
+ import React , { Component } from ' react'
2
+ import fileSaver from ' file-saver'
3
+ import LoadingIcon from ' ../shared-components/LoadingIcon.jsx'
4
+ import Alert from ' ../shared-components/Alert.jsx'
5
+ import Header from ' ../shared-components/Header.jsx'
6
+ import runFetch from ' ./runFetch.js'
7
7
8
- import " ./CSVUpload.css" ;
8
+ import ' ./CSVUpload.css'
9
9
10
10
const defaultState = {
11
11
isFetching : false ,
12
- filename : "" ,
12
+ filename : '' ,
13
13
error : false
14
- } ;
14
+ }
15
15
16
16
class CSVUpload extends Component {
17
17
constructor ( props ) {
18
- super ( props ) ;
19
- this . state = defaultState ;
20
- this . handleCSVSelect = this . handleCSVSelect . bind ( this ) ;
18
+ super ( props )
19
+ this . state = defaultState
20
+ this . handleCSVSelect = this . handleCSVSelect . bind ( this )
21
21
22
- this . refScrollTo = React . createRef ( ) ;
22
+ this . refScrollTo = React . createRef ( )
23
23
}
24
24
25
25
componentDidUpdate ( prevProps , prevState ) {
26
26
if ( this . state . isFetching ) {
27
27
window . scrollTo ( {
28
28
top : this . refScrollTo . current . offsetTop ,
29
- behavior : " smooth"
30
- } ) ;
29
+ behavior : ' smooth'
30
+ } )
31
31
}
32
32
}
33
33
34
34
onCSVFetch ( ) {
35
- this . setState ( { isFetching : true , error : false } ) ;
35
+ this . setState ( { isFetching : true , error : false } )
36
36
}
37
37
38
38
onCSVCalculated ( response , file ) {
39
39
if ( response . status ) {
40
40
return this . setState ( {
41
41
isFetching : false ,
42
42
error : true
43
- } ) ;
43
+ } )
44
44
}
45
45
46
- const filename = " calculated-" + file . name ;
46
+ const filename = ' calculated-' + file . name
47
47
48
48
this . setState ( {
49
49
isFetching : false ,
50
50
filename : filename
51
- } ) ;
51
+ } )
52
52
53
53
return fileSaver . saveAs (
54
- new Blob ( [ response ] , { type : " text/csv;charset=utf-16" } ) ,
54
+ new Blob ( [ response ] , { type : ' text/csv;charset=utf-16' } ) ,
55
55
filename
56
- ) ;
56
+ )
57
57
}
58
58
59
59
handleCSVSelect ( event ) {
60
- event . preventDefault ( ) ;
61
- const file = event . target . files [ 0 ] ;
62
- if ( ! file ) return ;
60
+ event . preventDefault ( )
61
+ const file = event . target . files [ 0 ]
62
+ if ( ! file ) return
63
63
64
- event . target . value = null ;
64
+ event . target . value = null
65
65
66
- this . onCSVFetch ( ) ;
67
- const CSV_URL = " https://ffiec-api.cfpb.gov/public/rateSpread/csv" ;
66
+ this . onCSVFetch ( )
67
+ const CSV_URL = ' https://ffiec-api.cfpb.gov/public/rateSpread/csv'
68
68
runFetch ( CSV_URL , this . prepareCSVBody ( file ) , true ) . then ( res => {
69
- this . onCSVCalculated ( res , file ) ;
70
- } ) ;
69
+ this . onCSVCalculated ( res , file )
70
+ } )
71
71
}
72
72
73
73
prepareCSVBody ( file ) {
74
- const data = new FormData ( ) ;
75
- data . append ( " file" , file ) ;
76
- return data ;
74
+ const data = new FormData ( )
75
+ data . append ( ' file' , file )
76
+ return data
77
77
}
78
78
79
79
render ( ) {
@@ -97,10 +97,10 @@ class CSVUpload extends Component {
97
97
</ label >
98
98
</ p >
99
99
< p className = "text-small" >
100
- Please see{ " " }
100
+ Please see{ ' ' }
101
101
< a href = "http://cfpb.github.io/hmda-platform/rate-spread/#batch" >
102
102
the batch section of the API documentation
103
- </ a > { " " }
103
+ </ a > { ' ' }
104
104
for information on csv formatting.
105
105
</ p >
106
106
</ div >
@@ -114,7 +114,7 @@ class CSVUpload extends Component {
114
114
>
115
115
< p >
116
116
Please check your file format and try again later. If the
117
- problem persists, contact{ " " }
117
+ problem persists, contact{ ' ' }
118
118
< a href = "mailto:[email protected] " > HMDA Help
</ a > .
119
119
</ p >
120
120
</ Alert >
@@ -131,8 +131,8 @@ class CSVUpload extends Component {
131
131
) : null }
132
132
</ div >
133
133
</ div >
134
- ) ;
134
+ )
135
135
}
136
136
}
137
137
138
- export default CSVUpload ;
138
+ export default CSVUpload
0 commit comments