Spaces:
Running
Running
Improve calendar filters
Browse files- src/pages/Calendar.tsx +56 -21
src/pages/Calendar.tsx
CHANGED
@@ -91,17 +91,23 @@ const CalendarPage = () => {
|
|
91 |
conf.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
92 |
(conf.full_name && conf.full_name.toLowerCase().includes(searchQuery.toLowerCase()));
|
93 |
|
94 |
-
const matchesCategory = selectedCategories.size === 0 ||
|
95 |
-
(Array.isArray(conf.tags) && conf.tags.some(tag => selectedCategories.has(tag)));
|
96 |
-
|
97 |
-
if (!matchesSearch || !matchesCategory) return false;
|
98 |
-
|
99 |
const deadlineDate = safeParseISO(conf.deadline);
|
100 |
const startDate = safeParseISO(conf.start);
|
101 |
const endDate = safeParseISO(conf.end);
|
102 |
|
103 |
const dateMatches = isYearView ? isSameYear : isSameMonth;
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
const deadlineInPeriod = showDeadlines && deadlineDate && dateMatches(deadlineDate, date);
|
106 |
|
107 |
let conferenceInPeriod = false;
|
@@ -125,25 +131,49 @@ const CalendarPage = () => {
|
|
125 |
const getDayEvents = (date: Date) => {
|
126 |
const deadlines = showDeadlines ? conferencesData.filter(conf => {
|
127 |
const deadlineDate = safeParseISO(conf.deadline);
|
128 |
-
const
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
}) : [];
|
132 |
|
133 |
-
const conferences = conferencesData.filter(conf => {
|
134 |
const startDate = safeParseISO(conf.start);
|
135 |
const endDate = safeParseISO(conf.end);
|
136 |
-
const matchesCategory =
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
return {
|
145 |
-
deadlines,
|
146 |
-
conferences
|
147 |
};
|
148 |
};
|
149 |
|
@@ -176,11 +206,17 @@ const CalendarPage = () => {
|
|
176 |
const isStartOfWeek = (date: Date) => date.getDay() === 0; // Sunday
|
177 |
|
178 |
const getConferenceLineStyle = (date: Date) => {
|
|
|
|
|
|
|
|
|
|
|
179 |
return conferencesData
|
180 |
.filter(conf => {
|
181 |
const startDate = safeParseISO(conf.start);
|
182 |
const endDate = safeParseISO(conf.end);
|
183 |
-
|
|
|
184 |
(Array.isArray(conf.tags) && conf.tags.some(tag => selectedCategories.has(tag)));
|
185 |
return startDate && endDate && date >= startDate && date <= endDate && matchesCategory;
|
186 |
})
|
@@ -202,8 +238,7 @@ const CalendarPage = () => {
|
|
202 |
const color = conf.tags && conf.tags[0] ? categoryColors[conf.tags[0]] : "bg-gray-500";
|
203 |
|
204 |
return { style, color };
|
205 |
-
})
|
206 |
-
.filter(Boolean);
|
207 |
};
|
208 |
|
209 |
const renderDayContent = (date: Date) => {
|
|
|
91 |
conf.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
92 |
(conf.full_name && conf.full_name.toLowerCase().includes(searchQuery.toLowerCase()));
|
93 |
|
|
|
|
|
|
|
|
|
|
|
94 |
const deadlineDate = safeParseISO(conf.deadline);
|
95 |
const startDate = safeParseISO(conf.start);
|
96 |
const endDate = safeParseISO(conf.end);
|
97 |
|
98 |
const dateMatches = isYearView ? isSameYear : isSameMonth;
|
99 |
|
100 |
+
// If showing deadlines and no categories selected, only show deadlines
|
101 |
+
if (showDeadlines && selectedCategories.size === 0) {
|
102 |
+
return deadlineDate && dateMatches(deadlineDate, date) && matchesSearch;
|
103 |
+
}
|
104 |
+
|
105 |
+
// Otherwise, check for category matches and show both deadlines and conference dates
|
106 |
+
const matchesCategory = Array.isArray(conf.tags) &&
|
107 |
+
conf.tags.some(tag => selectedCategories.has(tag));
|
108 |
+
|
109 |
+
if (!matchesSearch || !matchesCategory) return false;
|
110 |
+
|
111 |
const deadlineInPeriod = showDeadlines && deadlineDate && dateMatches(deadlineDate, date);
|
112 |
|
113 |
let conferenceInPeriod = false;
|
|
|
131 |
const getDayEvents = (date: Date) => {
|
132 |
const deadlines = showDeadlines ? conferencesData.filter(conf => {
|
133 |
const deadlineDate = safeParseISO(conf.deadline);
|
134 |
+
const matchesSearch = searchQuery === "" ||
|
135 |
+
conf.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
136 |
+
(conf.full_name && conf.full_name.toLowerCase().includes(searchQuery.toLowerCase()));
|
137 |
+
|
138 |
+
// If no categories selected, show all deadlines
|
139 |
+
if (selectedCategories.size === 0) {
|
140 |
+
return deadlineDate && isSameDay(deadlineDate, date) && matchesSearch;
|
141 |
+
}
|
142 |
+
|
143 |
+
// Otherwise, filter by selected categories
|
144 |
+
const matchesCategory = Array.isArray(conf.tags) &&
|
145 |
+
conf.tags.some(tag => selectedCategories.has(tag));
|
146 |
+
return deadlineDate && isSameDay(deadlineDate, date) && matchesCategory && matchesSearch;
|
147 |
}) : [];
|
148 |
|
149 |
+
const conferences = selectedCategories.size > 0 ? conferencesData.filter(conf => {
|
150 |
const startDate = safeParseISO(conf.start);
|
151 |
const endDate = safeParseISO(conf.end);
|
152 |
+
const matchesCategory = Array.isArray(conf.tags) &&
|
153 |
+
conf.tags.some(tag => selectedCategories.has(tag));
|
154 |
+
const matchesSearch = searchQuery === "" ||
|
155 |
+
conf.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
156 |
+
(conf.full_name && conf.full_name.toLowerCase().includes(searchQuery.toLowerCase()));
|
157 |
+
|
158 |
+
if (!matchesCategory || !matchesSearch) return false;
|
159 |
+
|
160 |
+
if (startDate && endDate) {
|
161 |
+
let currentDate = new Date(startDate);
|
162 |
+
while (currentDate <= endDate) {
|
163 |
+
if (isSameDay(currentDate, date)) {
|
164 |
+
return true;
|
165 |
+
}
|
166 |
+
currentDate.setDate(currentDate.getDate() + 1);
|
167 |
+
}
|
168 |
+
} else if (startDate) {
|
169 |
+
return isSameDay(startDate, date);
|
170 |
+
}
|
171 |
+
return false;
|
172 |
+
}) : [];
|
173 |
|
174 |
return {
|
175 |
+
deadlines: deadlines,
|
176 |
+
conferences: conferences
|
177 |
};
|
178 |
};
|
179 |
|
|
|
206 |
const isStartOfWeek = (date: Date) => date.getDay() === 0; // Sunday
|
207 |
|
208 |
const getConferenceLineStyle = (date: Date) => {
|
209 |
+
// If only showing deadlines and no categories are selected, don't show any conference lines
|
210 |
+
if (selectedCategories.size === 0 && showDeadlines) {
|
211 |
+
return [];
|
212 |
+
}
|
213 |
+
|
214 |
return conferencesData
|
215 |
.filter(conf => {
|
216 |
const startDate = safeParseISO(conf.start);
|
217 |
const endDate = safeParseISO(conf.end);
|
218 |
+
// Only show conference dates if categories are selected
|
219 |
+
const matchesCategory = selectedCategories.size > 0 &&
|
220 |
(Array.isArray(conf.tags) && conf.tags.some(tag => selectedCategories.has(tag)));
|
221 |
return startDate && endDate && date >= startDate && date <= endDate && matchesCategory;
|
222 |
})
|
|
|
238 |
const color = conf.tags && conf.tags[0] ? categoryColors[conf.tags[0]] : "bg-gray-500";
|
239 |
|
240 |
return { style, color };
|
241 |
+
});
|
|
|
242 |
};
|
243 |
|
244 |
const renderDayContent = (date: Date) => {
|