Skip to content

Commit 3a03d08

Browse files
Merge pull request #15 from visual-heuristics/feat_fetch_problem_file
Send backend response to page4
2 parents 8d1eeba + 69161d7 commit 3a03d08

File tree

6 files changed

+27
-377
lines changed

6 files changed

+27
-377
lines changed

src/pages/PageOne/dragAndDrop.jsx

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/pages/PageOne/dropAndFetch.jsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,23 @@ class DropAndFetch extends React.Component {
2727
],
2828
};
2929

30-
uploadPDDL = (files) => {
30+
uploadPDDL = async (files) => {
3131
const formData = new FormData();
3232
for (const name in files) {
3333
formData.append(name, files[name]);
3434
}
35-
let resp;
35+
const resp = await fetch(
36+
"https://planimation.planning.domains/upload/pddl",
37+
{
38+
//"http://127.0.0.1:8000/upload/pddl" On local server
39+
method: "POST", //DO NOT use headers
40+
body: formData, // Dataformat
41+
}
42+
);
3643

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;
44+
const data = await resp.json();
45+
const txt = JSON.stringify(data);
46+
this.props.onStore(txt);
5047
};
5148

5249
handleSubmit = () => {
@@ -56,16 +53,16 @@ class DropAndFetch extends React.Component {
5653
"problem" in this.datas &&
5754
"animation" in this.datas
5855
) {
59-
let resp = this.uploadPDDL(this.datas);
60-
console.log(resp);
56+
this.uploadPDDL(this.datas);
6157
} else {
6258
console.log("Some files are missing");
6359
alert("Some files are missing");
6460
}
6561
};
6662

6763
handleFileLoad = (name, file) => {
68-
this.datas[name] = file;
64+
this.datas[name.toLowerCase()] = file;
65+
console.log(this.datas);
6966
};
7067

7168
render() {
@@ -87,7 +84,7 @@ class DropAndFetch extends React.Component {
8784
<div className={css.buttonBox}>
8885
<Button
8986
variant="contained"
90-
color="#224878"
87+
color="default"
9188
onClick={() => this.props.onClick()}
9289
>
9390
Cancel

src/pages/PageOne/dropZone.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ class DropZone extends React.Component {
1515
console.log(file);
1616

1717
if (file[0].name.endsWith(this.props.fileType)) {
18-
console.log(this.state.files);
18+
//console.log(this.state.files);
1919
this.setState({ files: file });
20-
console.log(this.state.files);
21-
this.props.onFileLoad(this.props.name, file[0]);
20+
//console.log(this.state.files);
21+
file[0].text().then((result) => {
22+
this.props.onFileLoad(this.props.name, result);
23+
});
2224
} else {
2325
console.log("Wrong file type");
2426
alert("Wrong file type");

src/pages/PageOne/dragAndDrop.test.js renamed to src/pages/PageOne/dropZone.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import DragAndDrop from './dragAndDrop';
3+
import DropZone from './dropZone';
44

55

66
it("Renders Correctly ", () => {

src/pages/PageOne/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class PageOne extends React.Component {
5353
handleOnClick() {
5454
this.props.history.push('/')
5555
}
56+
handleStore = (content)=> {
57+
localStorage.setItem('fileContent', content);
58+
window.location.href = '/page4';
59+
}
5660

5761
render() {
5862

@@ -91,7 +95,7 @@ class PageOne extends React.Component {
9195
Option 2 - Upload Problem Domain and Animation Profile Files
9296
</h3>
9397
</div>
94-
<DropAndFetch onClick={this.handleOnClick}/>
98+
<DropAndFetch onClick={this.handleOnClick} onStore={this.handleStore}/>
9599
</div>
96100

97101
);

0 commit comments

Comments
 (0)