Skip to content

Commit

Permalink
Fixed skills progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
aish2002 committed Sep 6, 2021
1 parent a3ad002 commit a33051f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ const getRepos = async (nam) => {
}
};

export { getUsers, getRepos, getOrgs, sortByStar };
const maxPercent=(skills)=>{
return Math.max.apply(Math, skills.map(function(o) { return o.percent; }))
}
export { getUsers, getRepos, getOrgs, sortByStar,maxPercent };
7 changes: 4 additions & 3 deletions src/components/Languages/Language.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react'
import { Col, ProgressBar, Row } from 'react-bootstrap'
import { usePercent } from '../../hooks/usePercent'

import {maxPercent} from '../../api/index'
const Language = ({ id }) => {
const {skills,total,max} = usePercent(id);
const {skills,total} = usePercent(id);

return (
<Col>
Expand All @@ -15,7 +15,8 @@ const Language = ({ id }) => {
{/* <img src={`/${skill}.svg`} alt="skill-badge"/> */}
<ProgressBar
now={Math.round(skills[key].percent*100/total) }
max={max*100/total}/>
max={Math.round(maxPercent(skills)*100/total)}/>
{/* max={Math.round(max*100/total)}/> */}
</Col>
))}
</Row>
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/usePercent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import axios from 'axios'
export const usePercent = (id) => {
const [total, setTotal] = useState(0)
const [skills, setSkills] = useState([])
const [max,setMax] = useState(0)

useEffect(() => {
getRepos(id).then(repos => {
Expand All @@ -25,10 +24,10 @@ export const usePercent = (id) => {
});
}
});

setSkills(languages)
setMax(Math.max.apply(Math, skills.map(function(o) { return o.percent; })))

}).catch(err => console.log(err));
}, [id,skills])
return {skills,total,max}
}, [id])
return {skills,total}
}

0 comments on commit a33051f

Please sign in to comment.