-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (50 loc) · 1.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//Run asynchronous function that renders dynamic class and race sections.
start();
async function start() {
//Api request for classes.
let classesFromAPI = await doAPIrequest("classes/");
// console.log(classesFromAPI);
let arrayOfClassNames = classesFromAPI.results.map(
(current) => current.index
);
// console.log(arrayOfClassNames);
//Api request for races.
let racesFromAPI = await doAPIrequest("races/");
// console.log(racesFromAPI);
let arrayOfRaceNames = racesFromAPI.results.map((current) => current.index);
// console.log(arrayOfRaceNames);
// let allMyPromises = arrayOfClassNames.map(current => doAPIrequest(`classes/${current}`));
//
// const classDetails = await Promise.all(allMyPromises);
// console.log(classDetails);
//Renders class of Classes and Races to the DOM.
ReactDOM.render(
<Classes classesArray={arrayOfClassNames} />,
document.querySelector("#classes")
);
ReactDOM.render(
<Races racesArray={arrayOfRaceNames} />,
document.querySelector("#races")
);
}
//Run asynchronous api request and return in json format.
async function doAPIrequest(endpoint) {
let requestUrl = "https://www.dnd5eapi.co/api/" + endpoint;
console.log("Fetching: " + requestUrl);
let response = await fetch(requestUrl);
// Get the API response as a JSON.
const json = await response.json();
return json;
}
var monsterTable = document.getElementById("M-banner");
monsterTable.onclick = function () {
window.location.href = "Subpages/monsters.html";
};
var equipTable = document.getElementById("E-banner");
equipTable.onclick = function () {
window.location.href = "Subpages/equipment.html";
};
var spellTable = document.getElementById("S-banner");
spellTable.onclick = function () {
window.location.href = "Subpages/spells.html";
};