Spaces:
Sleeping
Sleeping
gpt-engineer-app[bot]
commited on
Commit
·
6fe328e
1
Parent(s):
f4d9004
Fix calendar events display
Browse filesThe calendar was displaying events for the wrong month. This commit fixes the issue.
- src/pages/Calendar.tsx +30 -28
src/pages/Calendar.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import { useState } from "react";
|
| 2 |
import conferencesData from "@/data/conferences.yml";
|
| 3 |
import { Conference } from "@/types/conference";
|
|
@@ -8,6 +9,7 @@ import { parseISO, format, isValid, isSameMonth } from "date-fns";
|
|
| 8 |
const CalendarPage = () => {
|
| 9 |
const [selectedDate, setSelectedDate] = useState<Date | undefined>(new Date());
|
| 10 |
|
|
|
|
| 11 |
const safeParseISO = (dateString: string | undefined | number): Date | null => {
|
| 12 |
if (!dateString || dateString === 'TBD') return null;
|
| 13 |
|
|
@@ -25,19 +27,37 @@ const CalendarPage = () => {
|
|
| 25 |
}
|
| 26 |
};
|
| 27 |
|
|
|
|
| 28 |
const getMonthEvents = (date: Date) => {
|
| 29 |
return conferencesData.filter((conf: Conference) => {
|
| 30 |
const deadlineDate = safeParseISO(conf.deadline);
|
| 31 |
const startDate = safeParseISO(conf.start);
|
| 32 |
const endDate = safeParseISO(conf.end);
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
});
|
| 39 |
};
|
| 40 |
|
|
|
|
| 41 |
const getDatesWithEvents = () => {
|
| 42 |
const dates = {
|
| 43 |
conferences: new Set<string>(),
|
|
@@ -54,10 +74,10 @@ const CalendarPage = () => {
|
|
| 54 |
}
|
| 55 |
|
| 56 |
if (startDate && endDate) {
|
| 57 |
-
let currentDate = startDate;
|
| 58 |
while (currentDate <= endDate) {
|
| 59 |
dates.conferences.add(format(currentDate, 'yyyy-MM-dd'));
|
| 60 |
-
currentDate
|
| 61 |
}
|
| 62 |
} else if (startDate) {
|
| 63 |
dates.conferences.add(format(startDate, 'yyyy-MM-dd'));
|
|
@@ -70,27 +90,6 @@ const CalendarPage = () => {
|
|
| 70 |
};
|
| 71 |
};
|
| 72 |
|
| 73 |
-
const getConferencesForDate = (date: Date) => {
|
| 74 |
-
const formattedDate = format(date, 'yyyy-MM-dd');
|
| 75 |
-
return conferencesData.filter((conf: Conference) => {
|
| 76 |
-
const deadlineDate = safeParseISO(conf.deadline);
|
| 77 |
-
const startDate = safeParseISO(conf.start);
|
| 78 |
-
const endDate = safeParseISO(conf.end);
|
| 79 |
-
|
| 80 |
-
const deadlineDateStr = deadlineDate ? format(deadlineDate, 'yyyy-MM-dd') : null;
|
| 81 |
-
const isDeadlineMatch = deadlineDateStr === formattedDate;
|
| 82 |
-
|
| 83 |
-
let isConferenceDate = false;
|
| 84 |
-
if (startDate && endDate) {
|
| 85 |
-
isConferenceDate = date >= startDate && date <= endDate;
|
| 86 |
-
} else if (startDate) {
|
| 87 |
-
isConferenceDate = format(startDate, 'yyyy-MM-dd') === formattedDate;
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
return isDeadlineMatch || isConferenceDate;
|
| 91 |
-
});
|
| 92 |
-
};
|
| 93 |
-
|
| 94 |
const monthEvents = selectedDate ? getMonthEvents(selectedDate) : [];
|
| 95 |
const datesWithEvents = getDatesWithEvents();
|
| 96 |
|
|
@@ -122,7 +121,10 @@ const CalendarPage = () => {
|
|
| 122 |
month: "space-y-4 w-full",
|
| 123 |
caption: "flex justify-center pt-1 relative items-center mb-4",
|
| 124 |
caption_label: "text-lg font-semibold",
|
| 125 |
-
table: "w-full border-collapse",
|
|
|
|
|
|
|
|
|
|
| 126 |
cell: "h-14 w-14 text-center text-sm p-0 relative [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",
|
| 127 |
day: "h-14 w-14 p-0 font-normal aria-selected:opacity-100 hover:bg-neutral-100 rounded-lg transition-colors",
|
| 128 |
day_today: "bg-neutral-100 text-primary font-semibold",
|
|
|
|
| 1 |
+
|
| 2 |
import { useState } from "react";
|
| 3 |
import conferencesData from "@/data/conferences.yml";
|
| 4 |
import { Conference } from "@/types/conference";
|
|
|
|
| 9 |
const CalendarPage = () => {
|
| 10 |
const [selectedDate, setSelectedDate] = useState<Date | undefined>(new Date());
|
| 11 |
|
| 12 |
+
// Helper function to safely parse dates
|
| 13 |
const safeParseISO = (dateString: string | undefined | number): Date | null => {
|
| 14 |
if (!dateString || dateString === 'TBD') return null;
|
| 15 |
|
|
|
|
| 27 |
}
|
| 28 |
};
|
| 29 |
|
| 30 |
+
// Get all events (conferences and deadlines) for a given month
|
| 31 |
const getMonthEvents = (date: Date) => {
|
| 32 |
return conferencesData.filter((conf: Conference) => {
|
| 33 |
const deadlineDate = safeParseISO(conf.deadline);
|
| 34 |
const startDate = safeParseISO(conf.start);
|
| 35 |
const endDate = safeParseISO(conf.end);
|
| 36 |
|
| 37 |
+
// Check if deadline is in the selected month
|
| 38 |
+
const deadlineInMonth = deadlineDate && isSameMonth(deadlineDate, date);
|
| 39 |
+
|
| 40 |
+
// Check if any part of the conference falls in the selected month
|
| 41 |
+
let conferenceInMonth = false;
|
| 42 |
+
if (startDate && endDate) {
|
| 43 |
+
// For multi-day conferences, check if any day falls in the selected month
|
| 44 |
+
let currentDate = new Date(startDate);
|
| 45 |
+
while (currentDate <= endDate) {
|
| 46 |
+
if (isSameMonth(currentDate, date)) {
|
| 47 |
+
conferenceInMonth = true;
|
| 48 |
+
break;
|
| 49 |
+
}
|
| 50 |
+
currentDate.setDate(currentDate.getDate() + 1);
|
| 51 |
+
}
|
| 52 |
+
} else if (startDate) {
|
| 53 |
+
conferenceInMonth = isSameMonth(startDate, date);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
return deadlineInMonth || conferenceInMonth;
|
| 57 |
});
|
| 58 |
};
|
| 59 |
|
| 60 |
+
// Get all unique dates (deadlines and conference dates)
|
| 61 |
const getDatesWithEvents = () => {
|
| 62 |
const dates = {
|
| 63 |
conferences: new Set<string>(),
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
if (startDate && endDate) {
|
| 77 |
+
let currentDate = new Date(startDate);
|
| 78 |
while (currentDate <= endDate) {
|
| 79 |
dates.conferences.add(format(currentDate, 'yyyy-MM-dd'));
|
| 80 |
+
currentDate.setDate(currentDate.getDate() + 1);
|
| 81 |
}
|
| 82 |
} else if (startDate) {
|
| 83 |
dates.conferences.add(format(startDate, 'yyyy-MM-dd'));
|
|
|
|
| 90 |
};
|
| 91 |
};
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
const monthEvents = selectedDate ? getMonthEvents(selectedDate) : [];
|
| 94 |
const datesWithEvents = getDatesWithEvents();
|
| 95 |
|
|
|
|
| 121 |
month: "space-y-4 w-full",
|
| 122 |
caption: "flex justify-center pt-1 relative items-center mb-4",
|
| 123 |
caption_label: "text-lg font-semibold",
|
| 124 |
+
table: "w-full border-collapse space-y-1",
|
| 125 |
+
head_row: "flex",
|
| 126 |
+
head_cell: "text-muted-foreground rounded-md w-14 font-normal text-[0.8rem]",
|
| 127 |
+
row: "flex w-full mt-2",
|
| 128 |
cell: "h-14 w-14 text-center text-sm p-0 relative [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",
|
| 129 |
day: "h-14 w-14 p-0 font-normal aria-selected:opacity-100 hover:bg-neutral-100 rounded-lg transition-colors",
|
| 130 |
day_today: "bg-neutral-100 text-primary font-semibold",
|