Pages corrections pages health

This commit is contained in:
alma 2026-01-16 17:04:13 +01:00
parent 091b598d1b
commit 93f9e04c1f
2 changed files with 64 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from 'react';
import { useState, useEffect, useRef, useCallback } from 'react';
import { Calendar } from 'lucide-react';
import { OutlookNotificationData } from '@/components/outlook-notification';
import { format } from 'date-fns';
@ -24,6 +24,35 @@ export function useCalendarEventNotifications() {
const eventsRef = useRef<CalendarEvent[]>([]);
const checkIntervalRef = useRef<NodeJS.Timeout | null>(null);
// Load notified event IDs from localStorage on mount
useEffect(() => {
try {
const stored = localStorage.getItem('notified-event-ids');
if (stored) {
const ids = JSON.parse(stored);
notifiedEventIdsRef.current = new Set(ids);
console.log('[useCalendarEventNotifications] 📦 Loaded notified event IDs from localStorage', {
count: ids.length,
});
}
} catch (error) {
console.error('[useCalendarEventNotifications] ❌ Error loading notified event IDs from localStorage', error);
}
}, []);
// Save notified event IDs to localStorage whenever it changes
const saveNotifiedEventIds = useCallback(() => {
try {
const ids = Array.from(notifiedEventIdsRef.current);
localStorage.setItem('notified-event-ids', JSON.stringify(ids));
console.log('[useCalendarEventNotifications] 💾 Saved notified event IDs to localStorage', {
count: ids.length,
});
} catch (error) {
console.error('[useCalendarEventNotifications] ❌ Error saving notified event IDs to localStorage', error);
}
}, []);
useEffect(() => {
console.log('[useCalendarEventNotifications] 🎧 Hook initialized, listening for calendar-events-updated');
@ -170,10 +199,12 @@ export function useCalendarEventNotifications() {
setEventNotification(notification);
notifiedEventIdsRef.current.add(event.id);
saveNotifiedEventIds(); // Persist to localStorage
// Clean up old notified events (older than 1 hour) to allow re-notification if needed
setTimeout(() => {
notifiedEventIdsRef.current.delete(event.id);
saveNotifiedEventIds(); // Update localStorage after cleanup
}, 60 * 60 * 1000); // 1 hour
}
};

View File

@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from 'react';
import { useState, useEffect, useRef, useCallback } from 'react';
import { CheckSquare } from 'lucide-react';
import { OutlookNotificationData } from '@/components/outlook-notification';
import { format } from 'date-fns';
@ -24,6 +24,35 @@ export function useTaskNotifications() {
const tasksRef = useRef<Task[]>([]);
const checkIntervalRef = useRef<NodeJS.Timeout | null>(null);
// Load notified task IDs from localStorage on mount
useEffect(() => {
try {
const stored = localStorage.getItem('notified-task-ids');
if (stored) {
const ids = JSON.parse(stored);
notifiedTaskIdsRef.current = new Set(ids);
console.log('[useTaskNotifications] 📦 Loaded notified task IDs from localStorage', {
count: ids.length,
});
}
} catch (error) {
console.error('[useTaskNotifications] ❌ Error loading notified task IDs from localStorage', error);
}
}, []);
// Save notified task IDs to localStorage whenever it changes
const saveNotifiedTaskIds = useCallback(() => {
try {
const ids = Array.from(notifiedTaskIdsRef.current);
localStorage.setItem('notified-task-ids', JSON.stringify(ids));
console.log('[useTaskNotifications] 💾 Saved notified task IDs to localStorage', {
count: ids.length,
});
} catch (error) {
console.error('[useTaskNotifications] ❌ Error saving notified task IDs to localStorage', error);
}
}, []);
useEffect(() => {
console.log('[useTaskNotifications] 🎧 Hook initialized, listening for tasks-updated');
@ -295,10 +324,12 @@ export function useTaskNotifications() {
setTaskNotification(notification);
notifiedTaskIdsRef.current.add(task.id);
saveNotifiedTaskIds(); // Persist to localStorage
// Clean up old notified tasks (older than 1 hour) to allow re-notification if needed
setTimeout(() => {
notifiedTaskIdsRef.current.delete(task.id);
saveNotifiedTaskIds(); // Update localStorage after cleanup
}, 60 * 60 * 1000); // 1 hour
}
};