@@ -133,9 +133,18 @@ async function populateProfileDiffs(query = {}, newLink) {
133
133
} ) ;
134
134
}
135
135
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
+ } ) ;
139
148
} catch ( error ) {
140
149
showToast ( { type : 'error' , message : 'Something went wrong!' } ) ;
141
150
} finally {
@@ -177,7 +186,7 @@ function debounce(func, delay) {
177
186
} ;
178
187
}
179
188
180
- async function createProfileDiffCard ( data , profileDiffCardList ) {
189
+ function createProfileDiffCard ( data ) {
181
190
const time = data . timestamp ;
182
191
const fireBaseTime = new Date (
183
192
time . _seconds * 1000 + time . _nanoseconds / 1000000 ,
@@ -195,15 +204,14 @@ async function createProfileDiffCard(data, profileDiffCardList) {
195
204
196
205
const profileCard = createElement ( {
197
206
type : 'div' ,
198
- attributes : { class : 'profile-card' } ,
207
+ attributes : { class : 'profile-card' , 'data-id' : data . id } ,
199
208
} ) ;
200
209
if ( filterStates . status === Status . PENDING ) {
201
210
profileCard . style . cursor = 'pointer' ;
202
211
profileCard . addEventListener ( 'click' , ( ) => {
203
212
window . location . href = `/profile-diff-details/?id=${ data . id } ` ;
204
213
} ) ;
205
214
}
206
- profileDiffCardList . appendChild ( profileCard ) ;
207
215
208
216
const profileCardLeft = createElement ( {
209
217
type : 'div' ,
@@ -251,19 +259,29 @@ async function createProfileDiffCard(data, profileDiffCardList) {
251
259
profileCard . appendChild ( profileCardLeft ) ;
252
260
profileCard . appendChild ( profileCardRight ) ;
253
261
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' ) ;
256
273
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' ;
259
277
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 } ` ;
263
281
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 } ` ;
267
285
}
268
286
269
287
const addIntersectionObserver = ( ) => {
0 commit comments