@@ -5,48 +5,52 @@ import Container from "@material-ui/core/Container";
5
5
import CloudUploadIcon from "@material-ui/icons/CloudUpload" ;
6
6
import css from "./index.module.less" ;
7
7
8
+ const dragsAndDrops = [
9
+ { name : "Domain" , fileType : ".pddl" , desc : "or predictes and actions." } ,
10
+ {
11
+ name : "Problem" ,
12
+ fileType : ".pddl" ,
13
+ desc : "for objects, initial state and goal." ,
14
+ } ,
15
+ {
16
+ name : "Animation" ,
17
+ fileType : ".pddl" ,
18
+ desc : "object is representation." ,
19
+ } ,
20
+ ] ;
8
21
class DropAndFetch extends React . Component {
9
22
constructor ( props ) {
10
23
super ( props ) ;
11
24
this . datas = { } ;
12
25
}
13
26
14
- state = {
15
- dragsAndDrops : [
16
- { name : "Domain" , fileType : ".pddl" , desc : "or predictes and actions." } ,
17
- {
18
- name : "Problem" ,
19
- fileType : ".pddl" ,
20
- desc : "for objects, initial state and goal." ,
21
- } ,
22
- {
23
- name : "Animation" ,
24
- fileType : ".pddl" ,
25
- desc : "object is representation." ,
26
- } ,
27
- ] ,
27
+ componentWillUnmount = ( ) => {
28
+ this . setState = ( state , callback ) => {
29
+ return ;
30
+ } ;
28
31
} ;
29
32
30
- uploadPDDL = ( files ) => {
33
+ uploadPDDL = async ( files ) => {
31
34
const formData = new FormData ( ) ;
32
35
for ( const name in files ) {
33
36
formData . append ( name , files [ name ] ) ;
34
37
}
35
- let resp ;
38
+ try {
39
+ const resp = await fetch (
40
+ "https://planimation.planning.domains/upload/pddl" ,
41
+ {
42
+ //"http://127.0.0.1:8000/upload/pddl" On local server
43
+ method : "POST" , //DO NOT use headers
44
+ body : formData , // Dataformat
45
+ }
46
+ ) ;
36
47
37
- fetch ( "https://planimation.planning.domains/upload/pddl" , {
38
- //"http://127.0.0.1:8000/upload/pddl", {
39
- method : "POST" , //DO NOT use headers
40
- body : formData , // Dataformat
41
- } )
42
- . then (
43
- ( response ) => console . log ( response ) //read response code and replicate
44
- )
45
- . then (
46
- ( success ) => ( resp = success ) //success contains the VFG
47
- )
48
- . catch ( ( error ) => console . log ( error ) ) ;
49
- return resp ;
48
+ const data = await resp . json ( ) ;
49
+ const txt = JSON . stringify ( data ) ;
50
+ this . props . onStore ( txt ) ;
51
+ } catch ( error ) {
52
+ alert ( error ) ;
53
+ }
50
54
} ;
51
55
52
56
handleSubmit = ( ) => {
@@ -56,24 +60,24 @@ class DropAndFetch extends React.Component {
56
60
"problem" in this . datas &&
57
61
"animation" in this . datas
58
62
) {
59
- let resp = this . uploadPDDL ( this . datas ) ;
60
- console . log ( resp ) ;
63
+ this . uploadPDDL ( this . datas ) ;
61
64
} else {
62
65
console . log ( "Some files are missing" ) ;
63
66
alert ( "Some files are missing" ) ;
64
67
}
65
68
} ;
66
69
67
70
handleFileLoad = ( name , file ) => {
68
- this . datas [ name ] = file ;
71
+ this . datas [ name . toLowerCase ( ) ] = file ;
72
+ console . log ( this . datas ) ;
69
73
} ;
70
74
71
75
render ( ) {
72
76
return (
73
77
< React . Fragment >
74
78
< div >
75
79
< Container component = "main" className = { css . dropareaBox } >
76
- { this . state . dragsAndDrops . map ( ( drag ) => (
80
+ { dragsAndDrops . map ( ( drag ) => (
77
81
< DropZone
78
82
key = { drag . name }
79
83
name = { drag . name }
@@ -83,11 +87,11 @@ class DropAndFetch extends React.Component {
83
87
/>
84
88
) ) }
85
89
</ Container >
86
- < Container maxWidth = "sm" component = "main" marginTop = "50" >
90
+ < Container maxWidth = "sm" component = "main" >
87
91
< div className = { css . buttonBox } >
88
92
< Button
89
93
variant = "contained"
90
- color = "#224878 "
94
+ color = "default "
91
95
onClick = { ( ) => this . props . onClick ( ) }
92
96
>
93
97
Cancel
0 commit comments