Pages corrections pages health
This commit is contained in:
parent
091b598d1b
commit
93f9e04c1f
@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useRef } from 'react';
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||||
import { Calendar } from 'lucide-react';
|
import { Calendar } from 'lucide-react';
|
||||||
import { OutlookNotificationData } from '@/components/outlook-notification';
|
import { OutlookNotificationData } from '@/components/outlook-notification';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
@ -24,6 +24,35 @@ export function useCalendarEventNotifications() {
|
|||||||
const eventsRef = useRef<CalendarEvent[]>([]);
|
const eventsRef = useRef<CalendarEvent[]>([]);
|
||||||
const checkIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
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(() => {
|
useEffect(() => {
|
||||||
console.log('[useCalendarEventNotifications] 🎧 Hook initialized, listening for calendar-events-updated');
|
console.log('[useCalendarEventNotifications] 🎧 Hook initialized, listening for calendar-events-updated');
|
||||||
|
|
||||||
@ -170,10 +199,12 @@ export function useCalendarEventNotifications() {
|
|||||||
|
|
||||||
setEventNotification(notification);
|
setEventNotification(notification);
|
||||||
notifiedEventIdsRef.current.add(event.id);
|
notifiedEventIdsRef.current.add(event.id);
|
||||||
|
saveNotifiedEventIds(); // Persist to localStorage
|
||||||
|
|
||||||
// Clean up old notified events (older than 1 hour) to allow re-notification if needed
|
// Clean up old notified events (older than 1 hour) to allow re-notification if needed
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
notifiedEventIdsRef.current.delete(event.id);
|
notifiedEventIdsRef.current.delete(event.id);
|
||||||
|
saveNotifiedEventIds(); // Update localStorage after cleanup
|
||||||
}, 60 * 60 * 1000); // 1 hour
|
}, 60 * 60 * 1000); // 1 hour
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useRef } from 'react';
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||||
import { CheckSquare } from 'lucide-react';
|
import { CheckSquare } from 'lucide-react';
|
||||||
import { OutlookNotificationData } from '@/components/outlook-notification';
|
import { OutlookNotificationData } from '@/components/outlook-notification';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
@ -24,6 +24,35 @@ export function useTaskNotifications() {
|
|||||||
const tasksRef = useRef<Task[]>([]);
|
const tasksRef = useRef<Task[]>([]);
|
||||||
const checkIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
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(() => {
|
useEffect(() => {
|
||||||
console.log('[useTaskNotifications] 🎧 Hook initialized, listening for tasks-updated');
|
console.log('[useTaskNotifications] 🎧 Hook initialized, listening for tasks-updated');
|
||||||
|
|
||||||
@ -295,10 +324,12 @@ export function useTaskNotifications() {
|
|||||||
|
|
||||||
setTaskNotification(notification);
|
setTaskNotification(notification);
|
||||||
notifiedTaskIdsRef.current.add(task.id);
|
notifiedTaskIdsRef.current.add(task.id);
|
||||||
|
saveNotifiedTaskIds(); // Persist to localStorage
|
||||||
|
|
||||||
// Clean up old notified tasks (older than 1 hour) to allow re-notification if needed
|
// Clean up old notified tasks (older than 1 hour) to allow re-notification if needed
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
notifiedTaskIdsRef.current.delete(task.id);
|
notifiedTaskIdsRef.current.delete(task.id);
|
||||||
|
saveNotifiedTaskIds(); // Update localStorage after cleanup
|
||||||
}, 60 * 60 * 1000); // 1 hour
|
}, 60 * 60 * 1000); // 1 hour
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user