-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (55 loc) · 2.02 KB
/
script.js
File metadata and controls
56 lines (55 loc) · 2.02 KB
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
const timeBtn=document.querySelectorAll('.controle-panel .bottom h2');
const boxCon=document.querySelector('.boxes');
fetch('https://raw.githubusercontent.com/christopherjael/time-tracking-dashboard--solution/master/data.json').then((res)=>{
return res.json();
}).then((d)=>{
return d;
}).then((res)=>{
getClicked(res);
boxCon.childElementCount===0?document.querySelector('.weekly').click():' ';
})
function getClicked(array){
timeBtn.forEach((btn)=>{
btn.addEventListener('click',()=>{
switch (btn.className){
case 'daily':
boxCon.innerHTML=''
createBoxes(array,'daily','day');
break;
case 'monthly':
boxCon.innerHTML=''
createBoxes(array,'monthly','month');
break;
case 'weekly':
boxCon.innerHTML=''
createBoxes(array,'weekly','week');
break;
}
btn.classList.add('active');
})
})
}
function createBoxes(array,time,timeTitle){
timeBtn.forEach((btn)=>{
btn.classList.remove('active')
})
array.forEach((el)=>{
let box=`
<div class="box ${el.title.toLowerCase()}">
<div class="img"></div>
<div class="text">
<div class="header">
<h3>${el.title}</h3>
<svg xmlns="http://www.w3.org/2000/svg" width="21" height="5" ><path d="M2.5 0a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5Zm8 0a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5Zm8 0a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5Z" fill="#BBC0FF" fill-rule="evenodd" class="dot"/></svg>
</div>
<div class="content">
<h3>${el.timeframes[time].current}hrs</h3>
<p>last-${timeTitle} - ${el.timeframes[time].previous}hrs</p>
</div>
</div>
</div>
`;
boxCon.innerHTML+=box;
})
}
window.onload=()=>{document.querySelector('.weekly').click()};