ProSchedulerSign in

Scheduler · Configuring the view

Event buffer

bufferBefore and bufferAfter reserve travel or set-up time around an event. They draw hatched and, with overlaps off, count as busy.

Live demo

Drag the review call right after the shoot · Move it an hour later

Fullscreen
import { ProScheduler, type PschInvalid, type PschValidationFailure, type SchedulerEvent } from "@andreisaac/pro-scheduler"
import { weekStart } from "./data/studio"
import { Log, useEvents, useLog } from "./kit"

/** One line explaining why a change was refused. */
function reason(failure: PschValidationFailure) {
  return failure.reason === "invalid"
    ? `blocked (${failure.invalid?.title ?? "unavailable"})`
    : `overlaps "${failure.overlapping?.title}"`
}

export function EventBufferDemo() {
  const { events, handlers } = useEvents<SchedulerEvent>(() => {
    const monday = weekStart()
    const at = (day: number, h: number, m = 0) =>
      new Date(monday.getFullYear(), monday.getMonth(), monday.getDate() + day, h, m)
    return [
      { id: 1, title: "Site visit: Harbor", start: at(0, 10), end: at(0, 12), bufferBefore: 45, bufferAfter: 45 },
      { id: 2, title: "Client lunch", start: at(1, 12), end: at(1, 13, 30), bufferBefore: 30, bufferAfter: 30 },
      { id: 3, title: "Shoot: Kinetic", start: at(2, 9), end: at(2, 13), bufferBefore: 60, bufferAfter: 60 },
      { id: 4, title: "Review call", start: at(2, 15), end: at(2, 15, 30) },
      { id: 5, title: "Workshop", start: at(3, 10), end: at(3, 12), bufferAfter: 30 },
    ]
  })
  const { lines, log } = useLog()

  return (
    <div className="docs-demo__stack">
      <ProScheduler
        data={events}
        view={{ scheduler: { type: "week", startTime: "07:00", endTime: "19:00", dragTimeStep: 15 } }}
        // Buffers are travel/set-up time: drawn hatched, and they count as busy.
        eventOverlap={false}
        onEventUpdateFailed={(f) => log(`"${f.event.title}" would ${reason(f)}, travel time included`)}
        onEventCreateFailed={(f) => log(`That slot ${reason(f)}`)}
        height={560}
        {...handlers}
      />
      <Log lines={lines} empty="Drag the review call next to the shoot…" />
    </div>
  )
}

const blocked: PschInvalid[] = [
  { recurring: { repeat: "daily" }, startTime: "12:00", endTime: "13:00", title: "Lunch" },
  { recurring: { repeat: "weekly", weekDays: [0, 6] }, title: "Weekend" },
]

About this demo

bufferBefore and bufferAfter reserve travel or set-up time around an event. They draw hatched and, with overlaps off, count as busy.

Things to try

  • Drag the review call right after the shoot
  • Move it an hour later

The props behind it are explained in Rules and backgrounds.

Use ProScheduler in your project