Skip to content

Commit 9758406

Browse files
committed
show dropdown list ofall companies
1 parent e8cdfe7 commit 9758406

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/problems-by-company/company.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<body>
1010
<nav id="navbar">
1111
</nav>
12+
<select id="companySelect"></select>
1213
<h1 id="title">Amazon</h1>
1314
<p>
1415
<span id="score">Score</span> = How likely the company is to ask this question in an interview on a scale of

src/problems-by-company/company.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const companies = [
55
'Adobe', 'Apple', 'Bloomberg', 'Cisco', 'Facebook', 'Google', 'Microsoft', 'Spotify'
66
];
77

8-
function main() {
8+
async function main() {
99
chrome.storage.local.get('clickedCompany', function (data: { [key: string]: any; }) {
1010
companyName = data.clickedCompany;
1111
const title: HTMLElement | null = document.getElementById('title');
@@ -19,6 +19,7 @@ function main() {
1919
document.getElementById('Score')?.addEventListener('click', () => sortBy('Score'));
2020

2121
addNavbarLinks();
22+
await addCompaniesToSelect();
2223
}
2324

2425
function addNavbarLinks() {
@@ -61,11 +62,10 @@ function addNavbarLinks() {
6162
button.appendChild(companyName);
6263

6364
navbar?.appendChild(button);
65+
6466
});
6567
}
6668

67-
68-
6969
interface Company {
7070
name: string;
7171
score: number;
@@ -127,6 +127,39 @@ function addCompanyProblems(sortMethod: string) {
127127
});
128128
}
129129

130+
async function addCompaniesToSelect() {
131+
const companySelect = document.getElementById('companySelect') as HTMLSelectElement;
132+
133+
let uniqueCompanies = new Set<string>();
134+
135+
const data = await new Promise<{ leetcodeProblems: LeetcodeProblems }>(resolve => {
136+
chrome.storage.local.get('leetcodeProblems', function (items: { [key: string]: any; }) {
137+
resolve(items as { leetcodeProblems: LeetcodeProblems });
138+
});
139+
});
140+
141+
data.leetcodeProblems.questions.forEach((question: Question) => {
142+
if (question.companies) {
143+
question.companies.forEach((company: Company) => {
144+
uniqueCompanies.add(company.name);
145+
});
146+
}
147+
});
148+
149+
uniqueCompanies.forEach((company) => {
150+
const option = document.createElement('option');
151+
option.value = company;
152+
option.text = company;
153+
companySelect.appendChild(option);
154+
});
155+
156+
companySelect.addEventListener('change', () => {
157+
chrome.storage.local.set({ clickedCompany: companySelect.value }, () => {
158+
location.reload();
159+
});
160+
});
161+
}
162+
130163
function sortBy(column: string) {
131164
if (column === 'Score') {
132165
solutions.sort((a, b) => b.score - a.score);

0 commit comments

Comments
 (0)