diff options
author | Pierluigi Minardi <pigi-1990@hotmail.it> | 2021-07-15 17:56:36 +0200 |
---|---|---|
committer | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-07-16 05:31:37 +0530 |
commit | ad662650979b3d3aced69770ecb20a4b974ddf4a (patch) | |
tree | 9e37a18798d85fc625b35b23b0465a51a624a400 /src/components/ui | |
parent | Fix the file path format + function to recognize the OS (diff) | |
download | ferdium-app-ad662650979b3d3aced69770ecb20a4b974ddf4a.tar.gz ferdium-app-ad662650979b3d3aced69770ecb20a4b974ddf4a.tar.zst ferdium-app-ad662650979b3d3aced69770ecb20a4b974ddf4a.zip |
if changed with conditional operator + getOS removed and replaced with isWindows
Diffstat (limited to 'src/components/ui')
-rw-r--r-- | src/components/ui/ImageUpload.js | 30 |
1 files 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'; | |||
4 | import { Field } from 'mobx-react-form'; | 4 | import { Field } from 'mobx-react-form'; |
5 | import classnames from 'classnames'; | 5 | import classnames from 'classnames'; |
6 | import Dropzone from 'react-dropzone'; | 6 | import Dropzone from 'react-dropzone'; |
7 | import { isWindows } from '../../environment'; | ||
7 | 8 | ||
8 | export default @observer class ImageUpload extends Component { | 9 | export default @observer class ImageUpload extends Component { |
9 | static propTypes = { | 10 | static propTypes = { |
@@ -24,49 +25,24 @@ export default @observer class ImageUpload extends Component { | |||
24 | }; | 25 | }; |
25 | 26 | ||
26 | dropzoneRef = null; | 27 | dropzoneRef = null; |
27 | |||
28 | imgPath = null; | 28 | imgPath = null; |
29 | 29 | ||
30 | onDrop(acceptedFiles) { | 30 | onDrop(acceptedFiles) { |
31 | const { field } = this.props; | 31 | const { field } = this.props; |
32 | 32 | ||
33 | acceptedFiles.forEach((file) => { | 33 | acceptedFiles.forEach((file) => { |
34 | console.log(this.getOS()); | 34 | this.imgPath = isWindows ? file.path.replace(/\\/g, '/') : file.path; |
35 | |||
36 | if (this.getOS() === 'Windows') { | ||
37 | this.imgPath = file.path.replace(/\\/g, '/'); | ||
38 | } else { | ||
39 | this.imgPath = file.path; | ||
40 | } | ||
41 | |||
42 | console.log(this.imgPath); | ||
43 | 35 | ||
44 | this.setState({ | 36 | this.setState({ |
45 | path: this.imgPath, | 37 | path: this.imgPath, |
46 | }); | 38 | }); |
39 | |||
47 | this.props.field.onDrop(file); | 40 | this.props.field.onDrop(file); |
48 | }); | 41 | }); |
49 | 42 | ||
50 | field.set(''); | 43 | field.set(''); |
51 | } | 44 | } |
52 | 45 | ||
53 | getOS() { | ||
54 | const platform = window.navigator.platform; | ||
55 | const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']; | ||
56 | const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; | ||
57 | let os = null; | ||
58 | |||
59 | if (macosPlatforms.indexOf(platform) !== -1) { | ||
60 | os = 'Mac OS'; | ||
61 | } else if (windowsPlatforms.indexOf(platform) !== -1) { | ||
62 | os = 'Windows'; | ||
63 | } else if (!os && /Linux/.test(platform)) { | ||
64 | os = 'Linux'; | ||
65 | } | ||
66 | |||
67 | return os; | ||
68 | } | ||
69 | |||
70 | render() { | 46 | render() { |
71 | const { | 47 | const { |
72 | field, className, multiple, textDelete, textUpload, | 48 | field, className, multiple, textDelete, textUpload, |