ProSchedulerSign in

Scheduler · Resources

Hide resources without events

Only the people with something booked on the visible day get a column; page to another day and the columns follow.

Live demo

Page to tomorrow · Show everyone

Fullscreen
import { useMemo, useState } from "react"
import { ProScheduler } from "@andreisaac/pro-scheduler"
import { studioResources, studioSessions } from "./data/studio"
import { Choice, Toolbar, useEvents } from "./kit"

export function HideResourcesDemo() {
  const { events, handlers } = useEvents(studioSessions)
  const [hideIdle, setHideIdle] = useState(true)
  const [day, setDay] = useState(() => new Date())

  // Who has anything booked on the visible day?
  const busy = useMemo(() => {
    const from = new Date(day.getFullYear(), day.getMonth(), day.getDate()).getTime()
    const to = from + 86_400_000
    return new Set(
      events
        .filter((e) => new Date(e.start).getTime() < to && new Date(e.end!).getTime() > from)
        .flatMap((e) => [e.resource].flat())
    )
  }, [events, day])

  return (
    <div className="docs-demo__stack">
      <Toolbar>
        <Choice active={hideIdle} onClick={() => setHideIdle(!hideIdle)}>
          Hide people with nothing booked
        </Choice>
        <span className="demo-muted">
          {busy.size} of {studioResources.length} busy
        </span>
      </Toolbar>
      <ProScheduler
        data={events}
        resources={hideIdle ? studioResources.filter((r) => busy.has(r.id)) : studioResources}
        view={{ scheduler: { type: "day", resources: true, startTime: "07:00", endTime: "20:00" } }}
        selectedDate={day}
        onSelectedDateChange={setDay}
        height={580}
        {...handlers}
      />
    </div>
  )
}

About this demo

Only the people with something booked on the visible day get a column; page to another day and the columns follow.

Things to try

  • Page to tomorrow
  • Show everyone

The props behind it are explained in Resources.

Use ProScheduler in your project