8
8
} from './utils.js' ;
9
9
let nextLink ;
10
10
let isDataLoading = false ;
11
+ let totalApplicationCount = 0 ;
12
+ let currentApplicationIndex = 0 ;
11
13
const loader = document . querySelector ( '.loader' ) ;
12
14
const filterModal = document . querySelector ( '.filter-modal' ) ;
13
15
const backDrop = document . querySelector ( '.backdrop' ) ;
@@ -38,6 +40,7 @@ const applicationDetailsActionsContainer = document.querySelector(
38
40
) ;
39
41
const urlParams = new URLSearchParams ( window . location . search ) ;
40
42
const isDev = urlParams . get ( 'dev' ) === 'true' ;
43
+ let isApplicationPending = urlParams . get ( 'status' ) === 'pending' ;
41
44
const filterButton = isDev
42
45
? document . getElementById ( 'filter-button-new' )
43
46
: document . getElementById ( 'filter-button' ) ;
@@ -100,6 +103,7 @@ function changeFilter() {
100
103
} else {
101
104
totalCountElement . classList . add ( 'hidden' ) ;
102
105
status = 'all' ;
106
+ totalApplicationCount = 0 ;
103
107
}
104
108
applicationContainer . innerHTML = '' ;
105
109
}
@@ -297,7 +301,7 @@ function removeQueryParamInUrl(queryParamKey) {
297
301
window . history . replaceState ( window . history . state , '' , updatedUrl ) ;
298
302
}
299
303
300
- function createApplicationCard ( { application, dev } ) {
304
+ function createApplicationCard ( { application, dev, index } ) {
301
305
const applicationCard = createElement ( {
302
306
type : 'div' ,
303
307
attributes : { class : 'application-card' } ,
@@ -314,6 +318,29 @@ function createApplicationCard({ application, dev }) {
314
318
innerText : application . biodata . firstName ,
315
319
} ) ;
316
320
321
+ if ( dev && isApplicationPending ) {
322
+ const usernameTextAndIndex = createElement ( {
323
+ type : 'div' ,
324
+ attributes : { class : 'user-text-index' } ,
325
+ } ) ;
326
+
327
+ const userIndex = createElement ( {
328
+ type : 'input' ,
329
+ attributes : {
330
+ type : 'number' ,
331
+ value : `${ index } ` ,
332
+ readonly : '' ,
333
+ class : 'user-index' ,
334
+ 'data-testid' : 'user-index' ,
335
+ } ,
336
+ } ) ;
337
+ usernameTextAndIndex . appendChild ( usernameText ) ;
338
+ usernameTextAndIndex . appendChild ( userIndex ) ;
339
+ userInfoContainer . appendChild ( usernameTextAndIndex ) ;
340
+ } else {
341
+ userInfoContainer . appendChild ( usernameText ) ;
342
+ }
343
+
317
344
const companyNameText = createElement ( {
318
345
type : 'p' ,
319
346
attributes : { class : 'company-name hide-overflow' } ,
@@ -326,7 +353,6 @@ function createApplicationCard({ application, dev }) {
326
353
innerText : `Skills: ${ application . professional . skills } ` ,
327
354
} ) ;
328
355
329
- userInfoContainer . appendChild ( usernameText ) ;
330
356
userInfoContainer . appendChild ( companyNameText ) ;
331
357
userInfoContainer . appendChild ( skillsText ) ;
332
358
@@ -382,7 +408,10 @@ async function renderApplicationCards(next, status, isInitialRender, dev) {
382
408
changeLoaderVisibility ( { hide : true } ) ;
383
409
const applications = data . applications ;
384
410
const totalSelectedCount = data . totalCount ;
385
-
411
+ if ( isInitialRender ) {
412
+ totalApplicationCount = data . totalCount ;
413
+ currentApplicationIndex = totalApplicationCount ;
414
+ }
386
415
nextLink = data . next ;
387
416
if ( isDev && status != 'all' ) {
388
417
showAppliedFilter ( status ) ;
@@ -394,12 +423,19 @@ async function renderApplicationCards(next, status, isInitialRender, dev) {
394
423
}
395
424
if ( ! applications . length )
396
425
return noApplicationFoundText . classList . remove ( 'hidden' ) ;
397
- applications . forEach ( ( application ) => {
426
+
427
+ if ( isInitialRender || ! next ) {
428
+ applicationContainer . innerHTML = '' ;
429
+ currentApplicationIndex = totalSelectedCount ;
430
+ }
431
+ applications . forEach ( ( application , index ) => {
398
432
const applicationCard = createApplicationCard ( {
399
433
application,
400
434
dev,
435
+ index : currentApplicationIndex ,
401
436
} ) ;
402
437
applicationContainer . appendChild ( applicationCard ) ;
438
+ currentApplicationIndex -- ;
403
439
} ) ;
404
440
}
405
441
@@ -448,7 +484,8 @@ async function renderApplicationById(id) {
448
484
if ( applicationId ) {
449
485
await renderApplicationById ( applicationId ) ;
450
486
}
451
-
487
+ totalApplicationCount = 0 ;
488
+ currentApplicationIndex = 0 ;
452
489
if ( isDev ) {
453
490
await renderApplicationCards ( '' , status , true , isDev ) ;
454
491
} else {
@@ -467,7 +504,7 @@ const intersectionObserver = new IntersectionObserver(async (entries) => {
467
504
if ( entries [ 0 ] . isIntersecting && ! isDataLoading ) {
468
505
const dev = urlParams . get ( 'dev' ) ;
469
506
if ( dev ) {
470
- await renderApplicationCards ( nextLink , status , true , dev ) ;
507
+ await renderApplicationCards ( nextLink , status , false , dev ) ;
471
508
} else {
472
509
await renderApplicationCards ( nextLink ) ;
473
510
}
@@ -514,7 +551,7 @@ if (isDev) {
514
551
const dev = urlParams . get ( 'dev' ) ;
515
552
516
553
if ( dev ) {
517
- renderApplicationCards ( nextLink , status , false , dev ) ;
554
+ renderApplicationCards ( nextLink , status , true , dev ) ;
518
555
} else {
519
556
renderApplicationCards ( nextLink , status ) ;
520
557
}
@@ -539,7 +576,7 @@ function applyFilter(filter, isDev) {
539
576
addQueryParamInUrl ( 'status' , filter ) ;
540
577
changeFilter ( ) ;
541
578
status = filter ;
542
- renderApplicationCards ( nextLink , status , false , isDev ) ;
579
+ renderApplicationCards ( '' , status , false , isDev ) ;
543
580
filterDropdown . style . display = 'none' ;
544
581
}
545
582
}
@@ -550,7 +587,7 @@ filterRemove.addEventListener('click', () => {
550
587
removeQueryParamInUrl ( 'status' ) ;
551
588
changeFilter ( ) ;
552
589
const dev = urlParams . get ( 'dev' ) ;
553
- renderApplicationCards ( nextLink , status , false , dev ) ;
590
+ renderApplicationCards ( nextLink , status , true , dev ) ;
554
591
} ) ;
555
592
556
593
backDrop . addEventListener ( 'click' , ( ) => {
0 commit comments