Updating the callbacks function.

This commit is contained in:
Nate Taylor
2019-10-25 20:16:16 -05:00
parent 92a8bb3012
commit 6028661f00

View File

@@ -27,33 +27,30 @@ export function raceCondition() {
} }
export function callbacks() { export function callbacks() {
var xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.open("GET", "http://localhost:3000/orders"); let statuses = [];
xhr.open("GET", "http://localhost:3000/orderStatuses");
xhr.onload = () => { xhr.onload = () => {
const data = JSON.parse(xhr.responseText); statuses = JSON.parse(xhr.responseText);
const itemId = data[0].itemIds[0];
let xhr2 = new XMLHttpRequest();
xhr2.open("GET", "http://localhost:3000/orders/1");
const xhr2 = new XMLHttpRequest();
xhr2.open("GET", `http://localhost:3000/items/${itemId}`);
xhr2.onload = () => { xhr2.onload = () => {
const data = JSON.parse(xhr2.responseText); const order = JSON.parse(xhr2.responseText);
const categoryId = data.itemCategoryId;
const xhr3 = new XMLHttpRequest(); const description = statuses.map(t => {
xhr3.open("GET", `http://localhost:3000/itemCategories/${categoryId}`); if (t.id === order.orderStatusId) {
return t.description;
xhr3.onload = () => {
const {description} = JSON.parse(xhr3.responseText);
setText(`Order Item Category: ${description}`);
} }
xhr3.onerror = () => setText(xhr3.statusText); })[0];
xhr3.send();
setText(`Order Status: ${description}`);
}; };
xhr2.onerror = () => setText(xhr2.statusText);
xhr2.send(); xhr2.send();
}; };
xhr.onerror = () => setText(xhr.statusText);
xhr.send(); xhr.send();
} }