Skip to content

Commit

Permalink
fix: events disappear when start/end dates are out of grid bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
slash-84 committed Apr 25, 2024
1 parent c7d5ca0 commit 5899125
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/lib/components/events/TodayEvents.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fragment } from "react";
import { ProcessedEvent } from "../../types";
import EventItem from "./EventItem";
import { differenceInMinutes } from "date-fns";
import { differenceInMinutes, setHours } from "date-fns";

Check warning on line 4 in src/lib/components/events/TodayEvents.tsx

View workflow job for this annotation

GitHub Actions / Install (16.x)

'setHours' is defined but never used

Check warning on line 4 in src/lib/components/events/TodayEvents.tsx

View workflow job for this annotation

GitHub Actions / Install (18.x)

'setHours' is defined but never used
import { isTimeZonedToday, traversCrossingEvents } from "../../helpers/generals";
import { BORDER_HEIGHT } from "../../helpers/constants";
import CurrentTimeBar from "./CurrentTimeBar";
Expand All @@ -10,6 +10,7 @@ interface TodayEventsProps {
todayEvents: ProcessedEvent[];
today: Date;
startHour: number;
endHour: number;
step: number;
minuteHeight: number;
direction: "rtl" | "ltr";
Expand All @@ -19,6 +20,7 @@ const TodayEvents = ({
todayEvents,
today,
startHour,
endHour,
step,
minuteHeight,
direction,
Expand All @@ -39,10 +41,13 @@ const TodayEvents = ({
)}

{todayEvents.map((event, i) => {
const height = differenceInMinutes(event.end, event.start) * minuteHeight - BORDER_HEIGHT;
const maxHeight = (endHour * 60 - startHour * 60) * minuteHeight;
const eventHeight = differenceInMinutes(event.end, event.start) * minuteHeight;
const height = Math.min(eventHeight, maxHeight) - BORDER_HEIGHT;

const calendarStartInMins = startHour * 60;
const eventStartInMins = event.start.getHours() * 60 + event.start.getMinutes();
const minituesFromTop = Math.abs(calendarStartInMins - eventStartInMins);
const minituesFromTop = Math.max(eventStartInMins - calendarStartInMins, 0);

const topSpace = minituesFromTop * minuteHeight;
/** Add border factor to height of each slot */
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/week/WeekTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const WeekTable = ({
timeZone,
stickyNavigation,
} = useStore();
const { startHour, step, cellRenderer, disableGoToDay, headRenderer, hourRenderer } = week!;
const { startHour, endHour, step, cellRenderer, disableGoToDay, headRenderer, hourRenderer } =
week!;
const { renderedSlots } = usePosition();
const { headersRef, bodyRef } = useSyncScroll();
const MULTI_SPACE = MULTI_DAY_EVENT_HEIGHT;
Expand Down Expand Up @@ -177,6 +178,7 @@ const WeekTable = ({
today={date}
minuteHeight={minutesHeight}
startHour={startHour}
endHour={endHour}
step={step}
direction={direction}
timeZone={timeZone}
Expand Down
1 change: 1 addition & 0 deletions src/lib/views/Day.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const Day = () => {
today={START_TIME}
minuteHeight={MINUTE_HEIGHT}
startHour={startHour}
endHour={endHour}
step={step}
direction={direction}
timeZone={timeZone}
Expand Down

0 comments on commit 5899125

Please sign in to comment.