9
9
let nextLink ;
10
10
let isDataLoading = false ;
11
11
const loader = document . querySelector ( '.loader' ) ;
12
- const filterButton = document . getElementById ( 'filter-button' ) ;
13
12
const filterModal = document . querySelector ( '.filter-modal' ) ;
14
13
const backDrop = document . querySelector ( '.backdrop' ) ;
15
14
const backDropBlur = document . querySelector ( '.backdrop-blur' ) ;
@@ -36,8 +35,25 @@ const lastElementContainer = document.getElementById('page_bottom_element');
36
35
const applicationDetailsActionsContainer = document . querySelector (
37
36
'.application-details-actions' ,
38
37
) ;
39
-
40
38
const urlParams = new URLSearchParams ( window . location . search ) ;
39
+ const isDev = urlParams . get ( 'dev' ) === 'true' ;
40
+ const filterButton = isDev
41
+ ? document . getElementById ( 'filter-button-new' )
42
+ : document . getElementById ( 'filter-button' ) ;
43
+ if ( isDev )
44
+ document
45
+ . getElementsByClassName ( 'filter-container' ) [ 0 ]
46
+ . classList . remove ( 'hidden' ) ;
47
+
48
+ const filterDropdown = document . querySelector ( '.filter-dropdown' ) ;
49
+ const filterOptions = document . querySelectorAll (
50
+ '.filter-dropdown div:not(.close-dropdown-btn)' ,
51
+ ) ;
52
+ const filterLabel = document . querySelector ( '.filter-label' ) ;
53
+ const filterText = document . querySelector ( '.filter-label .filter-text' ) ;
54
+ const filterRemove = document . querySelector ( '.filter-remove' ) ;
55
+ const closeDropdownBtn = document . querySelector ( '.close-dropdown-btn' ) ;
56
+
41
57
let applicationId = urlParams . get ( 'id' ) ;
42
58
43
59
let currentApplicationId ;
@@ -76,8 +92,12 @@ function updateUserApplication({ isAccepted }) {
76
92
77
93
function changeFilter ( ) {
78
94
nextLink = '' ;
79
- filterModal . classList . add ( 'hidden' ) ;
80
- backDrop . style . display = 'none' ;
95
+ if ( ! isDev ) {
96
+ filterModal . classList . add ( 'hidden' ) ;
97
+ backDrop . style . display = 'none' ;
98
+ } else {
99
+ status = 'all' ;
100
+ }
81
101
applicationContainer . innerHTML = '' ;
82
102
}
83
103
@@ -343,6 +363,9 @@ async function renderApplicationCards(next, status, isInitialRender) {
343
363
changeLoaderVisibility ( { hide : true } ) ;
344
364
const applications = data . applications ;
345
365
nextLink = data . next ;
366
+ if ( isDev && status != 'all' ) {
367
+ showAppliedFilter ( status ) ;
368
+ }
346
369
if ( isInitialRender ) filterButton . classList . remove ( 'hidden' ) ;
347
370
if ( ! applications . length )
348
371
return noApplicationFoundText . classList . remove ( 'hidden' ) ;
@@ -392,7 +415,7 @@ async function renderApplicationById(id) {
392
415
const urlParams = new URLSearchParams ( window . location . search ) ;
393
416
status = urlParams . get ( 'status' ) || 'all' ;
394
417
395
- if ( status !== 'all' ) {
418
+ if ( ! isDev && status !== 'all' ) {
396
419
document . querySelector ( `input[name="status"]#${ status } ` ) . checked = true ;
397
420
}
398
421
@@ -418,9 +441,71 @@ const addIntersectionObserver = () => {
418
441
intersectionObserver . observe ( lastElementContainer ) ;
419
442
} ;
420
443
421
- filterButton . addEventListener ( 'click' , ( ) => {
422
- filterModal . classList . toggle ( 'hidden' ) ;
423
- backDrop . style . display = 'flex' ;
444
+ if ( isDev ) {
445
+ filterButton . addEventListener ( 'click' , ( ) => {
446
+ filterDropdown . style . display =
447
+ filterDropdown . style . display === 'block' ? 'none' : 'block' ;
448
+ } ) ;
449
+
450
+ filterOptions . forEach ( ( option ) => {
451
+ option . addEventListener ( 'click' , ( ) => {
452
+ const filter = option . getAttribute ( 'data-filter' ) ;
453
+ applyFilter ( filter ) ;
454
+ } ) ;
455
+ } ) ;
456
+ } else {
457
+ filterButton . addEventListener ( 'click' , ( ) => {
458
+ filterModal . classList . toggle ( 'hidden' ) ;
459
+ backDrop . style . display = 'flex' ;
460
+ } ) ;
461
+
462
+ backDrop . addEventListener ( 'click' , ( ) => {
463
+ filterModal . classList . add ( 'hidden' ) ;
464
+ backDrop . style . display = 'none' ;
465
+ } ) ;
466
+
467
+ applyFilterButton . addEventListener ( 'click' , ( ) => {
468
+ const selectedFilterOption = document . querySelector (
469
+ 'input[name="status"]:checked' ,
470
+ ) ;
471
+
472
+ const selectedStatus = selectedFilterOption . value ;
473
+ addQueryParamInUrl ( 'status' , selectedStatus ) ;
474
+ changeFilter ( ) ;
475
+ status = selectedStatus ;
476
+ renderApplicationCards ( nextLink , status ) ;
477
+ } ) ;
478
+
479
+ clearButton . addEventListener ( 'click' , clearFilter ) ;
480
+ }
481
+
482
+ function showAppliedFilter ( filterApplied ) {
483
+ if ( filterApplied ) {
484
+ filterLabel . classList . remove ( 'hidden' ) ;
485
+ filterText . textContent =
486
+ 'Status :' + filterApplied [ 0 ] . toUpperCase ( ) + filterApplied . substring ( 1 ) ;
487
+ }
488
+ }
489
+
490
+ function applyFilter ( filter ) {
491
+ if ( filter . length > 0 ) {
492
+ if ( ! filterLabel . classList . contains ( 'hidden' ) ) {
493
+ filterLabel . classList . add ( 'hidden' ) ;
494
+ }
495
+ addQueryParamInUrl ( 'status' , filter ) ;
496
+ changeFilter ( ) ;
497
+ status = filter ;
498
+ renderApplicationCards ( nextLink , status ) ;
499
+ filterDropdown . style . display = 'none' ;
500
+ }
501
+ }
502
+
503
+ filterRemove . addEventListener ( 'click' , ( ) => {
504
+ filterLabel . classList . add ( 'hidden' ) ;
505
+ filterText . textContent = '' ;
506
+ removeQueryParamInUrl ( 'status' ) ;
507
+ changeFilter ( ) ;
508
+ renderApplicationCards ( nextLink , status ) ;
424
509
} ) ;
425
510
426
511
backDrop . addEventListener ( 'click' , ( ) => {
@@ -431,19 +516,15 @@ backDrop.addEventListener('click', () => {
431
516
backDropBlur . addEventListener ( 'click' , closeApplicationDetails ) ;
432
517
applicationCloseButton . addEventListener ( 'click' , closeApplicationDetails ) ;
433
518
434
- applyFilterButton . addEventListener ( 'click' , ( ) => {
435
- const selectedFilterOption = document . querySelector (
436
- 'input[name="status"]:checked' ,
437
- ) ;
438
-
439
- const selectedStatus = selectedFilterOption . value ;
440
- addQueryParamInUrl ( 'status' , selectedStatus ) ;
441
- changeFilter ( ) ;
442
- status = selectedStatus ;
443
- renderApplicationCards ( nextLink , status ) ;
519
+ document . addEventListener ( 'click' , ( e ) => {
520
+ if ( ! filterButton . contains ( e . target ) && ! filterDropdown . contains ( e . target ) ) {
521
+ filterDropdown . style . display = 'none' ;
522
+ }
444
523
} ) ;
445
524
446
- clearButton . addEventListener ( 'click' , clearFilter ) ;
525
+ closeDropdownBtn . addEventListener ( 'click' , ( ) => {
526
+ filterDropdown . style . display = 'none' ;
527
+ } ) ;
447
528
448
529
applicationAcceptButton . addEventListener ( 'click' , ( ) =>
449
530
updateUserApplication ( { isAccepted : true } ) ,
0 commit comments