gpt-engineer-app[bot] commited on
Commit
f09e08a
·
1 Parent(s): 2b96622

Fix calendar event line rendering

Browse files

The calendar event lines were overlapping days of different, non-consecutive months. This commit addresses the rendering issue.

Files changed (1) hide show
  1. src/pages/Calendar.tsx +10 -9
src/pages/Calendar.tsx CHANGED
@@ -189,25 +189,26 @@ const CalendarPage = () => {
189
  const startDate = safeParseISO(conf.start);
190
  const endDate = safeParseISO(conf.end);
191
 
192
- if (startDate && !isSameDay(startDate, day)) {
193
  return null;
194
  }
195
 
196
  const categoryColor = conf.tags?.[0] ? categoryColors[conf.tags[0]] || "bg-purple-600" : "bg-purple-600";
197
 
198
- let width = "w-full";
199
- if (startDate && endDate) {
200
- const daysBetween = Math.ceil((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24));
201
- width = `w-[calc(100%_*_${daysBetween})]`;
 
 
 
202
  }
203
 
204
  return (
205
  <div
206
  key={conf.id}
207
- className={`h-0.5 ${categoryColor} absolute ${width} -mr-[1px]`}
208
- style={{
209
- width: startDate && endDate ? `calc(100% * ${Math.ceil((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24))})` : '100%'
210
- }}
211
  title={conf.title}
212
  />
213
  );
 
189
  const startDate = safeParseISO(conf.start);
190
  const endDate = safeParseISO(conf.end);
191
 
192
+ if (!startDate || !isSameDay(startDate, day)) {
193
  return null;
194
  }
195
 
196
  const categoryColor = conf.tags?.[0] ? categoryColors[conf.tags[0]] || "bg-purple-600" : "bg-purple-600";
197
 
198
+ let width = '100%';
199
+ if (endDate) {
200
+ const lastDayOfMonth = new Date(day.getFullYear(), day.getMonth() + 1, 0);
201
+ const effectiveEndDate = endDate < lastDayOfMonth ? endDate : lastDayOfMonth;
202
+
203
+ const daysBetween = Math.ceil((effectiveEndDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24)) + 1;
204
+ width = `calc(100% * ${daysBetween})`;
205
  }
206
 
207
  return (
208
  <div
209
  key={conf.id}
210
+ className={`h-0.5 ${categoryColor} absolute`}
211
+ style={{ width }}
 
 
212
  title={conf.title}
213
  />
214
  );