-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add dashboard and menu(hidden)
- Loading branch information
Showing
6 changed files
with
351 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
async function getAllEvents(username) { | ||
const oneMonthAgo = new Date(); | ||
oneMonthAgo.setDate(oneMonthAgo.getDate() - 30); | ||
let page = 1; | ||
let events = []; | ||
|
||
while (true) { | ||
const url = `https://api.github.com/users/${username}/events/public?per_page=100&page=${page}`; | ||
|
||
try { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
|
||
if (data.length === 0) { | ||
break; | ||
} | ||
|
||
events = events.concat(data.filter(event => { | ||
const eventDate = new Date(event.created_at); | ||
return eventDate > oneMonthAgo; | ||
})); | ||
|
||
page++; | ||
} catch (error) { | ||
console.error(error); | ||
return 'Error'; | ||
} | ||
} | ||
|
||
console.log(events); | ||
|
||
return events; | ||
} | ||
|
||
async function getCommits(events) { | ||
let commitCount = 0; | ||
|
||
const commits = events.filter(event => event.type === 'PushEvent'); | ||
|
||
commits.forEach(commit => { | ||
commitCount += commit.payload.size; | ||
}); | ||
|
||
return commitCount; | ||
} | ||
|
||
async function getPullRequests(events) { | ||
let pullRequestCount = 0; | ||
|
||
const pullRequests = events.filter(event => event.type === 'PullRequestEvent'); | ||
|
||
pullRequestCount += pullRequests.length; | ||
|
||
return pullRequestCount; | ||
} | ||
|
||
async function getIssues(events) { | ||
let issueCount = 0; | ||
|
||
const issues = events.filter(event => event.type === 'IssuesEvent' || event.type === 'IssueCommentEvent'); | ||
|
||
issueCount += issues.length; | ||
|
||
return issueCount; | ||
} | ||
|
||
async function getFollowers(username) { | ||
const url = `https://api.github.com/users/${username}`; | ||
|
||
try { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
|
||
return data.followers; | ||
} catch (error) { | ||
console.error(error); | ||
return 'Error'; | ||
} | ||
} | ||
|
||
async function getAllRepos(username) { | ||
const url = `https://api.github.com/users/${username}/repos`; | ||
|
||
try { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
|
||
return data; | ||
} catch (error) { | ||
console.error(error); | ||
return 'Error'; | ||
} | ||
} | ||
|
||
async function getTotalStars(repos) { | ||
let totalStars = 0; | ||
repos.forEach(repo => { | ||
totalStars += repo.stargazers_count; | ||
}); | ||
|
||
return totalStars; | ||
} | ||
|
||
async function getTotalForks(repos) { | ||
let totalForks = 0; | ||
repos.forEach(repo => { | ||
totalForks += repo.forks_count; | ||
}); | ||
|
||
return totalForks; | ||
} | ||
|
||
const username = 'WCY-dt'; | ||
|
||
const commit = document.querySelector('#commit number'); | ||
const pullRequest = document.querySelector('#pr number'); | ||
const issue = document.querySelector('#issue number'); | ||
|
||
getAllEvents(username).then(events => { | ||
getCommits(events).then(commitCount => { | ||
commit.textContent = commitCount; | ||
}); | ||
|
||
getPullRequests(events).then(pullRequestCount => { | ||
pullRequest.textContent = pullRequestCount; | ||
}); | ||
|
||
getIssues(events).then(issueCount => { | ||
issue.textContent = issueCount; | ||
}); | ||
}) | ||
|
||
const follower = document.querySelector('#follower number'); | ||
getFollowers(username).then(followerCount => { | ||
follower.textContent = followerCount; | ||
}); | ||
|
||
|
||
const star = document.querySelector('#star number'); | ||
const fork = document.querySelector('#fork number'); | ||
getAllRepos(username).then(repos => { | ||
getTotalStars(repos).then(starCount => { | ||
star.textContent = starCount; | ||
}); | ||
|
||
getTotalForks(repos).then(forkCount => { | ||
fork.textContent = forkCount; | ||
}); | ||
}); | ||
|
||
|
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,12 @@ | ||
window.addEventListener('scroll', function() { | ||
var menuItems = document.querySelectorAll('#menu a'); | ||
menuItems.forEach(function(menuItem) { | ||
var targetElement = document.querySelector(menuItem.getAttribute('href')); | ||
var rect = targetElement.getBoundingClientRect(); | ||
if (rect.top <= 0 && rect.bottom >= 0) { | ||
menuItem.parentElement.classList.add('active'); | ||
} else { | ||
menuItem.parentElement.classList.remove('active'); | ||
} | ||
}); | ||
}); |
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,69 @@ | ||
.dashboard { | ||
width: 100%; | ||
} | ||
|
||
.dashboard-content { | ||
width: calc(100% - 8rem); | ||
background-color: var(--primary-color); | ||
display: grid; | ||
grid-template-columns: repeat(3, auto); | ||
gap: 1rem; | ||
padding: 4rem; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.dashboard-item { | ||
position: relative; | ||
background-color: var(--white-color); | ||
color: var(--black-color); | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
grid-template-rows: 1fr auto; | ||
gap: 1rem; | ||
width: 15rem; | ||
padding: 2rem; | ||
box-shadow: 0 0 1rem var(--black-shadow-primary-color); | ||
transition: transform 0.25s ease-in-out, box-shadow 0.25s ease-in-out; | ||
} | ||
|
||
.dashboard-item:hover { | ||
transform: translateY(-0.25rem); | ||
box-shadow: 0 0 2rem var(--black-shadow-secondary-color); | ||
} | ||
|
||
.dashboard-item .icon { | ||
position: absolute; | ||
top: 0.5rem; | ||
right: 0.5rem; | ||
font-size: 9rem; | ||
color: var(--tertiary-color); | ||
} | ||
|
||
.dashboard-item number { | ||
font-size: 5rem; | ||
line-height: 4rem; | ||
font-weight: 900; | ||
letter-spacing: 0.5rem; | ||
font-family: var(--primary-font); | ||
text-transform: uppercase; | ||
margin: 0; | ||
z-index: 10; | ||
} | ||
|
||
.dashboard-item .dashboard-text { | ||
font-size: 1.2rem; | ||
margin: 0; | ||
z-index: 10; | ||
} | ||
|
||
@media screen and (max-width: 768px) { | ||
.dashboard-content { | ||
grid-template-columns: auto auto; | ||
} | ||
|
||
.dashboard-item { | ||
width: 12rem; | ||
height: 9rem; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
.menu { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
position: fixed; | ||
top: 0; | ||
left: 50%; | ||
transform: translateX(-50%) translateY(-3rem); | ||
margin: 0; | ||
padding: 0.75rem 1rem 0.25rem 1rem; | ||
background-color: var(--primary-color); | ||
box-shadow: 0 0 0.5rem var(--black-shadow-primary-color), 0 0 2rem var(--black-shadow-secondary-color); | ||
opacity: 0.5; | ||
transition: transform 0.25s ease-in-out, opacity 0.25s ease-in-out; | ||
} | ||
|
||
.menu:hover { | ||
transform: translateX(-50%) translateY(0); | ||
opacity: 1; | ||
} | ||
|
||
.menu ul { | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 1rem; | ||
height: 100%; | ||
} | ||
|
||
.menu ul li { | ||
width: 2rem; | ||
height: 2rem; | ||
} | ||
|
||
|
||
|
||
.menu ul li a { | ||
display: block; | ||
width: 2rem; | ||
height: 2rem; | ||
background-color: var(--white-color); | ||
transform: scale(0.75); | ||
transition: background-color 0.25s ease-in-out, transform 0.25s ease-in-out; | ||
} | ||
|
||
.menu ul li.active a { | ||
background-color: var(--secondary-color); | ||
transform: scale(1); | ||
} | ||
|
||
.menu hr { | ||
width: 40%; | ||
height: 0.1rem; | ||
background-color: var(--white-color); | ||
margin: 0.5rem 0 0 0; | ||
} |
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