Fondation
This commit is contained in:
parent
bda8eb896a
commit
4882dcff35
@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useRef, useMemo } from "react";
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { format, isToday, isTomorrow, addDays } from "date-fns";
|
||||
import { fr } from "date-fns/locale";
|
||||
import { CalendarIcon, ChevronRight } from "lucide-react";
|
||||
@ -22,29 +22,23 @@ type Event = {
|
||||
};
|
||||
|
||||
export function CalendarWidget() {
|
||||
const { data: session, status } = useSession();
|
||||
const [events, setEvents] = useState<Event[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { triggerNotification } = useWidgetNotification();
|
||||
const lastEventCountRef = useRef<number>(-1);
|
||||
|
||||
// Declare useSession after other hooks to avoid TypeScript scope analysis issues
|
||||
const sessionResult = useSession();
|
||||
|
||||
useEffect(() => {
|
||||
// Capture values from sessionResult inside useEffect to avoid scope issues
|
||||
const currentSession = sessionResult.data;
|
||||
const currentStatus = sessionResult.status;
|
||||
console.log("Calendar Widget - Session Status:", status);
|
||||
console.log("Calendar Widget - Session Data:", session);
|
||||
|
||||
console.log("Calendar Widget - Session Status:", currentStatus);
|
||||
console.log("Calendar Widget - Session Data:", currentSession);
|
||||
|
||||
if (currentStatus === "loading") {
|
||||
if (status === "loading") {
|
||||
console.log("Calendar Widget - Session is loading");
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentStatus !== "authenticated" || !currentSession) {
|
||||
if (status !== "authenticated" || !session) {
|
||||
console.log("Calendar Widget - Not authenticated, skipping fetch");
|
||||
setLoading(false);
|
||||
return;
|
||||
@ -205,7 +199,7 @@ export function CalendarWidget() {
|
||||
}, 300000);
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}, [sessionResult.data, sessionResult.status, triggerNotification]);
|
||||
}, [session, status, triggerNotification]);
|
||||
|
||||
const formatEventDate = (date: Date, isAllDay: boolean) => {
|
||||
let dateString = "";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user