@@ -72,23 +72,27 @@ function addNavbarLinks() {
7272 } ) ;
7373}
7474
75- function updateFrequency ( selectedFrequency : string ) {
75+ async function updateFrequency ( selectedFrequency : string ) {
7676 // Clear the existing table
7777 const table = document . getElementById ( 'solutionTable' ) as HTMLTableElement ;
7878 while ( table . rows . length > 1 ) {
7979 table . deleteRow ( 1 ) ;
8080 }
8181
8282 // Update the frequency values in the solutions array
83- solutions . forEach ( ( solution , index ) => {
83+ const data = await new Promise < { companyProblems : any } > ( ( resolve ) => {
8484 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- }
85+ resolve ( data ) ;
8986 } ) ;
9087 } ) ;
9188
89+ const companyProblems = data . companyProblems [ companyName ] ;
90+ if ( Array . isArray ( companyProblems ) ) {
91+ solutions . forEach ( ( solution , index ) => {
92+ solution . frequency = companyProblems [ index ] [ selectedFrequency ] ;
93+ } ) ;
94+ }
95+
9296 // Rebuild the table with updated frequency values
9397 solutions . forEach ( ( solution ) => {
9498 const row = table . insertRow ( - 1 ) ;
@@ -107,7 +111,6 @@ function updateFrequency(selectedFrequency: string) {
107111 } ) ;
108112}
109113
110-
111114interface Company {
112115 name : string ;
113116}
@@ -126,19 +129,26 @@ let minFrequency = Number.MAX_SAFE_INTEGER;
126129let maxFrequency = 0 ;
127130
128131function addCompanyProblems ( sortMethod : string ) {
129- chrome . storage . local . get ( 'companyProblems' , function ( data ) {
130- // Get the problems for the selected company
132+ chrome . storage . local . get ( [ 'companyProblems' , 'leetcodeProblems' ] , function ( data ) {
131133 const companyProblems = data . companyProblems [ companyName ] ;
132- console . log ( 'companyProblems' , companyProblems ) ;
134+ const leetcodeProblems = data . leetcodeProblems . questions ;
133135
134136 // Reset max and min frequency
135137 maxFrequency = 0 ;
136138 minFrequency = Number . MAX_SAFE_INTEGER ;
139+
140+ // Check if companyProblems is an array before proceeding
137141 if ( Array . isArray ( companyProblems ) ) {
138142 companyProblems . forEach ( ( problem ) => {
139- const freq = problem . freq_alltime ;
140- if ( freq > maxFrequency ) maxFrequency = freq ;
141- if ( freq < minFrequency ) minFrequency = freq ;
143+ const correspondingLeetcodeProblem = leetcodeProblems . find ( q => q . frontend_id === problem . id ) ;
144+ solutions . push ( {
145+ id : problem . id ,
146+ title : problem . title ,
147+ url : `https://leetcode.com/problems/${ problem . title . replace ( / \s / g, '-' ) } /` ,
148+ frequency : problem . freq_alltime ,
149+ difficulty : correspondingLeetcodeProblem ?. difficulty_lvl , // Add difficulty
150+ acceptance : correspondingLeetcodeProblem ?. acceptance , // Add acceptance
151+ } ) ;
142152 } ) ;
143153 }
144154
@@ -150,7 +160,6 @@ function addCompanyProblems(sortMethod: string) {
150160 title : problem . title ,
151161 url : `https://leetcode.com/problems/${ problem . title . replace ( / \s / g, '-' ) } /` ,
152162 frequency : problem . freq_alltime ,
153- // acceptance: company.acceptance, // Adjust this as needed
154163 } ) ;
155164 } ) ;
156165 }
@@ -159,16 +168,16 @@ function addCompanyProblems(sortMethod: string) {
159168
160169 const table = document . getElementById ( 'solutionTable' ) as HTMLTableElement ;
161170
171+ // Modify table rendering to include difficulty and acceptance
162172 solutions . forEach ( solution => {
163173 const row = table . insertRow ( - 1 ) ;
164- // add id
165174 row . insertCell ( 0 ) . innerText = solution . id . toString ( ) ;
166- // add title and link to the problem
167- row . insertCell ( 1 ) . innerHTML = `<a href="${ solution . url } " target="_blank">${ solution . title } </a>` ;
168-
175+ row . insertCell ( 1 ) . innerText = solution . difficulty ?. toString ( ) || 'N/A' ; // New column for difficulty
176+ row . insertCell ( 2 ) . innerHTML = `<a href="${ solution . url } " target="_blank">${ solution . title } </a>` ;
177+ row . insertCell ( 3 ) . innerText = ( solution . acceptance ? ( solution . acceptance * 100 ) . toFixed ( 2 ) + '%' : 'N/A' ) ; // New column for acceptance
169178 // add frequency as a bar
170179 if ( solution . frequency ) {
171- const frequencyCell = row . insertCell ( 2 ) ;
180+ const frequencyCell = row . insertCell ( 4 ) ;
172181 const bar = document . createElement ( 'div' ) ;
173182 const width = ( ( solution . frequency - minFrequency ) / ( maxFrequency - minFrequency ) ) * 100 ;
174183 bar . style . width = width + '%' ;
@@ -177,6 +186,7 @@ function addCompanyProblems(sortMethod: string) {
177186 bar . style . borderRadius = '10px' ;
178187 frequencyCell . appendChild ( bar ) ;
179188 }
189+
180190 } ) ;
181191 } ) ;
182192}
@@ -278,6 +288,7 @@ function sortBy(column: string) {
278288 bar . style . height = '10px' ;
279289 bar . style . backgroundColor = 'lightgreen' ;
280290 bar . style . borderRadius = '10px' ;
291+ bar . style . border = '1px solid lightgreen' ;
281292 frequencyCell . appendChild ( bar ) ;
282293 } ) ;
283294}
0 commit comments