Skip to content

Commit

Permalink
Allow to remove single filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite committed Mar 4, 2024
1 parent fb3f689 commit c2c1497
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions scripts/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,41 @@ document.querySelectorAll('.filter-item').forEach(function(item) {
if (this.hasAttribute('data-categoryid')) {
const categoryId = this.getAttribute('data-categoryid');
const urlParams = new URLSearchParams(window.location.search);
let newUrl = `stats.php?category=${categoryId}`;
let newUrl = 'stats.php?';

if (urlParams.has('member')) {
newUrl += `&member=${urlParams.get('member')}`;
}

if (urlParams.has('payment')) {
newUrl += `&payment=${urlParams.get('payment')}`;
if (urlParams.get('category') === categoryId) {
urlParams.delete('category');
} else {
urlParams.set('category', categoryId);
}

newUrl += urlParams.toString();
window.location.href = newUrl;
} else if (this.hasAttribute('data-memberid')) {
const memberId = this.getAttribute('data-memberid');
const urlParams = new URLSearchParams(window.location.search);
let newUrl = `stats.php?member=${memberId}`;

if (urlParams.has('category')) {
newUrl += `&category=${urlParams.get('category')}`;
}
let newUrl = 'stats.php?';

if (urlParams.has('payment')) {
newUrl += `&payment=${urlParams.get('payment')}`;
if (urlParams.get('member') === memberId) {
urlParams.delete('member');
} else {
urlParams.set('member', memberId);
}

newUrl += urlParams.toString();
window.location.href = newUrl;
} else if (this.hasAttribute('data-paymentid')) {
const paymentId = this.getAttribute('data-paymentid');
const urlParams = new URLSearchParams(window.location.search);
let newUrl = `stats.php?payment=${paymentId}`;

if (urlParams.has('member')) {
newUrl += `&member=${urlParams.get('member')}`;
}
let newUrl = 'stats.php?';

if (urlParams.has('category')) {
newUrl += `&category=${urlParams.get('category')}`;
if (urlParams.get('payment') === paymentId) {
urlParams.delete('payment');
} else {
urlParams.set('payment', paymentId);
}

newUrl += urlParams.toString();
window.location.href = newUrl;
}
});
Expand Down

0 comments on commit c2c1497

Please sign in to comment.