Fix notifications hook registration

This commit is contained in:
root
2026-01-31 03:06:53 +02:00
parent 4d529a2e52
commit 99f9dacba9

View File

@@ -1,17 +1,30 @@
<script data-navigate-once>
document.addEventListener('livewire:init', () => {
if (!window.Livewire || !window.Livewire.hook || !window.Livewire.dispatch) {
return;
}
(function () {
let hookRegistered = false;
window.Livewire.hook('commit', ({ component, succeed }) => {
if (component?.name === 'notifications') {
const registerHook = () => {
if (hookRegistered || !window.Livewire?.hook || !window.Livewire?.dispatch) {
return;
}
succeed(() => {
window.Livewire.dispatch('notificationsSent');
hookRegistered = true;
window.Livewire.hook('commit', ({ component, succeed }) => {
if (component?.name === 'notifications') {
return;
}
succeed(() => {
window.Livewire.dispatch('notificationsSent');
});
});
});
});
};
document.addEventListener('livewire:init', registerHook);
document.addEventListener('livewire:navigated', registerHook);
if (window.Livewire?.hook) {
registerHook();
}
})();
</script>