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