Switch to unified view

a b/app/frontend/src/components/Upload.js
1
import React, { Component } from 'react'
2
import Loader from 'react-loader-spinner'
3
4
import {connect} from 'react-redux';
5
import {postRequest} from '../actions'
6
7
import {Link} from 'react-router-dom';
8
9
10
11
class Upload extends Component {
12
    state = {
13
        loading: false,
14
        file: [],
15
        error:""
16
    }
17
18
    handleFileUpload = (e) => {
19
        let filesUploaded = e.target.files
20
        
21
        this.setState({
22
            loading:true
23
        },
24
        ()=>console.log("Just Set to Loading!"))
25
        
26
        this.props.postRequest(filesUploaded).then(()=>this.setState({
27
            loading:false,
28
            error:"Data Succesfully Loaded"
29
        }))
30
        
31
        // .catch(()=>this.setState({
32
        //     loading: false,
33
        //     error: "Upload Failed. Please try again"
34
        // })).then(()=>this.setState({loading:false, error:"Data Succesfully Loaded"})
35
        // ).catch((e)=>this.setState({error: "Upload Failed. Please try again"}))
36
    }
37
38
    renderError = () => {
39
        if(this.state.error == "Data Succesfully Loaded"){
40
            return <p style ={{fontSize:"10px", margin:"20px 0px"}}>Your results have been loaded, check out <Link to ='/past' class="no-underline hover:underline text-blue-500 px-1">past results</Link> to view them</p>
41
        }
42
        if(this.state.error){
43
            return  <p style = {{color: "red", fontSize:"10px", margin:"20px 0px"}}>{this.state.error}</p>
44
        }
45
    }
46
47
    render() {
48
        if(this.state.loading){
49
            return(
50
                <div class="flex w-full h-screen items-center justify-center bg-grey-lighter">
51
                <Loader
52
                    type="TailSpin"
53
                    color="#00BFFF"
54
                    height={150}
55
                    width={150}
56
                />
57
                </div>
58
            )
59
        }
60
        else{
61
            return (
62
                <div className = "h-screen" style={{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"}}>
63
                <div class="flex w-full items-center justify-center bg-grey-lighter">
64
                <button onChange = {this.handleFileUpload}>
65
                <label class="w-64 flex flex-col items-center px-4 py-6 bg-white text-blue rounded-lg shadow-lg tracking-wide uppercase border border-blue cursor-pointer">
66
                    
67
                        <svg class="w-8 h-8" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
68
                        <path d="M16.88 9.1A4 4 0 0 1 16 17H5a5 5 0 0 1-1-9.9V7a3 3 0 0 1 4.52-2.59A4.98 4.98 0 0 1 17 8c0 .38-.04.74-.12 1.1zM11 11h3l-4-4-4 4h3v3h2v-3z" />
69
                        </svg>
70
                        <span class="mt-2 text-base leading-normal">Upload your image</span>
71
                        <span style = {{fontSize:"8px"}}>* Only PA and AP X-ray views are supported at the moment. Prediction accuracy might be affected if other views are used</span>
72
                        <input type='file' multiple class="hidden" />
73
            
74
                </label>
75
                
76
                </button>
77
                
78
                </div>
79
                {this.renderError()}
80
                </div>
81
                )
82
        }
83
        
84
    }
85
}
86
87
const mapStateToProps = state =>{
88
    return {
89
        images: state.Image
90
    }
91
}
92
93
export default connect(mapStateToProps,{
94
    postRequest
95
})(Upload);