gpt-engineer-app[bot] commited on
Commit
7cc30be
·
1 Parent(s): 50f641f

Fix: Type errors in ConferenceDialog and Calendar

Browse files

The commit addresses type errors related to `instanceof` expressions in `ConferenceDialog.tsx` and `Calendar.tsx`. These errors were causing compilation failures.

src/components/ConferenceDialog.tsx CHANGED
@@ -63,8 +63,12 @@ const ConferenceDialog = ({ conference, open, onOpenChange }: ConferenceDialogPr
63
 
64
  // Primary: Use start and end fields
65
  if (conference.start && conference.end) {
66
- // If the dates are already Date objects, use them directly
67
- if (conference.start instanceof Date && conference.end instanceof Date) {
 
 
 
 
68
  startDate = conference.start;
69
  endDate = conference.end;
70
  } else {
 
63
 
64
  // Primary: Use start and end fields
65
  if (conference.start && conference.end) {
66
+ // Check if the dates are Date objects using a type guard
67
+ const isDate = (value: any): value is Date => {
68
+ return value && Object.prototype.toString.call(value) === '[object Date]';
69
+ };
70
+
71
+ if (isDate(conference.start) && isDate(conference.end)) {
72
  startDate = conference.start;
73
  endDate = conference.end;
74
  } else {
src/pages/Calendar.tsx CHANGED
@@ -57,9 +57,12 @@ const CalendarPage = () => {
57
  const safeParseISO = (dateString: string | undefined | number): Date | null => {
58
  if (!dateString) return null;
59
  if (dateString === 'TBD') return null;
 
 
 
 
60
 
61
- // If it's already a Date object, return it
62
- if (dateString instanceof Date) return dateString;
63
 
64
  try {
65
  if (typeof dateString === 'object') {
@@ -169,11 +172,9 @@ const CalendarPage = () => {
169
  );
170
  };
171
 
172
- // Add these helper functions at the top of the file
173
  const isEndOfWeek = (date: Date) => date.getDay() === 6; // Saturday
174
  const isStartOfWeek = (date: Date) => date.getDay() === 0; // Sunday
175
 
176
- // Update the getConferenceLineStyle function
177
  const getConferenceLineStyle = (date: Date) => {
178
  return conferencesData
179
  .filter(conf => {
@@ -191,7 +192,6 @@ const CalendarPage = () => {
191
 
192
  let style = "w-[calc(100%+1rem)] -left-2 relative";
193
 
194
- // Add specific styles for start, middle, and end days
195
  if (isSameDay(date, startDate)) {
196
  style += " rounded-l-sm";
197
  }
@@ -199,7 +199,6 @@ const CalendarPage = () => {
199
  style += " rounded-r-sm";
200
  }
201
 
202
- // Get the color based on the first tag
203
  const color = conf.tags && conf.tags[0] ? categoryColors[conf.tags[0]] : "bg-gray-500";
204
 
205
  return { style, color };
@@ -207,15 +206,12 @@ const CalendarPage = () => {
207
  .filter(Boolean);
208
  };
209
 
210
- // Update the renderDayContent function
211
  const renderDayContent = (date: Date) => {
212
  const dayEvents = getDayEvents(date);
213
  const hasEvents = dayEvents.deadlines.length > 0 || dayEvents.conferences.length > 0;
214
 
215
- // Get conference line styles first
216
  const conferenceStyles = getConferenceLineStyle(date);
217
 
218
- // Get deadline style
219
  const hasDeadline = showDeadlines && dayEvents.deadlines.length > 0;
220
 
221
  const handleDayClick = (e: React.MouseEvent) => {
@@ -232,27 +228,22 @@ const CalendarPage = () => {
232
  className="relative w-full h-full flex flex-col"
233
  onClick={handleDayClick}
234
  >
235
- {/* Day number at the top with moderate space */}
236
  <div className="h-10 flex items-center justify-center">
237
  <span>{format(date, 'd')}</span>
238
  </div>
239
 
240
- {/* Event indicator lines closer to the day number */}
241
  <div className="absolute bottom-2 left-0 right-0 flex flex-col-reverse gap-[1px]">
242
- {/* Conference lines at the bottom (rendered first) */}
243
  {conferenceStyles.map((style, index) => (
244
  <div
245
  key={`conf-${index}`}
246
  className={`h-[2px] ${style.style} ${style.color}`}
247
  />
248
  ))}
249
- {/* Deadline lines on top */}
250
  {hasDeadline && (
251
  <div className="h-[2px] w-[calc(100%+1rem)] -left-2 relative bg-red-500" />
252
  )}
253
  </div>
254
 
255
- {/* Tooltip trigger */}
256
  {hasEvents && (
257
  <TooltipProvider>
258
  <Tooltip>
@@ -423,7 +414,6 @@ const CalendarPage = () => {
423
  </TooltipProvider>
424
  ))}
425
 
426
- {/* Only show Reset when some filters are deselected */}
427
  {(selectedCategories.size < Object.keys(categoryColors).length || !showDeadlines) && (
428
  <button
429
  onClick={() => {
@@ -445,7 +435,6 @@ const CalendarPage = () => {
445
  <div className="min-h-screen bg-neutral-light">
446
  <Header onSearch={setSearchQuery} />
447
 
448
- {/* Add a search results section when there's a search query */}
449
  {searchQuery && (
450
  <div className="p-6 bg-white border-b">
451
  <div className="max-w-4xl mx-auto">
 
57
  const safeParseISO = (dateString: string | undefined | number): Date | null => {
58
  if (!dateString) return null;
59
  if (dateString === 'TBD') return null;
60
+
61
+ const isDate = (value: any): value is Date => {
62
+ return value && Object.prototype.toString.call(value) === '[object Date]';
63
+ };
64
 
65
+ if (isDate(dateString)) return dateString;
 
66
 
67
  try {
68
  if (typeof dateString === 'object') {
 
172
  );
173
  };
174
 
 
175
  const isEndOfWeek = (date: Date) => date.getDay() === 6; // Saturday
176
  const isStartOfWeek = (date: Date) => date.getDay() === 0; // Sunday
177
 
 
178
  const getConferenceLineStyle = (date: Date) => {
179
  return conferencesData
180
  .filter(conf => {
 
192
 
193
  let style = "w-[calc(100%+1rem)] -left-2 relative";
194
 
 
195
  if (isSameDay(date, startDate)) {
196
  style += " rounded-l-sm";
197
  }
 
199
  style += " rounded-r-sm";
200
  }
201
 
 
202
  const color = conf.tags && conf.tags[0] ? categoryColors[conf.tags[0]] : "bg-gray-500";
203
 
204
  return { style, color };
 
206
  .filter(Boolean);
207
  };
208
 
 
209
  const renderDayContent = (date: Date) => {
210
  const dayEvents = getDayEvents(date);
211
  const hasEvents = dayEvents.deadlines.length > 0 || dayEvents.conferences.length > 0;
212
 
 
213
  const conferenceStyles = getConferenceLineStyle(date);
214
 
 
215
  const hasDeadline = showDeadlines && dayEvents.deadlines.length > 0;
216
 
217
  const handleDayClick = (e: React.MouseEvent) => {
 
228
  className="relative w-full h-full flex flex-col"
229
  onClick={handleDayClick}
230
  >
 
231
  <div className="h-10 flex items-center justify-center">
232
  <span>{format(date, 'd')}</span>
233
  </div>
234
 
 
235
  <div className="absolute bottom-2 left-0 right-0 flex flex-col-reverse gap-[1px]">
 
236
  {conferenceStyles.map((style, index) => (
237
  <div
238
  key={`conf-${index}`}
239
  className={`h-[2px] ${style.style} ${style.color}`}
240
  />
241
  ))}
 
242
  {hasDeadline && (
243
  <div className="h-[2px] w-[calc(100%+1rem)] -left-2 relative bg-red-500" />
244
  )}
245
  </div>
246
 
 
247
  {hasEvents && (
248
  <TooltipProvider>
249
  <Tooltip>
 
414
  </TooltipProvider>
415
  ))}
416
 
 
417
  {(selectedCategories.size < Object.keys(categoryColors).length || !showDeadlines) && (
418
  <button
419
  onClick={() => {
 
435
  <div className="min-h-screen bg-neutral-light">
436
  <Header onSearch={setSearchQuery} />
437
 
 
438
  {searchQuery && (
439
  <div className="p-6 bg-white border-b">
440
  <div className="max-w-4xl mx-auto">