-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add data from API to contributors page for hacktoberfest (#431)
Relates to #404
- Loading branch information
1 parent
5066562
commit 56e12ea
Showing
15 changed files
with
325 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,57 @@ | ||
import { useContributionsList } from "lib/hooks/useContributionsList"; | ||
import useContributorData from "lib/hooks/useContributorData"; | ||
import { calcMonthsFromToday } from "lib/utils/date-utils"; | ||
import { calcDistanceFromToday } from "lib/utils/date-utils"; | ||
import ContributorCard from "../ContributorCard/contributor-card"; | ||
import color from "lib/utils/color.json"; | ||
import { useTopicContributions } from "lib/hooks/useTopicContributions"; | ||
|
||
const Contributors = (): JSX.Element =>{ | ||
const colorKeys = Object.keys(color); | ||
|
||
const Contributors = (): JSX.Element => { | ||
const contributorData = useContributorData(); | ||
const { data, isError, isLoading } = useContributionsList("769"); | ||
const { data, isError, isLoading } = useTopicContributions(); | ||
|
||
const freeCodeCamp = "freecodecamp"; | ||
|
||
const contributorArray = isError ? [] : data?.map(contributor => { | ||
const timeSinceFirstCommit = calcMonthsFromToday(new Date(parseInt(contributor.first_commit_time))); | ||
const contributorLanguageList = contributor.langs.split(","); | ||
const contributorArray = isError | ||
? [] | ||
: data?.map((contributor) => { | ||
const timeSinceFirstCommit = calcDistanceFromToday(new Date(parseInt(contributor.first_commit_time))); | ||
const contributorLanguageList = (contributor.langs || "").split(","); | ||
const repoList = (contributor.recent_repo_list || "").split(",").map((repo) => { | ||
const [repoOwner, repoName] = repo.split("/"); | ||
|
||
return { | ||
...contributorData, | ||
profile: { | ||
...contributorData.profile, | ||
githubAvatar: `https://www.github.com/${contributor.host_login}.png?size=60`, | ||
githubName: contributor.host_login, | ||
dateOfFirstPR: `${timeSinceFirstCommit}${timeSinceFirstCommit !== 1 ? "mos" : "mo"}` | ||
}, | ||
languageList: contributorLanguageList.map(language => { | ||
const preparedLanguageKey = Object.keys(color).find(key => key.toLowerCase() === language.toLowerCase()); | ||
return { | ||
repoName, | ||
repoIcon: `https://www.github.com/${repoOwner ?? "github"}.png?size=460` | ||
}; | ||
}); | ||
const languageList = contributorLanguageList.map((language) => { | ||
const preparedLanguageKey = colorKeys.find((key) => key.toLowerCase() === language.toLowerCase()); | ||
|
||
return { | ||
languageName: preparedLanguageKey ? preparedLanguageKey : language, | ||
percentageUsed: Math.round( ( 1 / contributorLanguageList.length ) * 100) | ||
percentageUsed: Math.round((1 / contributorLanguageList.length) * 100) | ||
}; | ||
}), | ||
repoList: [ | ||
{ | ||
repoName: freeCodeCamp, | ||
repoIcon: `https://www.github.com/${freeCodeCamp ?? "github"}.png?size=460` | ||
} | ||
] | ||
}; | ||
}); | ||
}); | ||
|
||
return { | ||
...contributorData, | ||
profile: { | ||
...contributorData.profile, | ||
githubAvatar: `https://www.github.com/${contributor.host_login}.png?size=60`, | ||
githubName: contributor.host_login, | ||
dateOfFirstPR: timeSinceFirstCommit | ||
}, | ||
languageList, | ||
repoList | ||
}; | ||
}); | ||
|
||
return ( | ||
<div className="w-full grid grid-cols-automobile md:grid-cols-autodesktop gap-3"> | ||
{isLoading ? "Loading..." : ""} | ||
{ | ||
contributorArray.map((contributor, index) => ( | ||
<ContributorCard key={index} className="" contributor={{ ...contributor }} /> | ||
)) | ||
} | ||
{contributorArray.map((contributor, index) => ( | ||
<ContributorCard key={index} className="" contributor={{ ...contributor }} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
export default Contributors; | ||
export default Contributors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface CommitGraphData { | ||
x: number, | ||
y: number; | ||
} |
Oops, something went wrong.