Notifications corrections

This commit is contained in:
alma 2026-01-16 10:40:23 +01:00
parent 7797c77639
commit 424c283653
4 changed files with 35 additions and 18 deletions

View File

@ -5,6 +5,9 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { RefreshCw, Calendar as CalendarIcon } from "lucide-react";
import { useRouter } from "next/navigation";
import { useSession } from "next-auth/react";
import { useUnifiedRefresh } from "@/hooks/use-unified-refresh";
import { REFRESH_INTERVALS } from "@/lib/constants/refresh-intervals";
interface Event {
id: string;
@ -21,11 +24,13 @@ export function Calendar() {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const router = useRouter();
const { data: session, status } = useSession();
const fetchEvents = async () => {
const fetchEvents = async (forceRefresh: boolean = false) => {
setLoading(true);
try {
const response = await fetch('/api/calendars?refresh=true');
const url = forceRefresh ? '/api/calendars?refresh=true' : '/api/calendars';
const response = await fetch(url);
if (!response.ok) {
throw new Error('Failed to fetch events');
}
@ -151,9 +156,23 @@ export function Calendar() {
}
};
// Initial fetch on mount
useEffect(() => {
fetchEvents();
}, []);
if (status === 'authenticated') {
fetchEvents(true); // Force refresh on initial load
}
}, [status]);
// Integrate unified refresh for automatic polling
const { refresh } = useUnifiedRefresh({
resource: 'calendar',
interval: REFRESH_INTERVALS.CALENDAR, // 30 seconds (harmonized)
enabled: status === 'authenticated',
onRefresh: async () => {
await fetchEvents(false); // Use cache for auto-refresh
},
priority: 'high',
});
const formatDate = (dateString: string) => {
const date = new Date(dateString);
@ -181,7 +200,7 @@ export function Calendar() {
<Button
variant="ghost"
size="icon"
onClick={() => fetchEvents()}
onClick={() => fetchEvents(true)}
className="h-7 w-7 p-0 hover:bg-gray-100/50 rounded-full"
>
<RefreshCw className="h-3.5 w-3.5 text-gray-600" />

View File

@ -274,13 +274,13 @@ export function Email() {
// Integrate unified refresh for automatic polling
const { refresh } = useUnifiedRefresh({
resource: 'email',
interval: REFRESH_INTERVALS.EMAIL, // 1 minute
interval: REFRESH_INTERVALS.EMAIL, // 30 seconds (harmonized)
enabled: status === 'authenticated',
onRefresh: async () => {
await fetchEmails(false); // Use cache for auto-refresh
await fetchUnreadCount();
},
priority: 'medium',
priority: 'high',
});
// Manual refresh handler (bypasses cache)

View File

@ -303,12 +303,12 @@ export function Duties() {
// Integrate unified refresh for automatic polling
const { refresh } = useUnifiedRefresh({
resource: 'duties',
interval: REFRESH_INTERVALS.DUTIES, // 2 minutes
interval: REFRESH_INTERVALS.DUTIES, // 30 seconds (harmonized)
enabled: status === 'authenticated',
onRefresh: async () => {
await fetchTasks(false); // Use cache for auto-refresh
},
priority: 'medium',
priority: 'high',
});
// Manual refresh handler (bypasses cache)

View File

@ -7,18 +7,16 @@
*/
export const REFRESH_INTERVALS = {
// High priority - real-time updates
NOTIFICATIONS: 30000, // 30 seconds (reduced from 60s for better UX)
NOTIFICATIONS_COUNT: 30000, // 30 seconds (synchronized with notifications)
PAROLE: 30000, // 30 seconds (chat messages - unchanged)
// High priority - real-time updates (harmonized to 30 seconds)
NOTIFICATIONS: 30000, // 30 seconds
NOTIFICATIONS_COUNT: 30000, // 30 seconds (synchronized with notifications)
PAROLE: 30000, // 30 seconds (chat messages)
EMAIL: 30000, // 30 seconds (harmonized from 1 minute)
DUTIES: 30000, // 30 seconds (harmonized from 2 minutes)
CALENDAR: 30000, // 30 seconds (harmonized from 5 minutes)
NAVBAR_TIME: 1000, // 1 second (navigation bar time display - real-time)
// Medium priority - frequent but not real-time
EMAIL: 60000, // 1 minute (was manual only - now auto-refresh)
DUTIES: 120000, // 2 minutes (was manual only - now auto-refresh)
// Low priority - less frequent updates
CALENDAR: 300000, // 5 minutes (unchanged - calendar events don't change often)
NEWS: 600000, // 10 minutes (was manual only - now auto-refresh)
// Minimum interval between refreshes (prevents spam)