Skip to content

Commit 367b33a

Browse files
authored
Merge pull request #869 from Real-Dev-Squad/fix/profileDiffLoading
Fixed profile diff loading issue
2 parents 1fa763f + ce66aed commit 367b33a

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed
Lines changed: 4 additions & 0 deletions
Loading

profile-diff-details/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async function setUser(profileDiff) {
122122
type: 'img',
123123
attributes: {
124124
class: 'user_image',
125-
src: user.picture.url,
125+
src: user.picture?.url || 'assets/default-profile.svg',
126126
height: '71px',
127127
width: '71px',
128128
},
@@ -135,7 +135,7 @@ async function setUser(profileDiff) {
135135
class: 'user_name',
136136
},
137137
});
138-
username.innerHTML = `${user.first_name} ${user.last_name}`;
138+
username.innerHTML = `${user.first_name || ''} ${user.last_name || ''}`;
139139
CONTAINER.appendChild(username);
140140

141141
const expandControlContainer = createElement({

profile-diffs/script.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,18 @@ async function populateProfileDiffs(query = {}, newLink) {
133133
});
134134
}
135135
profileDiffsElement.appendChild(profileDiffsListElement);
136-
for (let data of allProfileDiffs) {
137-
await createProfileDiffCard(data, profileDiffsListElement);
138-
}
136+
137+
// Create all profile diff cards with shimmer effect
138+
allProfileDiffs.forEach((data) => {
139+
const card = createProfileDiffCard(data);
140+
profileDiffsListElement.appendChild(card);
141+
});
142+
143+
// Fetch user details and update cards
144+
allProfileDiffs.forEach(async (data) => {
145+
const user = await getUser(data.userId);
146+
updateProfileDiffCard(data.id, user);
147+
});
139148
} catch (error) {
140149
showToast({ type: 'error', message: 'Something went wrong!' });
141150
} finally {
@@ -177,7 +186,7 @@ function debounce(func, delay) {
177186
};
178187
}
179188

180-
async function createProfileDiffCard(data, profileDiffCardList) {
189+
function createProfileDiffCard(data) {
181190
const time = data.timestamp;
182191
const fireBaseTime = new Date(
183192
time._seconds * 1000 + time._nanoseconds / 1000000,
@@ -195,15 +204,14 @@ async function createProfileDiffCard(data, profileDiffCardList) {
195204

196205
const profileCard = createElement({
197206
type: 'div',
198-
attributes: { class: 'profile-card' },
207+
attributes: { class: 'profile-card', 'data-id': data.id },
199208
});
200209
if (filterStates.status === Status.PENDING) {
201210
profileCard.style.cursor = 'pointer';
202211
profileCard.addEventListener('click', () => {
203212
window.location.href = `/profile-diff-details/?id=${data.id}`;
204213
});
205214
}
206-
profileDiffCardList.appendChild(profileCard);
207215

208216
const profileCardLeft = createElement({
209217
type: 'div',
@@ -251,19 +259,29 @@ async function createProfileDiffCard(data, profileDiffCardList) {
251259
profileCard.appendChild(profileCardLeft);
252260
profileCard.appendChild(profileCardRight);
253261

254-
const user = await getUser(data.userId);
255-
profileCardLeft.classList.remove('shimmer');
262+
return profileCard;
263+
}
264+
265+
function updateProfileDiffCard(cardId, user) {
266+
const card = document.querySelector(`.profile-card[data-id="${cardId}"]`);
267+
if (!card) return;
268+
269+
const profileLeft = card.querySelector('.profile');
270+
const profilePic = card.querySelector('.profile-pic');
271+
const profileName = card.querySelector('.profile-name-shimmer');
272+
const profileUsername = card.querySelector('.profile-username-shimmer');
256273

257-
profileCardPhoto.style.backgroundImage = `url(${user.picture?.url})`;
258-
profileCardPhoto.style.backgroundSize = 'cover';
274+
profileLeft.classList.remove('shimmer');
275+
profilePic.style.backgroundImage = `url(${user.picture?.url})`;
276+
profilePic.style.backgroundSize = 'cover';
259277

260-
profileCardName.classList.remove('profile-name-shimmer');
261-
profileCardName.classList.add('profile-name');
262-
profileCardName.textContent = `${user.first_name} ${user.last_name}`;
278+
profileName.classList.remove('profile-name-shimmer');
279+
profileName.classList.add('profile-name');
280+
profileName.textContent = `${user.first_name} ${user.last_name}`;
263281

264-
profileCardUsername.classList.remove('profile-username-shimmer');
265-
profileCardUsername.classList.add('profile-username');
266-
profileCardUsername.textContent = `${user.username}`;
282+
profileUsername.classList.remove('profile-username-shimmer');
283+
profileUsername.classList.add('profile-username');
284+
profileUsername.textContent = `${user.username}`;
267285
}
268286

269287
const addIntersectionObserver = () => {

0 commit comments

Comments
 (0)