ProSchedulerSign in

Timeline · Use cases

Classroom timetable

Today's lessons by room. Lunch and after-hours are blocked, and a room holds one class at a time.

Live demo

Move a class into lunch · Move one onto another class · Book the gym at 16:00

Fullscreen
import { ProScheduler, type PschValidationFailure } from "@andreisaac/pro-scheduler"
import { classes, rooms, schoolClosed } from "./data/bookings"
import { Log, useEvents, useLog, when } from "./kit"

function reason(failure: PschValidationFailure) {
  return failure.reason === "invalid"
    ? `blocked (${failure.invalid?.title ?? "unavailable"})`
    : `overlaps "${failure.overlapping?.title}"`
}

const day = (base: Date, n: number) => new Date(base.getFullYear(), base.getMonth(), base.getDate() + n)

export function ClassroomDemo() {
  const { events, handlers } = useEvents(classes)
  const { lines, log } = useLog()

  return (
    <div className="docs-demo__stack">
      <ProScheduler
        data={events}
        resources={rooms}
        view={{ timeline: { type: "day", dragTimeStep: 30 } }}
        styleConfig={{ unitWidthPx: 70, fitToWidth: false, resourceColWidth: 170 }}
        invalid={schoolClosed} // lunch and after hours
        eventOverlap={false} // one class per room
        onEventUpdateFailed={(f) => log(`${f.event.title}: ${reason(f)}`)}
        onEventCreateFailed={(f) => log(`Can't book ${when(f.event.start)}: ${reason(f)}`)}
        renderResource={(room) => (
          <div className="min-w-0">
            <div className="truncate text-sm font-medium">{room.name}</div>
            <div className="text-xs text-muted-foreground">{String(room.capacity)} seats</div>
          </div>
        )}
        height={440}
        {...handlers}
      />
      <Log lines={lines} empty="Move a class into lunch, or onto another class…" />
    </div>
  )
}

About this demo

Today's lessons by room. Lunch and after-hours are blocked, and a room holds one class at a time.

Things to try

  • Move a class into lunch
  • Move one onto another class
  • Book the gym at 16:00

The props behind it are explained in Rules and backgrounds.

Use ProScheduler in your project