ProSchedulerSign in

Agenda · Displaying events

Multiple selection

Select sessions from the list and act on them together.

Live demo

Select a few, then Mark done

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 AgendaMultiSelectDemo() {
  const bulk = useBulk(() => studioSessions())
  return (
    <>
      <Toolbar label="Selection">
        <span className="text-sm text-muted-foreground">{bulk.selected.length} selected</span>
        <Choice
          onClick={() => {
            bulk.update((e) => ({ ...e, title: e.title.startsWith("✓ ") ? e.title : `✓ ${e.title}` }))
            bulk.log(`marked ${bulk.selected.length} done`)
          }}
        >
          Mark done
        </Choice>
        <Choice onClick={() => bulk.setSelected([])}>Clear</Choice>
      </Toolbar>
      <ProScheduler
        data={bulk.events}
        resources={studioResources}
        view={{ agenda: { type: "week" } }}
        selectMultipleEvents
        selectedEvents={bulk.selected}
        onSelectedEventsChange={bulk.setSelected}
        height={520}
        {...bulk.handlers}
      />
      <Log lines={bulk.lines} empty="Select a few sessions, then mark them done." />
    </>
  )
}

About this demo

Select sessions from the list and act on them together.

Things to try

  • Select a few, then Mark done

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

Use ProScheduler in your project