Files
jabali-panel/resources/views/filament/partials/notifications-refresh.blade.php

58 lines
2.1 KiB
PHP

<script data-navigate-once>
(function () {
let hookRegistered = false;
const registerHook = () => {
if (hookRegistered || !window.Livewire?.hook || !window.Livewire?.dispatch) {
return;
}
hookRegistered = true;
window.Livewire.hook('commit', ({ component, succeed }) => {
if (component?.name === 'notifications') {
return;
}
succeed(() => {
const livewire = window.Livewire;
const allComponents = typeof livewire?.all === 'function' ? livewire.all() : [];
const notificationsComponent = allComponents.find((component) => {
const name = component?.name ?? '';
return name === 'notifications' || name.includes('notifications');
});
if (notificationsComponent?.$wire?.pullNotificationsFromSession) {
try {
notificationsComponent.$wire.pullNotificationsFromSession();
return;
} catch (error) {
// fall back to dispatch-based refresh
}
}
const dispatchTo = livewire?.dispatchTo;
if (dispatchTo) {
['notifications', 'filament.notifications', 'filament-notifications'].forEach((name) => {
try {
dispatchTo(name, 'notificationsSent');
} catch (error) {
// ignore missing component names
}
});
}
livewire?.dispatch?.('notificationsSent');
});
});
};
document.addEventListener('livewire:init', registerHook);
document.addEventListener('livewire:navigated', registerHook);
if (window.Livewire?.hook) {
registerHook();
}
})();
</script>