Skip to content

Commit

Permalink
refactor of code has been done
Browse files Browse the repository at this point in the history
  • Loading branch information
gulshanyadav01 committed Aug 2, 2021
1 parent bbb8101 commit b8d962a
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/components/Repos.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
import React from 'react'

import Pie from "./Charts/pie"

import Column from "./Charts/Column"

import { GithubContext } from "../Context/Context";

import Doughnut from "./Charts/Doughnut"

import Bar from "./Charts/Bar";


const Repos = () => {

const {repos } = React.useContext( GithubContext );

const languages = repos.reduce((total, item) =>{

const {language, stargazers_count } = item;

if(!language) return total;

if(!total[language]){

total[language] = {

label: language, value:1,

stars: stargazers_count

};

}
else{
total[language] = {...total[language], value:total[language].value + 1,

stars: total[language].stars + stargazers_count,

};
}
return total;
Expand All @@ -29,16 +45,21 @@ const Repos = () => {


const mostUsed = Object.values(languages).sort((a, b) =>{

return b.value - a.value

}).slice(0,5)

// most start per lange


const mostPopular = Object.values(languages).sort((a,b) =>{
return b.stars - a.stars;
}).map((item) =>{

}).map((item) => {

return {...item, value:item.stars}

});


Expand All @@ -47,17 +68,21 @@ const Repos = () => {
let {stars, forks } = repos.reduce((total, item) =>{

const {stargazers_count, name , forks} = item;

total.stars[stargazers_count] = {label:name, value: stargazers_count};

total.forks[forks] = {label:name, value:forks}

return total;
},
{
stars:{},

forks:{},
});

stars = Object.values(stars).slice(-5).reverse();

forks = Object.values(forks).slice(-5).reverse();

return (
Expand Down Expand Up @@ -85,4 +110,4 @@ const Repos = () => {
)
}

export default Repos;
export default Repos

0 comments on commit b8d962a

Please sign in to comment.