@@ -402,7 +402,8 @@ document.addEventListener('DOMContentLoaded', () => {
402402 contributors = contributors . sort ( ( a , b ) => a . views - b . views )
403403 renderProfiles ( ) ;
404404 } ) ;
405- } else {
405+ }
406+ else if ( e . target . innerHTML == "Most Views" ) {
406407 fetch ( "https://raw.githubusercontent.com/recodehive/awesome-github-profiles/main/.all-contributorsrc" )
407408 . then ( ( response ) => response . json ( ) )
408409 . then ( ( data ) => {
@@ -421,6 +422,46 @@ document.addEventListener('DOMContentLoaded', () => {
421422 contributors = contributors . sort ( ( a , b ) => b . views - a . views )
422423 renderProfiles ( ) ;
423424 } ) ;
425+ } else if ( e . target . innerHTML == "Most Likes" ) {
426+ console . log ( 'sdsdsdsds' )
427+ fetch ( "https://raw.githubusercontent.com/recodehive/awesome-github-profiles/main/.all-contributorsrc" )
428+ . then ( ( response ) => response . json ( ) )
429+ . then ( ( data ) => {
430+ contributors = data . contributors ;
431+ contributors . map ( ( data ) => {
432+ const profileRef = firebase . database ( ) . ref ( `profiles/${ data . login } /likes` )
433+ profileRef . on ( "value" , ( snapshot ) => {
434+ if ( snapshot . exists ( ) ) {
435+ data [ 'likes' ] = snapshot . val ( )
436+ } else {
437+ // Handle new profile
438+ profileRef . set ( 0 ) ;
439+ }
440+ } ) ;
441+ } )
442+ contributors = contributors . sort ( ( a , b ) => b . likes - a . likes )
443+ renderProfiles ( ) ;
444+ } ) ;
445+ } else {
446+
447+ fetch ( "https://raw.githubusercontent.com/recodehive/awesome-github-profiles/main/.all-contributorsrc" )
448+ . then ( ( response ) => response . json ( ) )
449+ . then ( ( data ) => {
450+ contributors = data . contributors ;
451+ contributors . map ( ( data ) => {
452+ const profileRef = firebase . database ( ) . ref ( `profiles/${ data . login } /likes` )
453+ profileRef . on ( "value" , ( snapshot ) => {
454+ if ( snapshot . exists ( ) ) {
455+ data [ 'likes' ] = snapshot . val ( )
456+ } else {
457+ // Handle new profile
458+ profileRef . set ( 0 ) ;
459+ }
460+ } ) ;
461+ } )
462+ contributors = contributors . sort ( ( a , b ) => a . likes - b . likes )
463+ renderProfiles ( ) ;
464+ } ) ;
424465 }
425466 } )
426467 } )
0 commit comments