Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 14x 14x 14x 14x 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 6x 6x 6x 9x 6x 3x 2x 2x 2x 2x 2x 2x 1x 6x 6x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 1x 11x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 2x 2x 2x 2x 2x 1x 1x 1x 1x 2x 1x 1x 2x 11x 10x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 17x 17x 17x 17x 17x 17x 17x 17x 17x 4x 4x 4x 4x 4x 4x 4x 17x 17x 3x 3x 3x 3x 3x 3x 3x 17x 10x 10x 10x 10x 10x 17x 17x 17x 17x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 5x 5x 5x 5x 5x 5x 5x 11x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 11x 11x 11x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 168x 168x 168x 168x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 168x 168x 168x 168x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 72x 72x 72x 72x 24x 24x 24x 24x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x | 'use client'
import Link from 'next/link'
import {useRouter} from 'next/navigation'
import {useMemo, useState} from 'react'
import {
DndContext,
KeyboardSensor,
PointerSensor,
TouchSensor,
closestCenter,
useSensor,
useSensors,
type DragEndEvent,
} from '@dnd-kit/core'
import {
SortableContext,
arrayMove,
sortableKeyboardCoordinates,
useSortable,
verticalListSortingStrategy,
} from '@dnd-kit/sortable'
import {CSS} from '@dnd-kit/utilities'
import {transposeKey} from '@/lib/chordpro'
import {shortDate} from '@/lib/dates'
import PdfDialog from '@/components/PdfDialog'
import AutoTextarea from '@/components/AutoTextarea'
import {
formatLength,
runningOrder,
setSummary,
timeRange,
type BreakInfo,
type SetInfo,
} from '@/lib/gig'
export type PickSong = {
id: string
title: string
ready: boolean
leadSinger: string | null
key: string | null
/** How long it runs, for timing sets */
seconds: number | null
}
type SongItem = {
uid: string
kind: 'SONG'
songId: string
note: string
key: string
}
/** Starts a set; minutes and startTime are text while being typed */
type SetItem = {
uid: string
kind: 'SET'
label: string
minutes: string
startTime: string
}
type BreakItem = {uid: string; kind: 'BREAK'; minutes: string}
export type Item = SongItem | SetItem | BreakItem
type Values = {
name: string
gigDate: string
/** When the first set starts, "20:00" */
startTime: string
venue: string
notes: string
items: Item[]
}
const toMinutes = (t: string) => {
const n = Number(t)
return t.trim() && Number.isInteger(n) && n > 0 && n <= 600 ? n : null
}
/** The 12 keys reachable from a song's key, spelled conventionally. */
function keyOptions(original: string | null) {
if (!original) return []
return Array.from({length: 12}, (_, i) => transposeKey(original, i))
}
let uidCounter = 0
const newUid = () => `new-${Date.now()}-${uidCounter++}`
export default function SetlistEditor({
id,
library,
initial,
editedBy,
editedAt,
canDelete = false,
}: {
id: string
library: PickSong[]
initial: Values
editedBy: string
editedAt: string
/** Admins only: the API refuses everyone else */
canDelete?: boolean
}) {
const router = useRouter()
const [v, setV] = useState<Values>(initial)
const [saved, setSaved] = useState<Values>(initial)
const [busy, setBusy] = useState(false)
const [error, setError] = useState<string | null>(null)
const [picking, setPicking] = useState(false)
const [q, setQ] = useState('')
const [pdfOpen, setPdfOpen] = useState(false)
const byId = useMemo(() => new Map(library.map((s) => [s.id, s])), [library])
const dirty = JSON.stringify(v) !== JSON.stringify(saved)
const inSet = new Set(
v.items.flatMap((i) => (i.kind === 'SONG' ? [i.songId] : [])),
)
const songCount = v.items.filter((i) => i.kind === 'SONG').length
// Timing, worked out live as rows move
const order = useMemo(
() =>
runningOrder(
v.startTime || null,
v.items.map((i) =>
i.kind === 'SONG'
? {kind: i.kind, song: {seconds: byId.get(i.songId)?.seconds}}
: i.kind === 'SET'
? {
kind: i.kind,
label: i.label || 'Set',
minutes: toMinutes(i.minutes),
startTime: i.startTime || null,
}
: {kind: i.kind, minutes: toMinutes(i.minutes)},
),
),
[v.items, v.startTime, byId],
)
const sensors = useSensors(
useSensor(PointerSensor, {activationConstraint: {distance: 6}}),
useSensor(TouchSensor, {activationConstraint: {delay: 150, tolerance: 6}}),
useSensor(KeyboardSensor, {coordinateGetter: sortableKeyboardCoordinates}),
)
const setItems = (items: Item[]) => setV({...v, items})
const update = (
uid: string,
// Any row's text fields; `kind` never changes
patch: Partial<
Record<'note' | 'key' | 'label' | 'minutes' | 'startTime', string>
>,
) =>
setItems(
v.items.map((i) => (i.uid === uid ? ({...i, ...patch} as Item) : i)),
)
/** A new set: the first goes on top (around what's there), later ones at the end. */
function addSet() {
const n = v.items.filter((i) => i.kind === 'SET').length + 1
const row: SetItem = {
uid: newUid(),
kind: 'SET',
label: `Set ${n}`,
minutes: '45',
startTime: '',
}
setItems(n === 1 ? [row, ...v.items] : [...v.items, row])
}
const addBreak = () =>
setItems([...v.items, {uid: newUid(), kind: 'BREAK', minutes: '15'}])
const move = (from: number, to: number) =>
to >= 0 && to < v.items.length && setItems(arrayMove(v.items, from, to))
function onDragEnd(e: DragEndEvent) {
if (!e.over || e.active.id === e.over.id) return
const from = v.items.findIndex((i) => i.uid === e.active.id)
const to = v.items.findIndex((i) => i.uid === e.over!.id)
move(from, to)
}
async function save() {
setBusy(true)
setError(null)
const r = await fetch(`/api/setlists/${id}`, {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
name: v.name,
gigDate: v.gigDate || null,
startTime: v.startTime || null,
venue: v.venue || null,
notes: v.notes || null,
items: v.items.map((i) =>
i.kind === 'SONG'
? {
kind: i.kind,
songId: i.songId,
note: i.note || null,
key: i.key || null,
}
: i.kind === 'SET'
? {
kind: i.kind,
label: i.label.trim() || 'Set',
minutes: toMinutes(i.minutes),
startTime: i.startTime || null,
}
: {kind: i.kind, minutes: toMinutes(i.minutes)},
),
}),
})
setBusy(false)
if (!r.ok) return setError('Could not save the setlist.')
setSaved(v)
router.refresh()
}
async function remove() {
if (
!window.confirm(
`Delete the setlist “${saved.name}”? This can't be undone.`,
)
)
return
setBusy(true)
setError(null)
const r = await fetch(`/api/setlists/${id}`, {method: 'DELETE'})
setBusy(false)
if (!r.ok) return setError('Could not delete the setlist.')
router.push('/setlists')
router.refresh()
}
const results = library.filter((s) =>
s.title.toLowerCase().includes(q.trim().toLowerCase()),
)
return (
<main className="mx-auto max-w-3xl px-4 pb-32 pt-4">
<Link
href={`/setlists/${id}`}
className="text-sm text-muted no-underline hover:text-text"
>
‹ Back to the setlist
</Link>
<label className="mt-1 block">
<span className="sr-only">Setlist name</span>
<AutoTextarea
singleLine
value={v.name}
onChange={(e) =>
setV({...v, name: e.target.value.replace(/\n/g, ' ')})
}
className="block w-full rounded-lg border border-transparent bg-transparent px-1 text-3xl font-extrabold leading-tight hover:border-line-2 focus:border-line-2"
/>
</label>
<p className="mt-1 px-1 text-sm text-muted">
{songCount} songs · edited by {editedBy} · {shortDate(editedAt)}
</p>
<div className="mt-4 grid grid-cols-2 gap-3 sm:grid-cols-[1fr_auto_1fr]">
<label className="flex flex-col gap-1 text-sm text-muted">
Gig date
<input
type="date"
value={v.gigDate}
onChange={(e) => setV({...v, gigDate: e.target.value})}
className="min-h-11 rounded-lg border border-line-2 bg-panel px-3 text-base text-text"
/>
</label>
<label className="flex flex-col gap-1 text-sm text-muted">
Starts
<input
type="time"
value={v.startTime}
onChange={(e) => setV({...v, startTime: e.target.value})}
className="min-h-11 rounded-lg border border-line-2 bg-panel px-3 text-base text-text"
/>
</label>
<label className="col-span-2 flex flex-col gap-1 text-sm text-muted sm:col-span-1">
Venue
<input
value={v.venue}
onChange={(e) => setV({...v, venue: e.target.value})}
className="min-h-11 rounded-lg border border-line-2 bg-panel px-3 text-base text-text"
/>
</label>
</div>
<div className="mt-4 flex flex-wrap gap-2">
<Link
href={`/perform/${id}`}
className="inline-flex min-h-11 items-center rounded-lg bg-accent px-4 font-extrabold text-on-accent no-underline"
>
▶ Perform
</Link>
<button
type="button"
onClick={() => setPdfOpen(true)}
className="min-h-11 rounded-lg border border-line-2 px-4"
>
PDF of the set
</button>
</div>
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragEnd={onDragEnd}
>
<SortableContext
items={v.items.map((i) => i.uid)}
strategy={verticalListSortingStrategy}
>
<ol className="mt-5">
{v.items.map((item, n) => {
const entry = order.entries[n]
const common = {
n,
count: v.items.length,
onMove: (d: number) => move(n, n + d),
onRemove: () =>
setItems(v.items.filter((i) => i.uid !== item.uid)),
}
if (item.kind === 'SET' && entry?.kind === 'SET')
return (
<SetRow
key={item.uid}
{...common}
item={item}
info={entry.info}
onChange={(p) => update(item.uid, p)}
/>
)
if (item.kind === 'BREAK' && entry?.kind === 'BREAK')
return (
<BreakRow
key={item.uid}
{...common}
item={item}
info={entry.info}
onChange={(p) => update(item.uid, p)}
/>
)
if (item.kind !== 'SONG') return null
return (
<Row
key={item.uid}
{...common}
item={item}
number={entry?.kind === 'SONG' ? entry.n : n + 1}
song={byId.get(item.songId)}
onChange={(p) => update(item.uid, p)}
/>
)
})}
</ol>
</SortableContext>
</DndContext>
{!v.items.length && <p className="py-6 text-muted">No songs yet.</p>}
<div className="mt-4">
{picking ? (
<div className="rounded-xl border border-line-2 bg-panel p-3">
<div className="flex gap-2">
<label className="sr-only" htmlFor="pick-q">
Find a song
</label>
<input
id="pick-q"
autoFocus
value={q}
onChange={(e) => setQ(e.target.value)}
placeholder="Find a song"
className="min-h-11 flex-1 rounded-lg border border-line-2 bg-ink px-3"
/>
<button
type="button"
onClick={() => setPicking(false)}
className="min-h-11 px-3 text-muted"
>
Done
</button>
</div>
<ul className="mt-2 max-h-80 overflow-y-auto">
{results.map((s) => (
<li key={s.id}>
<button
type="button"
onClick={() =>
setItems([
...v.items,
{
uid: newUid(),
kind: 'SONG',
songId: s.id,
note: '',
key: '',
},
])
}
className="flex min-h-12 w-full items-center gap-3 border-t border-line px-1 text-left"
>
<span
aria-hidden="true"
className={`h-2.5 w-2.5 rounded-full ${s.ready ? 'bg-good' : 'border-2 border-muted'}`}
/>
<span className="flex-1">{s.title}</span>
{inSet.has(s.id) && (
<span className="text-xs text-muted">in set</span>
)}
<span className="font-mono font-bold text-amber">+</span>
</button>
</li>
))}
</ul>
</div>
) : (
<div className="flex gap-2">
<button
type="button"
onClick={() => setPicking(true)}
className="min-h-12 flex-1 rounded-xl border border-dashed border-line-2 font-semibold"
>
+ Add songs
</button>
<button
type="button"
onClick={addSet}
className="min-h-12 rounded-xl border border-dashed border-amber px-4 font-semibold text-amber"
>
+ Set
</button>
<button
type="button"
onClick={addBreak}
className="min-h-12 rounded-xl border border-dashed border-line-2 px-4 font-semibold text-muted"
>
+ Break
</button>
</div>
)}
</div>
<label className="mt-6 flex flex-col gap-1 text-sm text-muted">
Notes for the whole set
<textarea
value={v.notes}
onChange={(e) => setV({...v, notes: e.target.value})}
rows={3}
className="rounded-lg border border-line-2 bg-panel px-3 py-2 text-base text-text"
/>
</label>
{canDelete && (
<button
type="button"
onClick={remove}
disabled={busy}
className="mt-8 min-h-11 text-sm text-bad underline disabled:opacity-50"
>
Delete this setlist
</button>
)}
{(dirty || error) && (
<div className="fixed inset-x-0 bottom-[max(env(safe-area-inset-bottom),16px)] z-20 mx-auto flex max-w-3xl items-center gap-3 px-4">
<div className="flex flex-1 items-center gap-3 rounded-xl border border-line-2 bg-panel p-3 shadow-xl">
<span className="flex-1 text-sm text-muted">
{error ?? 'Unsaved changes'}
</span>
<button
type="button"
onClick={() => setV(saved)}
className="min-h-11 px-3 text-muted"
>
Undo
</button>
<button
type="button"
onClick={save}
disabled={busy}
className="min-h-11 rounded-lg bg-accent px-5 font-bold text-on-accent disabled:opacity-50"
>
{busy ? 'Saving…' : 'Save'}
</button>
</div>
</div>
)}
{pdfOpen && (
<PdfDialog
title={`${v.name} — ${songCount} charts in set order, each in its set key`}
sheet
baseUrl={`/api/setlists/${id}/pdf`}
shownKey={null}
originalKey={null}
footnote={
dirty ? 'Save first: the PDF uses the saved setlist.' : undefined
}
onClose={() => setPdfOpen(false)}
/>
)}
</main>
)
}
function Row({
item,
n,
number,
count,
song,
onChange,
onMove,
onRemove,
}: {
item: SongItem
n: number
/** Its number within its set */
number: number
count: number
song: PickSong | undefined
onChange: (p: Partial<SongItem>) => void
onMove: (d: number) => void
onRemove: () => void
}) {
const {attributes, listeners, setNodeRef, transform, transition, isDragging} =
useSortable({
id: item.uid,
})
const [noteOpen, setNoteOpen] = useState(Boolean(item.note))
const keys = keyOptions(song?.key ?? null)
return (
<li
ref={setNodeRef}
style={{transform: CSS.Transform.toString(transform), transition}}
className={`border-t border-line py-2 ${isDragging ? 'relative z-10 rounded-lg bg-panel shadow-xl' : ''}`}
>
<div className="flex items-center gap-2">
<DragHandle
label={song?.title ?? 'song'}
attributes={attributes}
listeners={listeners}
/>
<span className="w-6 font-mono text-sm text-faint">{number}</span>
<span className="min-w-0 flex-1">
<span className="block font-semibold leading-snug">
{song?.title ?? 'Deleted song'}
</span>
{(song?.leadSinger || song?.seconds) && (
<span className="text-[13px] text-muted">
{[
song.leadSinger,
song.seconds ? formatLength(song.seconds) : null,
]
.filter(Boolean)
.join(' · ')}
</span>
)}
</span>
{keys.length > 0 && (
<label className="hidden items-center sm:flex">
<span className="sr-only">Key for {song?.title}</span>
<select
value={item.key || keys[0]}
onChange={(e) =>
onChange({
key: e.target.value === keys[0] ? '' : e.target.value,
})
}
className={`min-h-11 rounded-lg border border-line-2 bg-panel px-2 font-mono font-bold ${item.key ? 'text-amber' : 'text-muted'}`}
>
{keys.map((k, i) => (
<option key={k} value={k}>
{k}
{i === 0 ? ' (orig)' : ''}
</option>
))}
</select>
</label>
)}
<span className="hidden gap-1 sm:flex">
<button
type="button"
aria-label="Move up"
disabled={n === 0}
onClick={() => onMove(-1)}
className="h-11 w-9 disabled:opacity-30"
>
↑
</button>
<button
type="button"
aria-label="Move down"
disabled={n === count - 1}
onClick={() => onMove(1)}
className="h-11 w-9 disabled:opacity-30"
>
↓
</button>
</span>
<button
type="button"
aria-label={`Remove ${song?.title}`}
onClick={onRemove}
className="h-11 w-9 text-xl text-faint"
>
×
</button>
</div>
<div className="flex flex-wrap items-start gap-2 pl-16">
{keys.length > 0 && (
<label className="flex shrink-0 items-center sm:hidden">
<span className="sr-only">Key for {song?.title}</span>
<select
value={item.key || keys[0]}
onChange={(e) =>
onChange({
key: e.target.value === keys[0] ? '' : e.target.value,
})
}
className={`min-h-11 rounded-lg border border-line-2 bg-panel px-2 font-mono font-bold ${item.key ? 'text-amber' : 'text-muted'}`}
>
{keys.map((k, i) => (
<option key={k} value={k}>
{k}
{i === 0 ? ' (orig)' : ''}
</option>
))}
</select>
</label>
)}
{noteOpen ? (
<label className="flex min-w-[12rem] flex-1 items-center gap-2">
<span className="sr-only">Note for {song?.title}</span>
<AutoTextarea
value={item.note}
onChange={(e) => onChange({note: e.target.value})}
placeholder="e.g. Micky counts it in · straight into the next song"
className="min-h-10 w-full rounded-lg border border-line-2 bg-panel px-3 py-2 text-[15px] leading-snug"
/>
</label>
) : (
<button
type="button"
onClick={() => setNoteOpen(true)}
className="min-h-8 text-sm text-faint hover:text-text"
>
+ Note
</button>
)}
</div>
</li>
)
}
function DragHandle({
label,
attributes,
listeners,
}: {
label: string
attributes: ReturnType<typeof useSortable>['attributes']
listeners: ReturnType<typeof useSortable>['listeners']
}) {
return (
<button
type="button"
aria-label={`Drag to reorder ${label}`}
className="flex h-11 w-8 shrink-0 cursor-grab touch-none items-center justify-center text-faint"
{...attributes}
{...listeners}
>
<svg
width="14"
height="20"
viewBox="0 0 14 20"
fill="currentColor"
aria-hidden="true"
>
{[3, 10, 17].map((y) => (
<g key={y}>
<circle cx="4" cy={y} r="1.6" />
<circle cx="10" cy={y} r="1.6" />
</g>
))}
</svg>
</button>
)
}
function useRow(uid: string) {
const s = useSortable({id: uid})
return {
...s,
style: {
transform: CSS.Transform.toString(s.transform),
transition: s.transition,
},
lifted: s.isDragging ? 'relative z-10 rounded-lg bg-panel shadow-xl' : '',
}
}
/** A set header: its name and length; its times are worked out. */
function SetRow({
item,
info,
onChange,
onRemove,
}: {
item: SetItem
info: SetInfo
n: number
count: number
onChange: (p: Partial<SetItem>) => void
onMove: (d: number) => void
onRemove: () => void
}) {
const r = useRow(item.uid)
const [timeOpen, setTimeOpen] = useState(Boolean(item.startTime))
const when = timeRange(info.start, info.end)
return (
<li
ref={r.setNodeRef}
style={r.style}
className={`mt-4 border-b-2 border-amber pb-2 pt-1 ${r.lifted}`}
>
<div className="flex items-center gap-2">
<DragHandle
label={item.label}
attributes={r.attributes}
listeners={r.listeners}
/>
<label className="min-w-0 flex-1">
<span className="sr-only">Set name</span>
<input
value={item.label}
onChange={(e) => onChange({label: e.target.value})}
className="min-h-11 w-full rounded-lg border border-transparent bg-transparent px-1 text-lg font-extrabold hover:border-line-2 focus:border-line-2"
/>
</label>
<label className="flex shrink-0 items-center gap-1 text-sm text-muted">
<span className="sr-only">Length of {item.label} in minutes</span>
<input
inputMode="numeric"
value={item.minutes}
onChange={(e) =>
onChange({minutes: e.target.value.replace(/\D/g, '')})
}
placeholder="—"
className="min-h-11 w-14 rounded-lg border border-line-2 bg-panel px-2 text-center font-mono text-base text-text"
/>
min
</label>
<button
type="button"
aria-label={`Remove ${item.label} (its songs stay)`}
onClick={onRemove}
className="h-11 w-9 text-xl text-faint"
>
×
</button>
</div>
<p className="flex flex-wrap items-center gap-x-3 pl-10 text-sm text-muted">
{when && <span className="font-mono text-text">{when}</span>}
<span>{setSummary(info)}</span>
{timeOpen ? (
<label className="flex items-center gap-1">
starts at
<input
type="time"
value={item.startTime}
onChange={(e) => onChange({startTime: e.target.value})}
className="min-h-9 rounded-lg border border-line-2 bg-panel px-2 text-text"
/>
</label>
) : (
<button
type="button"
onClick={() => setTimeOpen(true)}
className="min-h-9 text-faint hover:text-text"
>
set its own start time
</button>
)}
</p>
</li>
)
}
/** A break between sets: how long; its times are worked out. */
function BreakRow({
item,
info,
onChange,
onRemove,
}: {
item: BreakItem
info: BreakInfo
n: number
count: number
onChange: (p: Partial<BreakItem>) => void
onMove: (d: number) => void
onRemove: () => void
}) {
const r = useRow(item.uid)
const when = timeRange(info.start, info.end)
return (
<li ref={r.setNodeRef} style={r.style} className={`my-2 ${r.lifted}`}>
<div className="flex items-center gap-2 rounded-lg bg-panel px-1 text-muted">
<DragHandle
label="break"
attributes={r.attributes}
listeners={r.listeners}
/>
<span className="flex-1 font-semibold">
Break
{when && <span className="ml-3 font-mono font-normal">{when}</span>}
</span>
<label className="flex items-center gap-1 text-sm">
<span className="sr-only">Length of the break in minutes</span>
<input
inputMode="numeric"
value={item.minutes}
onChange={(e) =>
onChange({minutes: e.target.value.replace(/\D/g, '')})
}
className="min-h-10 w-14 rounded-lg border border-line-2 bg-ink px-2 text-center font-mono text-base text-text"
/>
min
</label>
<button
type="button"
aria-label="Remove the break"
onClick={onRemove}
className="h-11 w-9 text-xl text-faint"
>
×
</button>
</div>
</li>
)
}
|