@@ -16,6 +16,10 @@ interface Props {
1616
1717const BinaryUploadFile = ( props : Props ) => {
1818 const [ binaryData , setBinaryData ] = useState < ArrayBuffer | null > ( null ) ;
19+ // isChosen checks if file has been chosen
20+ const [ isChosen , setIsChosen ] = useState < boolean > ( false ) ;
21+ // isUploaded checks if 'Upload File' button has been clicked
22+ const [ isUploaded , setIsUploaded ] = useState < boolean > ( false ) ;
1923
2024 const {
2125 newRequestBodySet,
@@ -27,6 +31,7 @@ const BinaryUploadFile = (props: Props) => {
2731 // handleFileChange reads file uploaded, converts to binary, and stores in state
2832 const handleFileChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
2933 const file = e . target . files ?. [ 0 ] ;
34+
3035 if ( file ) {
3136 const reader = new FileReader ( ) ;
3237 reader . onload = ( ) => {
@@ -41,20 +46,37 @@ const BinaryUploadFile = (props: Props) => {
4146
4247 const handleSubmit = ( e : React . FormEvent < HTMLFormElement > ) => {
4348 e . preventDefault ( ) ;
49+ // once 'Upload File' clicked setIsUploaded to true
50+ setIsUploaded ( true ) ;
51+ // only if file has been chosen and then 'Upload File' clicked
52+ // setIsChosen to true
53+ if ( binaryData ) setIsChosen ( true ) ;
4454 newRequestBodySet ( {
4555 ...newRequestBody ,
4656 bodyContent : binaryData ,
47- bodyType : 'binary' ,
48- rawType : '' ,
49- JSONFormatted : false
57+ bodyType : 'binary'
5058 } ) ;
5159 } ;
5260
5361 return (
54- < form style = { { marginTop :'4px' } } onSubmit = { handleSubmit } >
55- < input type = "file" style = { { display :'ruby' , padding :'4px' } } id = "chooseFileBinary" className = 'button is-small is-outlined is-primary mr-3' onChange = { handleFileChange } />
56- < input type = "submit" id = "uploadFileBinary" className = 'button is-small is-outlined is-primary' value = "Upload File" />
57- </ form >
62+ < div style = { { display :'flex' } } >
63+ < form style = { { marginTop :'7px' } } onSubmit = { handleSubmit } >
64+ < input type = "file" style = { { padding :'4px 5px 6px 5px' } } id = "chooseFileBinary" className = 'button is-small is-outlined is-primary mr-3' onChange = { handleFileChange } />
65+ < input type = "submit" id = "uploadFileBinary" className = 'button is-small is-outlined is-primary' value = "Upload File" />
66+ </ form >
67+ < div id = 'isUploaded' style = { { margin :'2px 0px 0px 15px' , padding :'9px 5px 9px 5px' } } >
68+ { isUploaded
69+ ?
70+ isChosen
71+ ?
72+ < h1 > File Uploaded ✅</ h1 >
73+ :
74+ < h1 > Must Choose File ⏸️</ h1 >
75+ :
76+ < h1 > File Not Uploaded ❌</ h1 >
77+ }
78+ </ div >
79+ </ div >
5880 ) ;
5981} ;
6082
0 commit comments