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
Fullscreenimport { 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>
)
}// data/bookings.ts — sample data, relative to the current week or month.
import type { PschInvalid, SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
const at = (base: Date, day: number, hour: number, minute = 0) =>
new Date(base.getFullYear(), base.getMonth(), base.getDate() + day, hour, minute)
export const rooms: SchedulerResource[] = [
{ id: "lab-1", name: "Science lab", capacity: 24, color: "#0891b2" },
{ id: "room-12", name: "Room 12", capacity: 30, color: "#2563eb" },
{ id: "room-14", name: "Room 14", capacity: 30, color: "#7c3aed" },
{ id: "hall", name: "Assembly hall", capacity: 200, color: "#d97706" },
{ id: "gym", name: "Gym", capacity: 60, color: "#059669" },
{ id: "music", name: "Music room", capacity: 20, color: "#db2777" },
]
const lessons: [string, string, number, number][] = [
["lab-1", "Chemistry 10A", 8, 2],
["lab-1", "Biology 9C", 13, 2],
["room-12", "Maths 11B", 8, 1],
["room-12", "History 10A", 10, 1],
["room-12", "English 9A", 14, 1],
["room-14", "French 8B", 9, 1],
["room-14", "Geography 10C", 11, 1],
["room-14", "Maths 9A", 15, 1],
["hall", "Assembly", 8, 1],
["hall", "Exam: Physics", 13, 3],
["gym", "PE 8A", 9, 2],
["gym", "PE 11C", 14, 1],
["music", "Choir", 10, 1],
["music", "Band practice", 15, 2],
]
/** Today's lessons, one class per room at a time. */
export function classes(today = new Date()): SchedulerEvent[] {
return lessons.map(([room, title, hour, hours], i) => {
const start = new Date(today.getFullYear(), today.getMonth(), today.getDate(), hour)
return {
id: `class-${i + 1}`,
title,
resource: room,
start,
end: new Date(start.getTime() + hours * 3_600_000),
}
})
}
/** The school day: no lessons over lunch or outside 08:00–17:00. */
export const schoolClosed: PschInvalid[] = [
{ recurring: { repeat: "daily" }, startTime: "12:00", endTime: "13:00", title: "Lunch" },
{ recurring: { repeat: "daily" }, startTime: "17:00", endTime: "32:00", title: "Closed" },
]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.