1- import React from 'react'
2- import imageCompression from 'browser-image-compression'
1+ import React from 'react' ;
2+ import imageCompression from 'browser-image-compression' ;
33
44export default class App extends React . Component {
5- constructor ( ...args ) {
6- super ( ...args )
7- this . compressImage = this . compressImage . bind ( this )
8- this . handleChange = this . handleChange . bind ( this )
5+ constructor ( ...args ) {
6+ super ( ...args ) ;
7+ this . compressImage = this . compressImage . bind ( this ) ;
8+ this . handleChange = this . handleChange . bind ( this ) ;
99 this . state = {
1010 maxSizeMB : 1 ,
1111 maxWidthOrHeight : 1024 ,
@@ -14,72 +14,74 @@ export default class App extends React.Component {
1414 inputSize : null ,
1515 outputSize : null ,
1616 inputUrl : null ,
17- outputUrl : null
17+ outputUrl : null ,
1818 } ,
1919 mainThread : {
2020 progress : null ,
2121 inputSize : null ,
2222 outputSize : null ,
2323 inputUrl : null ,
24- outputUrl : null
25- }
26- }
24+ outputUrl : null ,
25+ } ,
26+ } ;
2727 }
2828
29- handleChange ( target ) {
29+ handleChange ( target ) {
3030 return ( e ) => {
31- this . setState ( { [ target ] : e . currentTarget . value } )
32- }
31+ this . setState ( { [ target ] : e . currentTarget . value } ) ;
32+ } ;
3333 }
3434
35- onProgress ( p , useWebWorker ) {
36- const targetName = useWebWorker ? 'webWorker' : 'mainThread'
37- this . setState ( prevState => ( {
35+ onProgress ( p , useWebWorker ) {
36+ const targetName = useWebWorker ? 'webWorker' : 'mainThread' ;
37+ this . setState ( ( prevState ) => ( {
3838 ...prevState ,
3939 [ targetName ] : {
4040 ...prevState [ targetName ] ,
41- progress : p
42- }
43- } ) )
41+ progress : p ,
42+ } ,
43+ } ) ) ;
4444 }
4545
46- async compressImage ( event , useWebWorker ) {
47- const file = event . target . files [ 0 ]
48- console . log ( 'input' , file )
46+ async compressImage ( event , useWebWorker ) {
47+ const file = event . target . files [ 0 ] ;
48+ console . log ( 'input' , file ) ;
4949 console . log (
5050 'ExifOrientation' ,
51- await imageCompression . getExifOrientation ( file )
52- )
53- const targetName = useWebWorker ? 'webWorker' : 'mainThread'
54- this . setState ( prevState => ( {
51+ await imageCompression . getExifOrientation ( file ) ,
52+ ) ;
53+ const targetName = useWebWorker ? 'webWorker' : 'mainThread' ;
54+ this . setState ( ( prevState ) => ( {
5555 ...prevState ,
5656 [ targetName ] : {
5757 ...prevState [ targetName ] ,
5858 inputSize : ( file . size / 1024 / 1024 ) . toFixed ( 2 ) ,
59- inputUrl : URL . createObjectURL ( file )
60- }
61- } ) )
62- var options = {
59+ inputUrl : URL . createObjectURL ( file ) ,
60+ } ,
61+ } ) ) ;
62+ const options = {
6363 maxSizeMB : this . state . maxSizeMB ,
6464 maxWidthOrHeight : this . state . maxWidthOrHeight ,
6565 useWebWorker,
66- onProgress : p => this . onProgress ( p , useWebWorker )
67- }
68- const output = await imageCompression ( file , options )
69- console . log ( 'output' , output )
70- this . setState ( prevState => ( {
66+ onProgress : ( p ) => this . onProgress ( p , useWebWorker ) ,
67+ } ;
68+ const output = await imageCompression ( file , options ) ;
69+ console . log ( 'output' , output ) ;
70+ this . setState ( ( prevState ) => ( {
7171 ...prevState ,
7272 [ targetName ] : {
7373 ...prevState [ targetName ] ,
7474 outputSize : ( output . size / 1024 / 1024 ) . toFixed ( 2 ) ,
75- outputUrl : URL . createObjectURL ( output )
76- }
77- } ) )
75+ outputUrl : URL . createObjectURL ( output ) ,
76+ } ,
77+ } ) ) ;
7878 }
7979
80- render ( ) {
81- const version = imageCompression . version
82- const { webWorker, mainThread, maxSizeMB, maxWidthOrHeight } = this . state
80+ render ( ) {
81+ const { version } = imageCompression ;
82+ const {
83+ webWorker, mainThread, maxSizeMB, maxWidthOrHeight,
84+ } = this . state ;
8385 return (
8486 < div className = "App" >
8587 < div >
@@ -100,7 +102,7 @@ export default class App extends React.Component {
100102 id = "web-worker"
101103 type = "file"
102104 accept = "image/*"
103- onChange = { e => this . compressImage ( e , true ) }
105+ onChange = { ( e ) => this . compressImage ( e , true ) }
104106 />
105107 </ label >
106108 < p >
@@ -120,7 +122,7 @@ export default class App extends React.Component {
120122 id = "main-thread"
121123 type = "file"
122124 accept = "image/*"
123- onChange = { e => this . compressImage ( e , false ) }
125+ onChange = { ( e ) => this . compressImage ( e , false ) }
124126 />
125127 </ label >
126128 < p >
@@ -170,6 +172,6 @@ export default class App extends React.Component {
170172 }
171173 ` } </ style >
172174 </ div >
173- )
175+ ) ;
174176 }
175- } ;
177+ }
0 commit comments