Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 25 gh projects imptovement infer tech from language and topics #94

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e1a4a7a
fetch project languages
nkapolcs Mar 2, 2020
915b0b5
Merge branch 'master' of github.com:c-hive/c-hive.dev into issue-25_g…
nkapolcs Mar 9, 2020
1078cb4
display repo languages
nkapolcs Mar 9, 2020
a937a92
cleanup css in projectDisplayer
nkapolcs Mar 9, 2020
35c0159
create settings for languages threshold
nkapolcs Mar 11, 2020
9741710
conditional check in projectDisplayer
nkapolcs Mar 11, 2020
788ca75
use reduce to count charNumber
nkapolcs Mar 16, 2020
4e8ac12
make the logic more reactish
nkapolcs Mar 18, 2020
a72c1f4
update projectDisplayer component
nkapolcs Mar 18, 2020
beb8656
update projectDisplayer display logic
nkapolcs Mar 18, 2020
a32c987
delete languageThreshold prop from project component
nkapolcs Mar 18, 2020
6c3e786
add languageThreshold documentation
nkapolcs Mar 19, 2020
2062a94
add languageThreshold documentation
nkapolcs Mar 19, 2020
476fd0d
fix documentation typo
nkapolcs Mar 21, 2020
4df639d
more meaningful variable names, delete eslint disabled no-shadow
nkapolcs Mar 21, 2020
8402246
simplify useEffect logic
nkapolcs Mar 21, 2020
3f51bff
simplify useEffect condition
nkapolcs Mar 21, 2020
2639e6c
handle githubRepoLanguages error case
nkapolcs Mar 21, 2020
8dd1607
handle githubRepoLanguages error case
nkapolcs Mar 21, 2020
c628e39
handle githubRepoLanguages error case
nkapolcs Mar 21, 2020
da79d0d
create defaultThreshold variable
nkapolcs Mar 22, 2020
11cd8cc
merge master
nkapolcs Mar 25, 2020
16bfa15
create useGithubFetch hook
nkapolcs Mar 25, 2020
7c1438d
update documentation
nkapolcs Mar 25, 2020
8be54ef
use filter(), more meaningful variable names
nkapolcs Mar 25, 2020
f2e5765
rename hook to useRepoLanguages
nkapolcs Mar 25, 2020
0d74fcc
use only filter in useRepoLanguages
nkapolcs Mar 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions src/components/Projects/ProjectDisplayer/ProjectDisplayer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from "react";
import styled from "styled-components";
import { projectDisplayerStyle } from "./ProjectDisplayer.style";
import {
projectDisplayerStyle,
repositoryLanguagesStyle,
} from "./ProjectDisplayer.style";
import * as customHooks from "../../../utils/CustomHooks/CustomHooks";
import * as githubUtils from "../utils/GithubUtils";
import Loader from "../../UI/Loader/Loader";
Expand All @@ -9,15 +12,24 @@ import StarIcon from "../../UI/Icons/StarIcon";
const ProjectDisplayer = styled.div`
${projectDisplayerStyle}
`;
const RepositoryLanguages = styled.div`
${repositoryLanguagesStyle}
`;

const projectDisplayer = ({ userName, repoName }) => {
const projectDisplayer = ({ userName, repoName, languageThreshold }) => {
nkapolcs marked this conversation as resolved.
Show resolved Hide resolved
const githubFetchState = customHooks.useFetch(
githubUtils.fetchRepo,
userName,
repoName
);

if (githubFetchState.isLoading) {
const githubRepoLanguages = customHooks.useFetch(
githubUtils.fetchRepoLanguages,
userName,
repoName
);

if (githubFetchState.isLoading || githubRepoLanguages.isLoading) {
return (
<ProjectDisplayer>
<Loader />
Expand All @@ -32,6 +44,18 @@ const projectDisplayer = ({ userName, repoName }) => {
return <div>{errorMessage}</div>;
}

if (!githubRepoLanguages.isLoading) {
nkapolcs marked this conversation as resolved.
Show resolved Hide resolved
let sum = 0;

Object.keys(githubRepoLanguages.data).forEach(item => {
// console.log(item); // key
nkapolcs marked this conversation as resolved.
Show resolved Hide resolved
// console.log(githubRepoLanguages.data[item]); // value
sum += githubRepoLanguages.data[item];
});

githubRepoLanguages.sum = sum;
nkapolcs marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<ProjectDisplayer>
<a
Expand All @@ -52,6 +76,17 @@ const projectDisplayer = ({ userName, repoName }) => {
<div className="project_description">
<div>{githubFetchState.data.description}</div>
</div>
<RepositoryLanguages>
{Object.keys(githubRepoLanguages.data).map(item => {
nkapolcs marked this conversation as resolved.
Show resolved Hide resolved
if (
githubRepoLanguages.data[item] / githubRepoLanguages.sum >
thisismydesign marked this conversation as resolved.
Show resolved Hide resolved
(languageThreshold || 10) / 100
) {
return <div key={item}>{item}</div>;
}
return null;
nkapolcs marked this conversation as resolved.
Show resolved Hide resolved
})}
</RepositoryLanguages>
</a>
</ProjectDisplayer>
);
Expand Down
24 changes: 24 additions & 0 deletions src/components/Projects/ProjectDisplayer/ProjectDisplayer.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,27 @@ export const projectDisplayerStyle = css`
}
}
`;

export const repositoryLanguagesStyle = css`
margin: 4px 2px;

div {
display: inline-block;
margin: 3px 9px 3px 0;
padding: 0.4em 1em;
background-color: rgba(247, 176, 84, 1);
font-size: 0.8em;
font-weight: 700;
line-height: 1;
text-align: center;
text-decoration: none;
color: #325359;
white-space: nowrap;
border-radius: 0.25rem;
transition: 0.3s;

&:hover {
text-decoration: underline;
}
}
`;
1 change: 1 addition & 0 deletions src/components/Projects/Projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const projects = () => {
key={repo}
userName={settings.github.name}
repoName={repo}
languageThreshold={settings.github.languageThreshold}
/>
))}
</Projects>
Expand Down
10 changes: 10 additions & 0 deletions src/components/Projects/utils/GithubUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ export const fetchRepo = (userName, repositoryName) => {
},
}).then(fetchedProjectDetails => fetchedProjectDetails.json());
};

export const fetchRepoLanguages = (userName, repositoryName) => {
nkapolcs marked this conversation as resolved.
Show resolved Hide resolved
const url = `https://api.github.com/repos/${userName}/${repositoryName}/languages`;

return fetch(url, {
headers: {
Accept: "application/vnd.github.baptiste-preview+json",
},
}).then(fetchedProjectLanguages => fetchedProjectLanguages.json());
};