Notifications corrections
This commit is contained in:
parent
7797c77639
commit
424c283653
@ -5,6 +5,9 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { RefreshCw, Calendar as CalendarIcon } from "lucide-react";
|
import { RefreshCw, Calendar as CalendarIcon } from "lucide-react";
|
||||||
import { useRouter } from "next/navigation";
|
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 {
|
interface Event {
|
||||||
id: string;
|
id: string;
|
||||||
@ -21,11 +24,13 @@ export function Calendar() {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { data: session, status } = useSession();
|
||||||
|
|
||||||
const fetchEvents = async () => {
|
const fetchEvents = async (forceRefresh: boolean = false) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
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) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch events');
|
throw new Error('Failed to fetch events');
|
||||||
}
|
}
|
||||||
@ -151,9 +156,23 @@ export function Calendar() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Initial fetch on mount
|
||||||
useEffect(() => {
|
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 formatDate = (dateString: string) => {
|
||||||
const date = new Date(dateString);
|
const date = new Date(dateString);
|
||||||
@ -181,7 +200,7 @@ export function Calendar() {
|
|||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => fetchEvents()}
|
onClick={() => fetchEvents(true)}
|
||||||
className="h-7 w-7 p-0 hover:bg-gray-100/50 rounded-full"
|
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" />
|
<RefreshCw className="h-3.5 w-3.5 text-gray-600" />
|
||||||
|
|||||||
@ -274,13 +274,13 @@ export function Email() {
|
|||||||
// Integrate unified refresh for automatic polling
|
// Integrate unified refresh for automatic polling
|
||||||
const { refresh } = useUnifiedRefresh({
|
const { refresh } = useUnifiedRefresh({
|
||||||
resource: 'email',
|
resource: 'email',
|
||||||
interval: REFRESH_INTERVALS.EMAIL, // 1 minute
|
interval: REFRESH_INTERVALS.EMAIL, // 30 seconds (harmonized)
|
||||||
enabled: status === 'authenticated',
|
enabled: status === 'authenticated',
|
||||||
onRefresh: async () => {
|
onRefresh: async () => {
|
||||||
await fetchEmails(false); // Use cache for auto-refresh
|
await fetchEmails(false); // Use cache for auto-refresh
|
||||||
await fetchUnreadCount();
|
await fetchUnreadCount();
|
||||||
},
|
},
|
||||||
priority: 'medium',
|
priority: 'high',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Manual refresh handler (bypasses cache)
|
// Manual refresh handler (bypasses cache)
|
||||||
|
|||||||
@ -303,12 +303,12 @@ export function Duties() {
|
|||||||
// Integrate unified refresh for automatic polling
|
// Integrate unified refresh for automatic polling
|
||||||
const { refresh } = useUnifiedRefresh({
|
const { refresh } = useUnifiedRefresh({
|
||||||
resource: 'duties',
|
resource: 'duties',
|
||||||
interval: REFRESH_INTERVALS.DUTIES, // 2 minutes
|
interval: REFRESH_INTERVALS.DUTIES, // 30 seconds (harmonized)
|
||||||
enabled: status === 'authenticated',
|
enabled: status === 'authenticated',
|
||||||
onRefresh: async () => {
|
onRefresh: async () => {
|
||||||
await fetchTasks(false); // Use cache for auto-refresh
|
await fetchTasks(false); // Use cache for auto-refresh
|
||||||
},
|
},
|
||||||
priority: 'medium',
|
priority: 'high',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Manual refresh handler (bypasses cache)
|
// Manual refresh handler (bypasses cache)
|
||||||
|
|||||||
@ -7,18 +7,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const REFRESH_INTERVALS = {
|
export const REFRESH_INTERVALS = {
|
||||||
// High priority - real-time updates
|
// High priority - real-time updates (harmonized to 30 seconds)
|
||||||
NOTIFICATIONS: 30000, // 30 seconds (reduced from 60s for better UX)
|
NOTIFICATIONS: 30000, // 30 seconds
|
||||||
NOTIFICATIONS_COUNT: 30000, // 30 seconds (synchronized with notifications)
|
NOTIFICATIONS_COUNT: 30000, // 30 seconds (synchronized with notifications)
|
||||||
PAROLE: 30000, // 30 seconds (chat messages - unchanged)
|
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)
|
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
|
// 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)
|
NEWS: 600000, // 10 minutes (was manual only - now auto-refresh)
|
||||||
|
|
||||||
// Minimum interval between refreshes (prevents spam)
|
// Minimum interval between refreshes (prevents spam)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user