-
Notifications
You must be signed in to change notification settings - Fork 3
/
companies.js
187 lines (167 loc) · 5.56 KB
/
companies.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
let login = document.getElementById("loginbtn").addEventListener("click",()=>{
window.location.href="signin.html"
})
let register = document.getElementById("registerbtn").addEventListener("click",()=>{
window.location.href="signup.html"
})
let landingPage = document.getElementById("dashboardlogo").addEventListener("click",()=>{
window.location.href="index.html"
})
let fetchURL = "https://636d633891576e19e327545a.mockapi.io/companies";
let companyData = document.querySelector(".companyList>div");
let arr = [];
// fetch company data
async function fetchData(pageNumber = 1) {
try {
let res = await fetch(`${fetchURL}?page=${pageNumber}&limit=14`);
let data = await res.json();
arr = data;
renderData(arr);
let totalPage = 5;
paginationData(totalPage);
} catch (err) {
console.log("Error Occurred");
}
}
fetchData();
function renderData(comData) {
// render data
companyData.innerHTML = "";
companyData.innerHTML = comData
.map((item) => {
return `
<div class="combox" data-id=${item.id}>
<div>
<img
src=${item.avatar}
alt="image"
/>
</div>
<div>
<h3>${item.companyName}</h3>
<p><i class="fa-solid fa-star"></i> ${item.rating}</p>
<p>${item.location}</p>
<p>${item.jobRole}</p>
</div>
</div>
`;
})
.join(" ");
// company detail
let comboxes = document.querySelectorAll(".combox");
for (let combox of comboxes) {
combox.addEventListener("click", (event) => {
for (let i = 0; i < comData.length; i++) {
if (comData[i].id === combox.dataset.id) {
localStorage.setItem("detailCompany", JSON.stringify(comData[i]));
window.location.href = "com_detail.html";
}
}
});
}
}
// filterPart
let inputJobButtons = document.querySelectorAll("#jobRole input");
for (let inputButton of inputJobButtons) {
inputButton.addEventListener("click", (event) => {
inputButton.setAttribute("checked", false);
if (inputButton.checked) {
inputButton.setAttribute("checked", true);
}
let inputValue = inputButton.value;
let filteredComp = arr.filter((item) => {
return item.jobRole === inputValue;
});
if (inputButton.checked) {
renderData(filteredComp);
} else {
renderData(arr);
}
});
}
let inputLocationButtons = document.querySelectorAll("#location input");
for (let inputButton of inputLocationButtons) {
inputButton.addEventListener("click", (event) => {
inputButton.setAttribute("checked", false);
if (inputButton.checked) {
inputButton.setAttribute("checked", true);
}
let inputValue = inputButton.value;
let filteredComp = arr.filter((item) => {
return item.location === inputValue;
});
if (inputButton.checked) {
renderData(filteredComp);
} else {
renderData(arr);
}
});
}
// Pagination part
function paginationData(totalPage) {
let paginationSection = document.querySelector(".pagination");
paginationSection.innerHTML = `
${createPagButton(totalPage).join(" ")}
`;
let pageButtons = document.querySelectorAll(".pagination-btn");
for (let pageButton of pageButtons) {
pageButton.addEventListener("click", (event) => {
let pageNumber = event.target.dataset.id;
// let limti = 16;
fetchData(pageNumber);
});
}
}
function createPagButton(totalPage) {
let array = [];
for (let page = 1; page <= totalPage; page++) {
array.push(
`<div class="pagination-btn" ${page ? `data-id = ${page}` : ""}><h4 ${
page ? `data-id = ${page}` : ""
}>${page}</h4></div>`
);
}
return array;
}
// hiringPart.nextElementSibling.children[0].classList.toggle("active");
let hiringParts = document.querySelectorAll(".hiring-part h3");
// for(let i=0; i<hiringParts.length; i++) {
// hiringParts[i].addEventListener("click",function(event){
// let main = hiringParts[i].nextElementSibling;
// if(main.style.display == "grid") {
// main.style.display = "none";
// } else {
// main.style.display = "grid";
// }
// })
// }
for (let i = 0; i < hiringParts.length; i++) {
hiringParts[0].nextElementSibling.style.display = "block";
hiringParts[0].style.borderBottom = "4px solid orange"
hiringParts[i].addEventListener("click", function () {
if (i == 0) {
hiringParts[0].style.borderBottom = "4px solid orange"
hiringParts[1].style.borderBottom = "none"
hiringParts[2].style.borderBottom = "none"
hiringParts[0].nextElementSibling.style.display = "block";
hiringParts[1].nextElementSibling.style.display = "none";
hiringParts[2].nextElementSibling.style.display = "none";
}
else if (i == 1) {
hiringParts[1].style.borderBottom = "4px solid orange"
hiringParts[0].style.borderBottom = "none"
hiringParts[2].style.borderBottom = "none"
hiringParts[1].nextElementSibling.style.display = "block";
hiringParts[0].nextElementSibling.style.display = "none";
hiringParts[2].nextElementSibling.style.display = "none";
}
else if (i == 2) {
hiringParts[2].style.borderBottom = "4px solid orange"
hiringParts[0].style.borderBottom = "none"
hiringParts[1].style.borderBottom = "none"
hiringParts[2].nextElementSibling.style.display = "block";
hiringParts[0].nextElementSibling.style.display = "none";
hiringParts[1].nextElementSibling.style.display = "none";
}
});
}