-
Notifications
You must be signed in to change notification settings - Fork 6
/
details.js
84 lines (74 loc) · 3.13 KB
/
details.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
document.addEventListener("DOMContentLoaded", () => {
const urlParams = new URLSearchParams(window.location.search);
const jobId = urlParams.get("id");
fetch("./data.json")
.then((response) => response.json())
.then((data) => {
const job = data.find((job) => job.id === jobId);
if (job) {
document.querySelector(".title").textContent = job.title;
document.querySelector(".employer").textContent += job.employer;
document.querySelector(".departament").textContent += job.department;
document.querySelector(".location").textContent = job.location;
document.querySelector(".jobType").textContent = job.jobType;
document.querySelector(".experience").textContent = job.experience;
document.querySelector(".salary").textContent = job.salary;
document.getElementById("jd").textContent = job.jobDescription;
const responsabilities = document.getElementById("responsabilities");
job.responsabilities.forEach((item) => {
const li = document.createElement("li");
li.textContent = item;
responsabilities.appendChild(li);
});
const demands = document.getElementById("demands");
job.demands.forEach((item) => {
const li = document.createElement("li");
li.textContent = item;
demands.appendChild(li);
});
const offerings = document.getElementById("offerings");
job.offerings.forEach((item) => {
const li = document.createElement("li");
li.textContent = item;
offerings.appendChild(li);
});
const generalInfo = document.getElementById("generalInfo");
job.generalInfo.forEach((item) => {
const li = document.createElement("li");
li.textContent = item;
generalInfo.appendChild(li);
});
document.getElementById("recruiter-photo").src =
job.aboutEmployer.photo;
document.querySelector(".contact__person").textContent =
job.aboutEmployer.name;
document.querySelector(".contact__role").textContent =
job.aboutEmployer.title;
document.getElementById("phone").textContent += job.aboutEmployer.phone;
document.getElementById("email").textContent += job.aboutEmployer.email;
document.getElementById("address").textContent +=
job.aboutEmployer.address;
}
checkPath(data); // Call the function to check if the path matches any of the job IDs
})
.catch((error) => {
{
throw new Error("Error loading data:", error);
}
});
});
function checkPath(data, idKey = "id") {
try {
if (!Array.isArray(data) || data.length === 0) {
throw new Error("Invalid data provided");
}
const path = new URLSearchParams(window.location.search);
const pathId = path.get(idKey);
const matchFound = data.some((job) => job[idKey] === pathId);
if (!matchFound) {
window.location.href = "404.html";
}
} catch (error) {
console.error("Error in checkPath:", error.message);
}
}