-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadButton.js
62 lines (48 loc) · 1.87 KB
/
loadButton.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
const LoadButtonCategories = ()=>{
fetch('https://openapi.programming-hero.com/api/peddy/categories')
.then(res=> res.json())
.then(data => LoadPetsInfoForBtn(data.categories))
.catch(error => console.log(error));
}
LoadButtonCategories();
const removeActiveClass=()=>{
const classname = document.getElementsByClassName('active-btn-class');
// ei class name theke ekta arry-like ase jar protita elements ke normally for calay access korte hobe
// classname.classList.remove('active');
for(const btn of classname){
btn.classList.remove('active');
}
}
// to show pets by category
const loadbycategory=(id)=>{
fetch(`https://openapi.programming-hero.com/api/peddy/category/${id}`)
.then(res=> res.json())
.then(data => {
removeActiveClass();
const activebtn = document.getElementById(`btn-${id}`);
activebtn.classList.add('active');
// add spinner start
document.getElementById('animal-show').style.display="none";
document.getElementById('wishlist-content').style.display="none";
document.getElementById('spinner').style.display="block";
setTimeout(function(){
showAllPets(data.data)
},2000)
})
.catch(error => console.log(error));
}
const LoadPetsInfoForBtn = (pets) =>{
const btnContainer = document.getElementById('btn-container');
// console.log(pets);
pets.forEach(pet => {
const div = document.createElement('div');
// button onclick function --
div.innerHTML= `
<button id="btn-${pet.category}" onclick="loadbycategory('${pet.category}')" class="active-btn-class btn btn-outline hover:rounded-full text-black font-bold category-btn h-[73px] w-[143px]">
<img src=${pet.category_icon}> ${pet.category}
</button>
`
btnContainer.append(div);
});
}
// LoadPetsInfo();