Skip to content

Commit

Permalink
Fix: earliest time range for initial scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
forabi committed Mar 23, 2019
1 parent 5fa6877 commit 3f79fa1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/components/TimeGridScheduler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
RecurringTimeRange,
} from '../utils/createMapCellInfoToRecurringTimeRange';
import { createMapDateRangeToCells } from '../utils/createMapDateRangeToCells';
import { getEarliestRange } from '../utils/getEarliestRange';
import { getEarliestTimeRange } from '../utils/getEarliestTimeRange';
import { getSpan } from '../utils/getSpan';
import { mergeEvents, mergeRanges } from '../utils/mergeEvents';
import { Cell } from './Cell';
Expand Down Expand Up @@ -328,7 +328,7 @@ export const TimeGridScheduler = React.memo(function TimeGridScheduler({
}

const range = dateRangeToCells(
getEarliestRange(schedule) || [
getEarliestTimeRange(schedule) || [
addHours(originDate, defaultHours[0]),
addHours(originDate, defaultHours[1]),
],
Expand Down
8 changes: 0 additions & 8 deletions src/utils/getEarliestRange.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/utils/getEarliestTimeRange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import compareDesc from 'date-fns/compare_desc';
import setDay from 'date-fns/set_day';
import { DateRange } from '../types';

export function getEarliestTimeRange(
ranges: DateRange[],
): DateRange | undefined {
return [...ranges].sort(([startA], [startB]) =>
compareDesc(setDay(startA, 0), setDay(startB, 0)),
)[0];
}

0 comments on commit 3f79fa1

Please sign in to comment.