@@ -11,6 +11,7 @@ let isDataLoading = false;
11
11
const loader = document . querySelector ( '.loader' ) ;
12
12
const filterModal = document . querySelector ( '.filter-modal' ) ;
13
13
const backDrop = document . querySelector ( '.backdrop' ) ;
14
+ const totalCountElement = document . querySelector ( '.total_count' ) ;
14
15
const backDropBlur = document . querySelector ( '.backdrop-blur' ) ;
15
16
const applicationDetailsModal = document . querySelector ( '.application-details' ) ;
16
17
const mainContainer = document . querySelector ( '.container' ) ;
@@ -95,7 +96,9 @@ function changeFilter() {
95
96
if ( ! isDev ) {
96
97
filterModal . classList . add ( 'hidden' ) ;
97
98
backDrop . style . display = 'none' ;
99
+ totalCountElement . classList . add ( 'hidden' ) ;
98
100
} else {
101
+ totalCountElement . classList . add ( 'hidden' ) ;
99
102
status = 'all' ;
100
103
}
101
104
applicationContainer . innerHTML = '' ;
@@ -294,7 +297,7 @@ function removeQueryParamInUrl(queryParamKey) {
294
297
window . history . replaceState ( window . history . state , '' , updatedUrl ) ;
295
298
}
296
299
297
- function createApplicationCard ( { application } ) {
300
+ function createApplicationCard ( { application, dev } ) {
298
301
const applicationCard = createElement ( {
299
302
type : 'div' ,
300
303
attributes : { class : 'application-card' } ,
@@ -333,45 +336,68 @@ function createApplicationCard({ application }) {
333
336
innerText : application . intro . introduction . slice ( 0 , 200 ) ,
334
337
} ) ;
335
338
336
- const viewDetailsButton = createElement ( {
337
- type : 'button' ,
338
- attributes : { class : 'view-details-button' } ,
339
- innerText : 'View Details' ,
340
- } ) ;
341
-
342
- viewDetailsButton . addEventListener ( 'click' , ( ) => {
343
- addQueryParamInUrl ( 'id' , application . id ) ;
344
- openApplicationDetails ( application ) ;
345
- } ) ;
346
-
347
339
applicationCard . appendChild ( userInfoContainer ) ;
348
340
applicationCard . appendChild ( introductionText ) ;
349
- applicationCard . appendChild ( viewDetailsButton ) ;
341
+
342
+ if ( dev ) {
343
+ applicationCard . style . cursor = 'pointer' ;
344
+ applicationCard . addEventListener ( 'click' , ( ) => {
345
+ addQueryParamInUrl ( 'id' , application . id ) ;
346
+ openApplicationDetails ( application ) ;
347
+ } ) ;
348
+ } else {
349
+ const viewDetailsButton = createElement ( {
350
+ type : 'button' ,
351
+ attributes : { class : 'view-details-button' } ,
352
+ innerText : 'View Details' ,
353
+ } ) ;
354
+
355
+ viewDetailsButton . addEventListener ( 'click' , ( ) => {
356
+ addQueryParamInUrl ( 'id' , application . id ) ;
357
+ openApplicationDetails ( application ) ;
358
+ } ) ;
359
+ applicationCard . appendChild ( viewDetailsButton ) ;
360
+ }
350
361
351
362
return applicationCard ;
352
363
}
353
364
354
- async function renderApplicationCards ( next , status , isInitialRender ) {
365
+ function updateTotalCount ( total , status ) {
366
+ if ( total > 0 ) {
367
+ totalCountElement . textContent = `Total ${ status } applications: ${ total } ` ;
368
+ totalCountElement . classList . remove ( 'hidden' ) ;
369
+ }
370
+ }
371
+
372
+ async function renderApplicationCards ( next , status , isInitialRender , dev ) {
355
373
noApplicationFoundText . classList . add ( 'hidden' ) ;
356
374
changeLoaderVisibility ( { hide : false } ) ;
357
375
isDataLoading = true ;
358
376
const data = await getApplications ( {
359
377
applicationStatus : status ,
360
378
next,
379
+ dev,
361
380
} ) ;
362
381
isDataLoading = false ;
363
382
changeLoaderVisibility ( { hide : true } ) ;
364
383
const applications = data . applications ;
384
+ const totalSelectedCount = data . totalCount ;
385
+
365
386
nextLink = data . next ;
366
387
if ( isDev && status != 'all' ) {
367
388
showAppliedFilter ( status ) ;
368
389
}
369
390
if ( isInitialRender ) filterButton . classList . remove ( 'hidden' ) ;
391
+
392
+ if ( dev ) {
393
+ updateTotalCount ( totalSelectedCount , status ) ;
394
+ }
370
395
if ( ! applications . length )
371
396
return noApplicationFoundText . classList . remove ( 'hidden' ) ;
372
397
applications . forEach ( ( application ) => {
373
398
const applicationCard = createApplicationCard ( {
374
399
application,
400
+ dev,
375
401
} ) ;
376
402
applicationContainer . appendChild ( applicationCard ) ;
377
403
} ) ;
@@ -422,7 +448,13 @@ async function renderApplicationById(id) {
422
448
if ( applicationId ) {
423
449
await renderApplicationById ( applicationId ) ;
424
450
}
425
- await renderApplicationCards ( '' , status , true , applicationId ) ;
451
+
452
+ if ( isDev ) {
453
+ await renderApplicationCards ( '' , status , true , isDev ) ;
454
+ } else {
455
+ await renderApplicationCards ( '' , status , true , applicationId ) ;
456
+ }
457
+
426
458
addIntersectionObserver ( ) ;
427
459
428
460
changeLoaderVisibility ( { hide : true } ) ;
@@ -433,7 +465,12 @@ const intersectionObserver = new IntersectionObserver(async (entries) => {
433
465
return ;
434
466
}
435
467
if ( entries [ 0 ] . isIntersecting && ! isDataLoading ) {
436
- await renderApplicationCards ( nextLink ) ;
468
+ const dev = urlParams . get ( 'dev' ) ;
469
+ if ( dev ) {
470
+ await renderApplicationCards ( nextLink , status , true , dev ) ;
471
+ } else {
472
+ await renderApplicationCards ( nextLink ) ;
473
+ }
437
474
}
438
475
} ) ;
439
476
@@ -450,7 +487,7 @@ if (isDev) {
450
487
filterOptions . forEach ( ( option ) => {
451
488
option . addEventListener ( 'click' , ( ) => {
452
489
const filter = option . getAttribute ( 'data-filter' ) ;
453
- applyFilter ( filter ) ;
490
+ applyFilter ( filter , isDev ) ;
454
491
} ) ;
455
492
} ) ;
456
493
} else {
@@ -473,7 +510,14 @@ if (isDev) {
473
510
addQueryParamInUrl ( 'status' , selectedStatus ) ;
474
511
changeFilter ( ) ;
475
512
status = selectedStatus ;
476
- renderApplicationCards ( nextLink , status ) ;
513
+ const urlParams = new URLSearchParams ( window . location . search ) ;
514
+ const dev = urlParams . get ( 'dev' ) ;
515
+
516
+ if ( dev ) {
517
+ renderApplicationCards ( nextLink , status , false , dev ) ;
518
+ } else {
519
+ renderApplicationCards ( nextLink , status ) ;
520
+ }
477
521
} ) ;
478
522
479
523
clearButton . addEventListener ( 'click' , clearFilter ) ;
@@ -487,15 +531,15 @@ function showAppliedFilter(filterApplied) {
487
531
}
488
532
}
489
533
490
- function applyFilter ( filter ) {
534
+ function applyFilter ( filter , isDev ) {
491
535
if ( filter . length > 0 ) {
492
536
if ( ! filterLabel . classList . contains ( 'hidden' ) ) {
493
537
filterLabel . classList . add ( 'hidden' ) ;
494
538
}
495
539
addQueryParamInUrl ( 'status' , filter ) ;
496
540
changeFilter ( ) ;
497
541
status = filter ;
498
- renderApplicationCards ( nextLink , status ) ;
542
+ renderApplicationCards ( nextLink , status , false , isDev ) ;
499
543
filterDropdown . style . display = 'none' ;
500
544
}
501
545
}
@@ -505,7 +549,8 @@ filterRemove.addEventListener('click', () => {
505
549
filterText . textContent = '' ;
506
550
removeQueryParamInUrl ( 'status' ) ;
507
551
changeFilter ( ) ;
508
- renderApplicationCards ( nextLink , status ) ;
552
+ const dev = urlParams . get ( 'dev' ) ;
553
+ renderApplicationCards ( nextLink , status , false , dev ) ;
509
554
} ) ;
510
555
511
556
backDrop . addEventListener ( 'click' , ( ) => {
0 commit comments