Skip to content

Commit 78f2634

Browse files
FlurinFlurin
Flurin
authored and
Flurin
committed
react stuff
1 parent f3d1197 commit 78f2634

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

soemi-woeb/src/App.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,49 @@ function App() {
55
const [location, setLocation] = useState('');
66
const [planet, setPlanet] = useState(null)
77

8-
const handleRestCall = () => {
9-
fetch(`http://sömi-weather.ch/api/get-the-star-wars-planets-mapping-for-the-current-temperature-completely-and-utterly-accurate?temp=${location}`)
10-
.then((response) => response.json())
11-
.then((data) => setPlanet(data))
12-
.catch((error) => console.error(error));
8+
const handleRestCall = async () => {
9+
const temp = await getTemp();
10+
const imgRes = await fetch(`http://sömi-weather.ch/api/get-the-star-wars-planets-mapping-for-the-current-temperature-completely-and-utterly-accurate?temp=${temp}`)
11+
const imgJson = await imgRes.json();
12+
13+
setPlanet(imgJson);
14+
};
15+
16+
const getTemp = async () => {
17+
const res = await fetch(`http://localhost:8080/engine-rest/process-definition/key/Process_13h4fbi/start`, {
18+
method: "POST",
19+
headers: {
20+
"Content-Type": "application/json"
21+
},
22+
body: JSON.stringify(
23+
{
24+
"businessKey": "yourBusinessKey",
25+
"variables": {
26+
"location": {"value": location, "type": "String"}
27+
}
28+
}
29+
)
30+
});
31+
const json = await res.json();
32+
const id = await json.id;
33+
34+
for(let i = 0; i < 10; i++)
35+
{
36+
await delay(500);
37+
try
38+
{
39+
const varRes = await fetch(`http://localhost:8080/engine-rest/history/variable-instance?processInstanceId=${id}&variableName=temp`)
40+
const varJson = await varRes.json();
41+
const temp = varJson.value;
42+
43+
return temp;
44+
}
45+
catch (err)
46+
{
47+
console.log(err);
48+
console.log("retrying");
49+
}
50+
}
1351
};
1452

1553
return (
@@ -26,6 +64,13 @@ function App() {
2664
);
2765
}
2866

67+
function delay(time) {
68+
return new Promise((resolve) => {
69+
setTimeout(() => resolve(), time);
70+
});
71+
}
72+
73+
2974
export function Planet({ planet }) {
3075
const {name, image} = planet
3176

0 commit comments

Comments
 (0)