forked from elise-bigdevsoon/big-dev-soon-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (40 loc) · 1.43 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
document.addEventListener("DOMContentLoaded", () => {
// DOM variables
const main = document.querySelector("main");
const sidebar = document.querySelector(".sidebar");
const cardsElement = document.querySelector(".cards-container");
// Get Data from API
const apiUrl = 'https://dummyjson.com/c/0bbf-1685-443d-b67c';
window.fetch(apiUrl).then((response) => {
return response.json();
}).then((data) => {
const cards = data[0]["General data"];
const charts = data[1];
const integration = data[2];
cards.forEach(card => {
const cardElement = `<div class="card">
<h3>${card.title}</h3>
<div class="value">${card.cardvalue}</div>
<div class="change">
<div class="trend ${card.trend}">${card.change}</div>
<div>Compared to last month</div>
</div>
</div>`
cardsElement.innerHTML += cardElement;
});
})
// Sidebar open/close beahvior
document.querySelector(".toggle-sidebar").addEventListener("click", (e) => {
if(main.classList.contains("side-open")) {
main.classList.remove("side-open");
main.classList.add("side-closed");
sidebar.classList.remove("open");
sidebar.classList.add("close");
} else {
main.classList.remove("side-closed");
main.classList.add("side-open");
sidebar.classList.remove("close");
sidebar.classList.add("open");
}
})
});