Skip to content

Commit b9c6b50

Browse files
committed
readd addcompaniestoselect function
1 parent 858397a commit b9c6b50

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/problems-by-company/company.ts

+50-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ let minFrequency = Number.MAX_SAFE_INTEGER;
9292
let maxFrequency = 0;
9393

9494

95-
9695
async function updateFrequency(selectedFrequency: string) {
9796
// Clear the existing table
9897
const table = document.getElementById('solutionTable') as HTMLTableElement;
@@ -237,6 +236,56 @@ function rebuildTable() {
237236
});
238237
}
239238

239+
async function addCompaniesToSelect() {
240+
const companySearch = document.getElementById('companySearch') as HTMLInputElement;
241+
const companyList = document.getElementById('companyList') as HTMLDataListElement;
242+
let companies = [];
243+
244+
const data = await new Promise<{ companyProblems: any }>((resolve) => {
245+
chrome.storage.local.get('companyProblems', function (data) {
246+
resolve(data);
247+
});
248+
});
249+
250+
const companyProblems = data.companyProblems;
251+
// Add all the keys to the set
252+
Object.keys(companyProblems).forEach((company) => {
253+
if (company) {
254+
companies.push(company);
255+
}
256+
});
257+
258+
// Event when the "Enter" key is pressed or an option is selected from the dropdown
259+
const handleSelection = () => {
260+
const inputValue = companySearch.value;
261+
// Find the selected company in a case-insensitive manner
262+
const selectedCompany = Array.from(companies).find(
263+
(company) => company.toLowerCase() === inputValue.toLowerCase()
264+
);
265+
if (selectedCompany) {
266+
chrome.storage.local.set({ clickedCompany: selectedCompany }, () => {
267+
location.reload();
268+
});
269+
}
270+
};
271+
272+
companySearch.addEventListener('keydown', (event) => {
273+
if (event.key === 'Enter') {
274+
handleSelection();
275+
}
276+
});
277+
278+
companySearch.addEventListener('change', handleSelection);
279+
280+
const sortedCompanies = companies.sort();
281+
282+
sortedCompanies.forEach((company) => {
283+
const option = document.createElement('option');
284+
option.value = company;
285+
companyList.appendChild(option);
286+
});
287+
}
288+
240289

241290
// Keep track of the sorting order for each column
242291
const sortOrders = {

0 commit comments

Comments
 (0)