Skip to content

Commit 7bfdae0

Browse files
committed
implement 6month, 1year, 2 year dropdowns
1 parent 16af8de commit 7bfdae0

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

src/problems-by-company/company.ts

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const solutions = [] as { id: number, title: string, score: number, url: string }[];
1+
const solutions = [] as { id: number, title: string, url: string }[];
22

33
let companyName = 'Amazon';
44
const companies = [
@@ -16,9 +16,13 @@ async function main() {
1616

1717
document.getElementById('#')?.addEventListener('click', () => sortBy('#'));
1818
document.getElementById('Title')?.addEventListener('click', () => sortBy('Title'));
19-
document.getElementById('Score')?.addEventListener('click', () => sortBy('Score'));
2019
document.getElementById('Difficulty')?.addEventListener('click', () => sortBy('Difficulty'));
2120
document.getElementById('Frequency')?.addEventListener('click', () => sortBy('Frequency'));
21+
document.getElementById('dateSelect')?.addEventListener('change', (event) => {
22+
const selectedFrequency = (event.target as HTMLSelectElement).value;
23+
updateFrequency(selectedFrequency);
24+
});
25+
2226

2327
addNavbarLinks();
2428
await addCompaniesToSelect();
@@ -68,9 +72,44 @@ function addNavbarLinks() {
6872
});
6973
}
7074

75+
function updateFrequency(selectedFrequency: string) {
76+
// Clear the existing table
77+
const table = document.getElementById('solutionTable') as HTMLTableElement;
78+
while (table.rows.length > 1) {
79+
table.deleteRow(1);
80+
}
81+
82+
// Update the frequency values in the solutions array
83+
solutions.forEach((solution, index) => {
84+
chrome.storage.local.get('companyProblems', function (data) {
85+
const companyProblems = data.companyProblems[companyName];
86+
if (Array.isArray(companyProblems)) {
87+
solution.frequency = companyProblems[index][selectedFrequency];
88+
}
89+
});
90+
});
91+
92+
// Rebuild the table with updated frequency values
93+
solutions.forEach((solution) => {
94+
const row = table.insertRow(-1);
95+
row.insertCell(0).innerText = solution.id.toString();
96+
row.insertCell(1).innerHTML = `<a href="${solution.url}" target="_blank">${solution.title}</a>`;
97+
98+
// Add frequency as a bar
99+
const frequencyCell = row.insertCell(2);
100+
const bar = document.createElement('div');
101+
const width = ((solution.frequency - minFrequency) / (maxFrequency - minFrequency)) * 100;
102+
bar.style.width = width + '%';
103+
bar.style.height = '10px';
104+
bar.style.backgroundColor = 'lightgreen';
105+
bar.style.borderRadius = '10px';
106+
frequencyCell.appendChild(bar);
107+
});
108+
}
109+
110+
71111
interface Company {
72112
name: string;
73-
score: number;
74113
}
75114

76115
interface Question {
@@ -109,7 +148,6 @@ function addCompanyProblems(sortMethod: string) {
109148
solutions.push({
110149
id: problem.id,
111150
title: problem.title,
112-
// score: company.score, // Adjust this as needed
113151
url: `https://leetcode.com/problems/${problem.title.replace(/\s/g, '-')}/`,
114152
frequency: problem.freq_alltime,
115153
// acceptance: company.acceptance, // Adjust this as needed
@@ -121,10 +159,6 @@ function addCompanyProblems(sortMethod: string) {
121159

122160
const table = document.getElementById('solutionTable') as HTMLTableElement;
123161

124-
if (sortMethod === 'Score') {
125-
solutions.sort((a, b) => b.score - a.score);
126-
}
127-
128162
solutions.forEach(solution => {
129163
const row = table.insertRow(-1);
130164
// add id
@@ -143,40 +177,6 @@ function addCompanyProblems(sortMethod: string) {
143177
bar.style.borderRadius = '10px';
144178
frequencyCell.appendChild(bar);
145179
}
146-
147-
// add difficulty
148-
// const difficultyCell = row.insertCell(1);
149-
// let innerText = '';
150-
// if (solution.difficulty === 1) {
151-
// innerText = 'Easy';
152-
// }
153-
// else if (solution.difficulty === 2) {
154-
// innerText = 'Medium';
155-
// }
156-
// else if (solution.difficulty === 3) {
157-
// innerText = 'Hard';
158-
// }
159-
// difficultyCell.innerText = innerText;
160-
// difficultyCell.style.color = color;
161-
162-
163-
// add score
164-
// const scoreCell = row.insertCell(2);
165-
// scoreCell.innerText = solution.score.toString();
166-
167-
// add acceptance
168-
// if (solution.acceptance) {
169-
// const acceptanceCell = row.insertCell(5);
170-
// acceptanceCell.innerText = solution.acceptance.toString();
171-
// acceptanceCell.style.color = color;
172-
// }
173-
174-
// add frequency
175-
// if (solution.frequency) {
176-
// const frequencyCell = row.insertCell(4);
177-
// frequencyCell.innerText = solution.frequency.toString();
178-
// frequencyCell.style.color = color;
179-
// }
180180
});
181181
});
182182
}
@@ -225,7 +225,6 @@ async function addCompaniesToSelect() {
225225
const sortOrders = {
226226
'#': false,
227227
'Title': false,
228-
'Score': false,
229228
'Frequency': false,
230229
};
231230

0 commit comments

Comments
 (0)