From ad662650979b3d3aced69770ecb20a4b974ddf4a Mon Sep 17 00:00:00 2001 From: Pierluigi Minardi Date: Thu, 15 Jul 2021 17:56:36 +0200 Subject: if changed with conditional operator + getOS removed and replaced with isWindows --- src/components/ui/ImageUpload.js | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/components/ui/ImageUpload.js b/src/components/ui/ImageUpload.js index fdcf77509..9510cf6a5 100644 --- a/src/components/ui/ImageUpload.js +++ b/src/components/ui/ImageUpload.js @@ -4,6 +4,7 @@ import { observer } from 'mobx-react'; import { Field } from 'mobx-react-form'; import classnames from 'classnames'; import Dropzone from 'react-dropzone'; +import { isWindows } from '../../environment'; export default @observer class ImageUpload extends Component { static propTypes = { @@ -24,49 +25,24 @@ export default @observer class ImageUpload extends Component { }; dropzoneRef = null; - imgPath = null; onDrop(acceptedFiles) { const { field } = this.props; acceptedFiles.forEach((file) => { - console.log(this.getOS()); - - if (this.getOS() === 'Windows') { - this.imgPath = file.path.replace(/\\/g, '/'); - } else { - this.imgPath = file.path; - } - - console.log(this.imgPath); + this.imgPath = isWindows ? file.path.replace(/\\/g, '/') : file.path; this.setState({ path: this.imgPath, }); + this.props.field.onDrop(file); }); field.set(''); } - getOS() { - const platform = window.navigator.platform; - const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']; - const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; - let os = null; - - if (macosPlatforms.indexOf(platform) !== -1) { - os = 'Mac OS'; - } else if (windowsPlatforms.indexOf(platform) !== -1) { - os = 'Windows'; - } else if (!os && /Linux/.test(platform)) { - os = 'Linux'; - } - - return os; - } - render() { const { field, className, multiple, textDelete, textUpload, -- cgit v1.2.3-54-g00ecf