1- import React , { useEffect , useState } from "react" ;
1+ import React , { useEffect , useState , useRef } from "react" ;
22import { useDispatch , useSelector } from "react-redux" ;
33import { Checkbox , FormControlLabel , makeStyles , Paper } from "@material-ui/core" ;
44import Container from "@material-ui/core/Container" ;
@@ -13,7 +13,6 @@ import CryptoJs from "crypto-js/crypto-js";
1313import { FileDataReader } from "../../utils/FileDataReader" ;
1414import { CryptoCalculator } from "../../utils/CryptoCalculator" ;
1515import BackButton from "../../components/BackButton" ;
16- import Input from '@material-ui/core/Input' ;
1716
1817const useStyles = makeStyles ( theme => ( {
1918 heroContent : {
@@ -43,14 +42,16 @@ const useStyles = makeStyles(theme => ({
4342const File = ( ) => {
4443
4544 const hashes = useSelector ( state => state . CryptoReducer . fileHashes ) ;
45+ const file = useSelector ( state => state . CryptoReducer . currentFile ) ;
4646 const language = useSelector ( state => state . MainReducer . languages [ state . MainReducer . languageIndex ] ) ;
4747 const dispatch = useDispatch ( ) ;
4848 const classes = useStyles ( ) ;
4949
50- const [ file , setFile ] = useState ( null ) ;
5150 const [ compare , setCompare ] = useState ( false ) ;
5251 const [ compareHash , setCompareHash ] = useState ( "" ) ;
5352
53+ const fileRef = useRef ( null ) ;
54+
5455 const md5 = useSelector ( state => state . CryptoReducer . md5 ) ;
5556 const sha1 = useSelector ( state => state . CryptoReducer . sha1 ) ;
5657 const sha224 = useSelector ( state => state . CryptoReducer . sha224 ) ;
@@ -80,7 +81,6 @@ const File = () => {
8081 < CopyPasteMenu id = { 1 } copyData = { ( ) => navigator . clipboard . writeText ( compareHash ) }
8182 pasteData = { ( ) => pasteData ( setCompareHash ) } >
8283 < TextField
83- id = "outlined-basic"
8484 style = { { width : '100%' } }
8585 margin = "normal"
8686 value = { compareHash }
@@ -127,10 +127,18 @@ const File = () => {
127127 * Clear the user interface
128128 */
129129 const clearData = ( ) => {
130- setFile ( null ) ;
131130 setCompare ( false ) ;
132131 setCompareHash ( "" ) ;
133- dispatch ( { type : "SET_FILE_HASHES" , payload : null } ) ;
132+ dispatch ( { type : 'SET_CURRENT_FILE' , payload : null } ) ;
133+ } ;
134+
135+ /**
136+ * Change the currently selected file
137+ * @param event The event that called this function
138+ */
139+ const onFileChange = function ( event ) {
140+ dispatch ( { type : 'SET_CURRENT_FILE' , payload : event . target . files [ 0 ] } ) ;
141+ fileRef . current . value = "" ;
134142 } ;
135143
136144 return (
@@ -154,7 +162,19 @@ const File = () => {
154162 { language . input }
155163 </ Typography >
156164 < Paper className = { classes . paper } >
157- < Input type = { "file" } onChange = { e => setFile ( e . target . files [ 0 ] ) } disableUnderline = { true } />
165+ < TextField
166+ margin = "normal"
167+ onClick = { ( ) => fileRef . current . click ( ) }
168+ disabled
169+ id = "filled-disabled"
170+ value = { file && file . path ? file . path : "" }
171+ variant = "outlined"
172+ />
173+
174+ < input ref = { fileRef } type = "file" onChange = { onFileChange }
175+ style = { { display : 'none' } } />
176+
177+ < Button color = { "primary" } variant = { "contained" } onClick = { ( ) => fileRef . current . click ( ) } > { language . select } </ Button >
158178
159179 < FormControlLabel
160180 control = {
0 commit comments