up
This commit is contained in:
+8
-1
@@ -550,10 +550,17 @@
|
||||
|
||||
async loadNotifications() {
|
||||
try {
|
||||
const resp = await fetch('api/get_notifications.php');
|
||||
const resp = await fetch('api/get_notifications.php', { credentials: 'same-origin' });
|
||||
if (resp.status === 401) {
|
||||
console.warn('Notifications fetch: unauthorized (session may have expired)');
|
||||
return;
|
||||
}
|
||||
const json = await resp.json();
|
||||
console.debug('loadNotifications response:', json);
|
||||
if (json && json.success && Array.isArray(json.data)) {
|
||||
json.data.forEach(n => this.showNotificationToast(n));
|
||||
} else if (json && json.success === false) {
|
||||
console.warn('get_notifications returned error:', json.error || json);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error loading notifications', e);
|
||||
|
||||
@@ -958,8 +958,14 @@ try {
|
||||
},
|
||||
async loadNotifications() {
|
||||
try {
|
||||
const resp = await fetch('api/get_notifications.php');
|
||||
const resp = await fetch('api/get_notifications.php', { credentials: 'same-origin' });
|
||||
if (resp.status === 401) {
|
||||
console.warn('Notifications fetch: unauthorized (session may have expired)');
|
||||
this.showSessionExpiredToast();
|
||||
return;
|
||||
}
|
||||
const json = await resp.json();
|
||||
console.debug('NotificationManager.loadNotifications response:', json);
|
||||
if (json && json.success && Array.isArray(json.data)) {
|
||||
const unreadCount = json.data.length;
|
||||
if (unreadCount > 0) {
|
||||
@@ -969,11 +975,35 @@ try {
|
||||
this.countEl.style.display = 'none';
|
||||
}
|
||||
json.data.forEach(n => this.showToast(n));
|
||||
} else if (json && json.success === false) {
|
||||
console.warn('Notification API error:', json.error || json);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error loading global notifications', e);
|
||||
}
|
||||
},
|
||||
showSessionExpiredToast() {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = 'notification-toast';
|
||||
toast.style.background = '#fff7f7';
|
||||
toast.style.border = '1px solid #f5c6cb';
|
||||
toast.style.padding = '10px 14px';
|
||||
toast.style.marginTop = '8px';
|
||||
toast.style.borderRadius = '6px';
|
||||
toast.style.minWidth = '220px';
|
||||
const msg = document.createElement('div');
|
||||
msg.textContent = 'La sesión ha expirado. Por favor, vuelve a iniciar sesión.';
|
||||
toast.appendChild(msg);
|
||||
const btn = document.createElement('button');
|
||||
btn.className = 'btn btn-sm btn-primary';
|
||||
btn.textContent = 'Ir a login';
|
||||
btn.onclick = () => { window.location.href = 'login.php'; };
|
||||
const actions = document.createElement('div');
|
||||
actions.style.marginTop = '8px';
|
||||
actions.appendChild(btn);
|
||||
toast.appendChild(actions);
|
||||
this.toastsContainer.appendChild(toast);
|
||||
}
|
||||
showToast(notification) {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = 'notification-toast';
|
||||
|
||||
Reference in New Issue
Block a user