Fix notifications hook registration
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user