Neah version calendar fix 3 debuger
This commit is contained in:
parent
181bdfaf2a
commit
1198883064
@ -23,51 +23,82 @@ export function Calendar() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const fetchEvents = async () => {
|
const fetchEvents = async () => {
|
||||||
|
console.log('🔍 Calendar Widget - Starting fetchEvents');
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/calendars');
|
console.log('📡 Calendar Widget - Making API request to /api/calendars');
|
||||||
|
const response = await fetch('/api/calendars', {
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('📥 Calendar Widget - Response status:', response.status);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch events');
|
const errorText = await response.text();
|
||||||
|
console.error('❌ Calendar Widget - API Error:', {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
errorText
|
||||||
|
});
|
||||||
|
throw new Error(`Failed to fetch events: ${response.status} ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const calendarsData = await response.json();
|
const calendarsData = await response.json();
|
||||||
console.log('Calendar Widget - Fetched calendars:', calendarsData);
|
console.log('📊 Calendar Widget - Raw API Response:', calendarsData);
|
||||||
|
|
||||||
// Get current date at the start of the day
|
// Get current date at the start of the day
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
now.setHours(0, 0, 0, 0);
|
now.setHours(0, 0, 0, 0);
|
||||||
|
console.log('📅 Calendar Widget - Current date:', now.toISOString());
|
||||||
|
|
||||||
// Extract and process events from all calendars
|
// Extract and process events from all calendars
|
||||||
const allEvents = calendarsData.flatMap((calendar: any) =>
|
console.log('🔄 Calendar Widget - Processing events from calendars');
|
||||||
(calendar.events || []).map((event: any) => ({
|
const allEvents = calendarsData.flatMap((calendar: any) => {
|
||||||
id: event.id,
|
console.log(`📋 Processing calendar: ${calendar.name} (${calendar.id})`);
|
||||||
title: event.title,
|
return (calendar.events || []).map((event: any) => {
|
||||||
start: event.start,
|
console.log(`📝 Processing event: ${event.title} (${event.id})`);
|
||||||
end: event.end,
|
return {
|
||||||
allDay: event.isAllDay,
|
id: event.id,
|
||||||
calendar: calendar.name,
|
title: event.title,
|
||||||
calendarColor: calendar.color
|
start: event.start,
|
||||||
}))
|
end: event.end,
|
||||||
);
|
allDay: event.isAllDay,
|
||||||
|
calendar: calendar.name,
|
||||||
|
calendarColor: calendar.color
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('📈 Calendar Widget - Total events before filtering:', allEvents.length);
|
||||||
|
|
||||||
// Filter for upcoming events
|
// Filter for upcoming events
|
||||||
const upcomingEvents = allEvents
|
const upcomingEvents = allEvents
|
||||||
.filter((event: any) => new Date(event.start) >= now)
|
.filter((event: any) => {
|
||||||
.sort((a: any, b: any) => new Date(a.start).getTime() - new Date(b.start).getTime())
|
const eventDate = new Date(event.start);
|
||||||
|
const isUpcoming = eventDate >= now;
|
||||||
|
console.log(`⏰ Event ${event.title}: ${eventDate.toISOString()} is ${isUpcoming ? 'upcoming' : 'past'}`);
|
||||||
|
return isUpcoming;
|
||||||
|
})
|
||||||
|
.sort((a: any, b: any) => {
|
||||||
|
const dateA = new Date(a.start);
|
||||||
|
const dateB = new Date(b.start);
|
||||||
|
return dateA.getTime() - dateB.getTime();
|
||||||
|
})
|
||||||
.slice(0, 7);
|
.slice(0, 7);
|
||||||
|
|
||||||
console.log('Calendar Widget - Processed events:', upcomingEvents);
|
console.log('✅ Calendar Widget - Final processed events:', upcomingEvents);
|
||||||
setEvents(upcomingEvents);
|
setEvents(upcomingEvents);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error fetching events:', err);
|
console.error('❌ Calendar Widget - Error in fetchEvents:', err);
|
||||||
setError('Failed to load events');
|
setError(err instanceof Error ? err.message : 'Failed to load events');
|
||||||
} finally {
|
} finally {
|
||||||
|
console.log('🏁 Calendar Widget - fetchEvents completed');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log('🔄 Calendar Widget - Component mounted, fetching events');
|
||||||
fetchEvents();
|
fetchEvents();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@ -517,7 +517,9 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
const fetchCalendars = async () => {
|
const fetchCalendars = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const response = await fetch("/api/calendars");
|
const response = await fetch("/api/calendars", {
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
if (!response.ok) throw new Error("Failed to fetch calendars");
|
if (!response.ok) throw new Error("Failed to fetch calendars");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log("Raw calendars data:", data);
|
console.log("Raw calendars data:", data);
|
||||||
@ -571,6 +573,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
|
credentials: 'include',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
...calendarData,
|
...calendarData,
|
||||||
userId,
|
userId,
|
||||||
@ -596,6 +599,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const response = await fetch(`/api/calendars/${calendarId}`, {
|
const response = await fetch(`/api/calendars/${calendarId}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@ -48,7 +48,9 @@ export function CalendarWidget() {
|
|||||||
|
|
||||||
// Fetch calendars with events
|
// Fetch calendars with events
|
||||||
console.log("Calendar Widget - Making API request to /api/calendars");
|
console.log("Calendar Widget - Making API request to /api/calendars");
|
||||||
const response = await fetch('/api/calendars');
|
const response = await fetch('/api/calendars', {
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("Calendar Widget - API response not OK:", response.status, response.statusText);
|
console.error("Calendar Widget - API response not OK:", response.status, response.statusText);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user