mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-25 05:02:57 +01:00
Use data-action to listen to w-swap:success in DrilldownController
and rename the method to updateParamsCount
This commit is contained in:
parent
a1e3f755e5
commit
7ba218a094
@ -8,38 +8,31 @@ export class DrilldownController extends Controller<HTMLElement> {
|
||||
};
|
||||
|
||||
declare activeSubmenuValue: string;
|
||||
declare swapSuccessListener: (e: Event) => void;
|
||||
|
||||
declare readonly menuTarget: HTMLElement;
|
||||
declare readonly toggleTargets: HTMLButtonElement[];
|
||||
|
||||
connect() {
|
||||
this.updateToggleCounts();
|
||||
|
||||
this.swapSuccessListener = (e: Event) => {
|
||||
const swapEvent = e as CustomEvent<{ requestUrl: string }>;
|
||||
if ((e.target as HTMLElement)?.id === 'listing-results') {
|
||||
const params = new URLSearchParams(
|
||||
swapEvent.detail?.requestUrl.split('?')[1],
|
||||
);
|
||||
const filteredParams = new URLSearchParams();
|
||||
params.forEach((value, key) => {
|
||||
if (value.trim() !== '') {
|
||||
// Check if the value is not empty after trimming white space
|
||||
filteredParams.append(key, value);
|
||||
}
|
||||
});
|
||||
const queryString = '?' + filteredParams.toString();
|
||||
this.updateToggleCounts();
|
||||
window.history.replaceState(null, '', queryString);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('w-swap:success', this.swapSuccessListener);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
document.removeEventListener('w-swap:success', this.swapSuccessListener);
|
||||
updateParamsCount(e: Event) {
|
||||
const swapEvent = e as CustomEvent<{ requestUrl: string }>;
|
||||
if ((e.target as HTMLElement)?.id === 'listing-results') {
|
||||
const params = new URLSearchParams(
|
||||
swapEvent.detail?.requestUrl.split('?')[1],
|
||||
);
|
||||
const filteredParams = new URLSearchParams();
|
||||
params.forEach((value, key) => {
|
||||
if (value.trim() !== '') {
|
||||
// Check if the value is not empty after trimming white space
|
||||
filteredParams.append(key, value);
|
||||
}
|
||||
});
|
||||
const queryString = '?' + filteredParams.toString();
|
||||
this.updateToggleCounts();
|
||||
window.history.replaceState(null, '', queryString);
|
||||
}
|
||||
}
|
||||
|
||||
open(e: MouseEvent) {
|
||||
|
@ -79,7 +79,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if filters %}
|
||||
<div class="w-drilldown" data-controller="w-drilldown">
|
||||
<div class="w-drilldown" data-controller="w-drilldown" data-action="w-swap:success@document->w-drilldown#updateParamsCount">
|
||||
{% fragment as toggle_suffix %}
|
||||
<span class="w-drilldown__count" hidden></span>
|
||||
{% endfragment %}
|
||||
|
Loading…
Reference in New Issue
Block a user