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

Fixed profile diff loading issue #869

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions profile-diff-details/assets/default-profile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions profile-diff-details/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async function setUser(profileDiff) {
type: 'img',
attributes: {
class: 'user_image',
src: user.picture.url,
src: user.picture?.url || 'assets/default-profile.svg',
height: '71px',
width: '71px',
},
Expand All @@ -135,7 +135,7 @@ async function setUser(profileDiff) {
class: 'user_name',
},
});
username.innerHTML = `${user.first_name} ${user.last_name}`;
username.innerHTML = `${user.first_name || ''} ${user.last_name || ''}`;
CONTAINER.appendChild(username);

const expandControlContainer = createElement({
Expand Down
50 changes: 34 additions & 16 deletions profile-diffs/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,18 @@ async function populateProfileDiffs(query = {}, newLink) {
});
}
profileDiffsElement.appendChild(profileDiffsListElement);
for (let data of allProfileDiffs) {
await createProfileDiffCard(data, profileDiffsListElement);
}

// Create all profile diff cards with shimmer effect
allProfileDiffs.forEach((data) => {
const card = createProfileDiffCard(data);
profileDiffsListElement.appendChild(card);
});

// Fetch user details and update cards
allProfileDiffs.forEach(async (data) => {
const user = await getUser(data.userId);
updateProfileDiffCard(data.id, user);
});
} catch (error) {
showToast({ type: 'error', message: 'Something went wrong!' });
} finally {
Expand Down Expand Up @@ -177,7 +186,7 @@ function debounce(func, delay) {
};
}

async function createProfileDiffCard(data, profileDiffCardList) {
function createProfileDiffCard(data) {
const time = data.timestamp;
const fireBaseTime = new Date(
time._seconds * 1000 + time._nanoseconds / 1000000,
Expand All @@ -195,15 +204,14 @@ async function createProfileDiffCard(data, profileDiffCardList) {

const profileCard = createElement({
type: 'div',
attributes: { class: 'profile-card' },
attributes: { class: 'profile-card', 'data-id': data.id },
});
if (filterStates.status === Status.PENDING) {
profileCard.style.cursor = 'pointer';
profileCard.addEventListener('click', () => {
window.location.href = `/profile-diff-details/?id=${data.id}`;
});
}
profileDiffCardList.appendChild(profileCard);

const profileCardLeft = createElement({
type: 'div',
Expand Down Expand Up @@ -251,19 +259,29 @@ async function createProfileDiffCard(data, profileDiffCardList) {
profileCard.appendChild(profileCardLeft);
profileCard.appendChild(profileCardRight);

const user = await getUser(data.userId);
profileCardLeft.classList.remove('shimmer');
return profileCard;
}

function updateProfileDiffCard(cardId, user) {
const card = document.querySelector(`.profile-card[data-id="${cardId}"]`);
if (!card) return;

const profileLeft = card.querySelector('.profile');
const profilePic = card.querySelector('.profile-pic');
const profileName = card.querySelector('.profile-name-shimmer');
const profileUsername = card.querySelector('.profile-username-shimmer');

profileCardPhoto.style.backgroundImage = `url(${user.picture?.url})`;
profileCardPhoto.style.backgroundSize = 'cover';
profileLeft.classList.remove('shimmer');
profilePic.style.backgroundImage = `url(${user.picture?.url})`;
profilePic.style.backgroundSize = 'cover';

profileCardName.classList.remove('profile-name-shimmer');
profileCardName.classList.add('profile-name');
profileCardName.textContent = `${user.first_name} ${user.last_name}`;
profileName.classList.remove('profile-name-shimmer');
profileName.classList.add('profile-name');
profileName.textContent = `${user.first_name} ${user.last_name}`;

profileCardUsername.classList.remove('profile-username-shimmer');
profileCardUsername.classList.add('profile-username');
profileCardUsername.textContent = `${user.username}`;
profileUsername.classList.remove('profile-username-shimmer');
profileUsername.classList.add('profile-username');
profileUsername.textContent = `${user.username}`;
}

const addIntersectionObserver = () => {
Expand Down
Loading