Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
142 lines (119 loc) · 4.28 KB
/
Copy pathscript.js
File metadata and controls
142 lines (119 loc) · 4.28 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
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
document.addEventListener("DOMContentLoaded", () => {
const form = document.getElementById("application-form");
const tableBody = document.getElementById("application-table-body");
const totalCountEl = document.getElementById("total-count");
const interviewCountEl = document.getElementById("interview-count");
const offerCountEl = document.getElementById("offer-count");
const rejectionCountEl = document.getElementById("rejection-count");
const themeToggleBtn = document.getElementById("theme-toggle");
const themeIcon = document.getElementById("theme-icon");
function applyTheme(theme) {
if (theme === "dark") {
document.body.classList.add("dark");
themeIcon.textContent = "☀️";
} else {
document.body.classList.remove("dark");
themeIcon.textContent = "🌙";
}
}
const savedTheme = localStorage.getItem("theme") || "dark";
applyTheme(savedTheme);
themeToggleBtn.addEventListener("click", () => {
const isDark = document.body.classList.contains("dark");
const newTheme = isDark ? "light" : "dark";
localStorage.setItem("theme", newTheme);
applyTheme(newTheme);
});
let applications = JSON.parse(localStorage.getItem("applications")) || [];
function saveData() {
localStorage.setItem("applications", JSON.stringify(applications));
}
function updateDashboard() {
const total = applications.length;
const interviews = applications.filter(
(app) => app.stage === "Interview",
).length;
const offers = applications.filter((app) => app.stage === "Offer").length;
const rejections = applications.filter(
(app) => app.stage === "Rejected" || app.result === "Rejected",
).length;
totalCountEl.textContent = total;
interviewCountEl.textContent = interviews;
offerCountEl.textContent = offers;
rejectionCountEl.textContent = rejections;
}
function getBadgeClass(type, value) {
if (type === "stage") {
if (value === "Offer") return "badge green";
if (value === "Rejected") return "badge red";
return "badge blue";
}
if (type === "result") {
if (value === "Cleared") return "badge green";
if (value === "Rejected") return "badge red";
return "badge gray";
}
return "badge gray";
}
function renderTable() {
tableBody.innerHTML = "";
if (applications.length === 0) {
const row = document.createElement("tr");
row.innerHTML =
'<td colspan="6" class="empty">No applications found. Start tracking your journey!</td>';
tableBody.appendChild(row);
updateDashboard();
return;
}
const sortedApps = [...applications].sort(
(a, b) => new Date(b.date) - new Date(a.date),
);
sortedApps.forEach((app) => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${app.company}</td>
<td>${app.role}</td>
<td><span class="${getBadgeClass("stage", app.stage)}">${app.stage}</span></td>
<td><span class="${getBadgeClass("result", app.result)}">${
app.result
}</span></td>
<td>${new Date(app.date).toLocaleDateString()}</td>
<td class="right">
<button class="delete-btn" data-id="${app.id}">Delete</button>
</td>
`;
tableBody.appendChild(row);
});
updateDashboard();
}
tableBody.addEventListener("click", (event) => {
const button = event.target.closest(".delete-btn");
if (!button) return;
const id = Number(button.dataset.id);
const confirmDelete = confirm(
"Are you sure you want to delete this application?",
);
if (!confirmDelete) return;
applications = applications.filter((app) => app.id !== id);
saveData();
renderTable();
});
form.addEventListener("submit", (event) => {
event.preventDefault();
const newApp = {
id: Date.now(),
company: document.getElementById("company").value.trim(),
role: document.getElementById("role").value.trim(),
stage: document.getElementById("stage").value,
result: document.getElementById("result").value,
date: document.getElementById("date").value,
};
applications.push(newApp);
saveData();
renderTable();
form.reset();
document.getElementById("date").valueAsDate = new Date();
});
document.getElementById("date").valueAsDate = new Date();
renderTable();
});