Skip to content

Commit

Permalink
Merge pull request #261 from Asymtode712/Feat
Browse files Browse the repository at this point in the history
Added profile filtering based on likes
  • Loading branch information
sanjay-kv authored Aug 9, 2024
2 parents c4b5039 + dc89db2 commit 049078b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ <h1 class="main-heading">Awesome GitHub Profile READMEs</h1>
<div class="modal-content">
<p class="views">Least Views</p>
<p class="views">Most Views</p>
<p class="likes">Least Likes</p>
<p class="likes">Most Likes</p>
</div>
</div>

Expand Down
63 changes: 63 additions & 0 deletions scripts/retriveprofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ function renderProfiles(filter = "") {
viewCount.className = "view-count";
viewCount.innerHTML = '<i class="fa fa-eye"></i> Views: Loading...'; // Placeholder text

const likeCount = document.createElement("p");
likeCount.className = "like-count";
likeCount.innerHTML = '<i class="fa fa-heart"></i> Likes: Loading...';

// Retrieve and listen to view count from Firebase
const profileRef = firebase.database().ref(`profiles/${contributor.login}/views`);
profileRef.on("value", (snapshot) => {
Expand All @@ -277,6 +281,17 @@ function renderProfiles(filter = "") {
}
});

// Retrieve and listen to like count from Firebase
const profileRefLikes = firebase.database().ref(`profiles/${contributor.login}/likes`);
profileRefLikes.on("value", (snapshot) => {
if (snapshot.exists()) {
likeCount.innerHTML = `<i class="fa fa-heart"></i> Likes: ${snapshot.val()}`;
} else {
profileRefLikes.set(0);
likeCount.innerHTML = '<i class="fa fa-heart"></i> Likes: 0';
}
});

// Increment view count on click
card.addEventListener("click", (e) => {
e.preventDefault();
Expand All @@ -290,6 +305,7 @@ function renderProfiles(filter = "") {
card.appendChild(imgContainer);
card.appendChild(name);
card.appendChild(viewCount);
card.appendChild(likeCount);
card.classList.add("profile-card");

container.appendChild(card);
Expand All @@ -304,6 +320,7 @@ document.addEventListener('DOMContentLoaded', () => {
const caretDown = document.getElementById('caret-down');
const closeButton = document.getElementById('close-button');
const views = document.getElementsByClassName('views');
const likes = document.getElementsByClassName('likes');


Array.from(views).map((ele)=>{
Expand Down Expand Up @@ -351,6 +368,52 @@ document.addEventListener('DOMContentLoaded', () => {
}
})
})

Array.from(likes).map((ele)=>{
ele.addEventListener(('click'),(e)=>{
close()
if(e.target.innerHTML=="Least Likes"){

fetch("https://raw.githubusercontent.com/recodehive/awesome-github-profiles/main/.all-contributorsrc")
.then((response) => response.json())
.then((data) => {
contributors = data.contributors;
contributors.map((data)=>{
const profileRefLikes = firebase.database().ref(`profiles/${data.login}/likes`)
profileRefLikes.on("value", (snapshot) => {
if (snapshot.exists()) {
data['likes']=snapshot.val()
} else {
profileRefLikes.set(0);
}
});
})
contributors=contributors.sort((a,b)=>a.likes-b.likes)
renderProfiles();
});
}else{
fetch("https://raw.githubusercontent.com/recodehive/awesome-github-profiles/main/.all-contributorsrc")
.then((response) => response.json())
.then((data) => {
contributors = data.contributors;
contributors.map((data)=>{
const profileRefLikes = firebase.database().ref(`profiles/${data.login}/likes`)
profileRefLikes.on("value", (snapshot) => {
if (snapshot.exists()) {
data['likes']=snapshot.val()
} else {
// Handle new profile
profileRefLikes.set(0);
}
});
})
contributors=contributors.sort((a,b)=>b.likes-a.likes)
renderProfiles();
});
}
})
})

caretDown.addEventListener('click', (event) => {
if(modal.style.display=="block"){
modal.style.display="none"
Expand Down

0 comments on commit 049078b

Please sign in to comment.