ProSchedulerSign in

Timeline · CRUD

Multiple selection

Select sessions across rows, then hand them all to one person.

Live demo

Select three sessions · Give them to Ada

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

/** Selection plus the bulk actions a host builds around it. */
function useBulk<T extends SchedulerEvent>(initial: () => T[]) {
  const { events, setEvents, handlers } = useEvents<T>(initial)
  const [selected, setSelected] = useState<SchedulerEvent[]>([])
  const { lines, log } = useLog(5)
  const ids = new Set(selected.map((e) => e.id))
  const update = (change: (e: T) => T) => {
    setEvents((list) => list.map((e) => (ids.has(e.id) ? change(e) : e)))
    setSelected([])
  }
  return { events, handlers, selected, setSelected, lines, log, ids, update, setEvents }
}

export function TimelineMultiSelectDemo() {
  const bulk = useBulk(() => studioSessions())
  return (
    <>
      <Toolbar label="Reassign the selection">
        <span className="text-sm text-muted-foreground">{bulk.selected.length} selected → </span>
        {studioResources.slice(0, 4).map((person) => (
          <Choice
            key={person.id}
            onClick={() => {
              bulk.update((e) => ({ ...e, resource: person.id }))
              bulk.log(`moved ${bulk.selected.length} to ${person.name}`)
            }}
          >
            {person.name.split(" ")[0]}
          </Choice>
        ))}
      </Toolbar>
      <ProScheduler
        data={bulk.events}
        resources={studioResources}
        view={{ timeline: { type: "week", resolutionHorizontal: "hour", startTime: "08:00", endTime: "19:00" } }}
        styleConfig={{ unitWidthPx: 22, fitToWidth: false }}
        selectMultipleEvents
        selectedEvents={bulk.selected}
        onSelectedEventsChange={bulk.setSelected}
        height={520}
        {...bulk.handlers}
      />
      <Log lines={bulk.lines} empty="Select sessions, then give them to someone." />
    </>
  )
}

About this demo

Select sessions across rows, then hand them all to one person.

Things to try

  • Select three sessions
  • Give them to Ada

The props behind it are explained in Selection, drag and drop, links.

Use ProScheduler in your project