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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 | 'use client' import * as Checkbox from '@radix-ui/react-checkbox' import * as HoverCard from '@radix-ui/react-hover-card' import Link from 'next/link' import { useCallback, useEffect, useRef, useState } from 'react' import { useTheme } from '@/contexts/ThemeContext' import { Z_INDEX } from '@/constants/zIndex' import type { Player } from '@/types/player' import type { EnrollmentStatus, StudentActivityStatus } from '@/types/student' import { css } from '../../../styled-system/css' import { NotesModal } from './NotesModal' import { StudentActionMenu } from './StudentActionMenu' import { RelationshipBadge } from './RelationshipBadge' import { RelationshipCard } from './RelationshipCard' import { avatarStyles, badgeStyles, centerStack, fontBold, gapLg, gapMd, gapSm, paddingLg, paddingMd, progressBarContainerStyles, progressBarFillStyles, roundedLg, textBase, textSm, themed, transitionNormal, wrap, } from './styles' // ============================================================================ // Helper Functions // ============================================================================ /** * Find the next student in a given direction based on bounding rects. * Used for arrow key navigation in the QuickLook modal. */ function findNextStudent( currentId: string, direction: 'up' | 'down' | 'left' | 'right', cardRefs: Map<string, HTMLDivElement> ): { studentId: string; bounds: DOMRect } | null { const currentRef = cardRefs.get(currentId) if (!currentRef) return null const currentRect = currentRef.getBoundingClientRect() const currentCenterX = currentRect.left + currentRect.width / 2 const currentCenterY = currentRect.top + currentRect.height / 2 let bestCandidate: { studentId: string bounds: DOMRect distance: number } | null = null for (const [studentId, ref] of cardRefs) { if (studentId === currentId) continue const rect = ref.getBoundingClientRect() const centerX = rect.left + rect.width / 2 const centerY = rect.top + rect.height / 2 // Check if this card is in the correct direction let isValidDirection = false switch (direction) { case 'left': isValidDirection = centerX < currentCenterX - 10 break case 'right': isValidDirection = centerX > currentCenterX + 10 break case 'up': isValidDirection = centerY < currentCenterY - 10 break case 'down': isValidDirection = centerY > currentCenterY + 10 break } if (!isValidDirection) continue // Calculate distance with preference for the primary direction let distance: number if (direction === 'left' || direction === 'right') { // Horizontal: prioritize same row (small Y difference) const yPenalty = Math.abs(centerY - currentCenterY) * 2 distance = Math.abs(centerX - currentCenterX) + yPenalty } else { // Vertical: prioritize same column (small X difference) const xPenalty = Math.abs(centerX - currentCenterX) * 2 distance = Math.abs(centerY - currentCenterY) + xPenalty } if (!bestCandidate || distance < bestCandidate.distance) { bestCandidate = { studentId, bounds: rect, distance } } } return bestCandidate ? { studentId: bestCandidate.studentId, bounds: bestCandidate.bounds } : null } // ============================================================================ // Types // ============================================================================ /** * Intervention data for students needing attention */ export interface StudentIntervention { type: 'struggling' | 'declining' | 'stale' | 'absent' | 'plateau' severity: 'high' | 'medium' | 'low' message: string icon: string } /** * Actions for enrollment requests (approve/deny buttons on cards) */ export interface EnrollmentActions { /** Called when approve is clicked, with the request ID */ onApprove: (requestId: string) => void /** Called when deny is clicked, with the request ID */ onDeny: (requestId: string) => void /** Request ID currently being approved */ approvingId: string | null /** Request ID currently being denied */ denyingId: string | null } /** * Student data with curriculum info for display */ export interface StudentWithProgress extends Player { currentLevel?: number currentPhaseId?: string masteryPercent?: number isArchived?: boolean practicingSkills?: string[] lastPracticedAt?: Date | null skillCategory?: string | null intervention?: StudentIntervention | null /** For enrollment requests, the request ID (used for approve/deny actions) */ enrollmentRequestId?: string /** Relationship data for action menu visibility */ relationship?: { isMyChild: boolean isEnrolled: boolean isPresent: boolean enrollmentStatus: EnrollmentStatus } /** Activity data for status display */ activity?: { status: StudentActivityStatus sessionProgress?: { current: number; total: number } sessionId?: string } } interface StudentCardProps { student: StudentWithProgress /** Optional callback when student is selected (Link handles navigation) */ onSelect?: (student: StudentWithProgress) => void onToggleSelection: (student: StudentWithProgress) => void onOpenQuickLook: (student: StudentWithProgress, bounds: DOMRect) => void isSelected?: boolean /** Callback when observe session is clicked */ onObserveSession?: (sessionId: string) => void /** Callback to register card ref for keyboard navigation */ onRegisterRef?: (studentId: string, ref: HTMLDivElement | null) => void /** Enrollment actions (approve/deny) - shows buttons when provided and student has enrollmentRequestId */ enrollmentActions?: EnrollmentActions } /** * Individual student card showing avatar, name, and progress * Clicking navigates to the student's practice page. * Checkbox is always visible for multi-select. */ function StudentCard({ student, onSelect, onToggleSelection, onOpenQuickLook, isSelected, onObserveSession, onRegisterRef, enrollmentActions, }: StudentCardProps) { const { resolvedTheme } = useTheme() const isDark = resolvedTheme === 'dark' const levelLabel = student.currentLevel ? `Lv.${student.currentLevel}` : 'New' const cardRef = useRef<HTMLDivElement>(null) const isArchived = student.isArchived ?? false // Register ref for keyboard navigation useEffect(() => { if (onRegisterRef && cardRef.current) { onRegisterRef(student.id, cardRef.current) } return () => { if (onRegisterRef) { onRegisterRef(student.id, null) } } }, [student.id, onRegisterRef]) // Relationship and activity data for status display and action menu const { relationship, activity } = student const handleQuickLookClick = useCallback( (e: React.MouseEvent) => { e.stopPropagation() if (cardRef.current) { const bounds = cardRef.current.getBoundingClientRect() onOpenQuickLook(student, bounds) } }, [student, onOpenQuickLook] ) return ( <div ref={cardRef} data-component="student-card" data-archived={isArchived} data-selected={isSelected} className={css({ ...centerStack, ...gapSm, ...paddingMd, ...roundedLg, ...transitionNormal, border: '2px solid', borderColor: isSelected ? 'blue.500' : isArchived ? isDark ? 'gray.700' : 'gray.300' : themed('border', isDark), backgroundColor: isArchived ? isDark ? 'gray.800/50' : 'gray.100' : themed('surface', isDark), minWidth: '100px', position: 'relative', opacity: isArchived ? 0.6 : 1, })} > {/* Selection checkbox - always visible */} <Checkbox.Root data-element="checkbox" checked={isSelected} onCheckedChange={() => onToggleSelection(student)} className={css({ position: 'absolute', top: '6px', left: '6px', width: '22px', height: '22px', borderRadius: '4px', border: '2px solid', borderColor: isSelected ? 'blue.500' : isDark ? 'gray.500' : 'gray.400', backgroundColor: isSelected ? 'blue.500' : 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', padding: 0, zIndex: 1, _hover: { borderColor: 'blue.400', }, })} > <Checkbox.Indicator className={css({ color: 'white', fontSize: '12px', fontWeight: 'bold', })} > ✓ </Checkbox.Indicator> </Checkbox.Root> {/* Archived badge */} {isArchived && ( <div data-element="archived-badge" className={css({ position: 'absolute', top: '6px', left: '32px', // After checkbox padding: '2px 6px', bg: isDark ? 'gray.700' : 'gray.300', color: isDark ? 'gray.400' : 'gray.600', fontSize: '10px', fontWeight: 'medium', borderRadius: '4px', })} > Archived </div> )} {/* Relationship badge with hover tooltip - shows viewer's relationship to this student */} {!isArchived && relationship && ( <HoverCard.Root openDelay={200} closeDelay={100}> <HoverCard.Trigger asChild> <button type="button" className={css({ position: 'absolute', top: '6px', left: '32px', // After checkbox background: 'none', border: 'none', padding: 0, cursor: 'help', zIndex: 1, })} aria-label="View relationship details" > <RelationshipBadge relationship={relationship} size="sm" showTooltip={false} /> </button> </HoverCard.Trigger> <HoverCard.Portal> <HoverCard.Content data-component="relationship-tooltip" side="right" align="start" sideOffset={8} className={css({ width: '280px', maxWidth: 'calc(100vw - 32px)', padding: '12px', borderRadius: '12px', backgroundColor: isDark ? 'gray.800' : 'white', border: '1px solid', borderColor: isDark ? 'gray.700' : 'gray.200', boxShadow: 'lg', zIndex: Z_INDEX.POPOVER, animation: 'fadeIn 0.15s ease', })} > <RelationshipCard playerId={student.id} compact /> <HoverCard.Arrow className={css({ fill: isDark ? 'gray.800' : 'white', })} /> </HoverCard.Content> </HoverCard.Portal> </HoverCard.Root> )} {/* Self-contained action menu - uses hooks internally for all actions */} <StudentActionMenu student={{ id: student.id, name: student.name, isArchived: student.isArchived, relationship, activity, }} onObserveSession={onObserveSession} /> {/* QuickLook button - hidden for enrollment requests */} {!student.enrollmentRequestId && ( <button type="button" data-action="open-quicklook" onClick={handleQuickLookClick} className={css({ position: 'absolute', top: '6px', right: '6px', width: '28px', height: '28px', borderRadius: '6px', border: 'none', backgroundColor: isDark ? 'gray.700' : 'gray.100', color: isDark ? 'gray.400' : 'gray.500', fontSize: '0.875rem', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'all 0.15s ease', _hover: { backgroundColor: isDark ? 'gray.600' : 'gray.200', color: isDark ? 'gray.200' : 'gray.700', transform: 'scale(1.1)', }, })} title="Quick look" > 👁 </button> )} {/* Main clickable area - uses Next.js Link for proper routing */} <Link href={`/practice/${student.id}/dashboard`} scroll={false} data-action="select-student" onClick={() => onSelect?.(student)} className={css({ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '0.5rem', background: 'none', border: 'none', cursor: 'pointer', padding: '0.5rem', paddingTop: '1.5rem', // Extra space for the notes/checkbox width: '100%', textDecoration: 'none', color: 'inherit', _hover: { '& > div:first-child': { transform: 'scale(1.05)', }, }, })} > {/* Avatar */} <div className={css({ ...avatarStyles('md'), transition: 'transform 0.15s ease', filter: isArchived ? 'grayscale(0.5)' : 'none', })} style={{ backgroundColor: student.color }} > {student.emoji} </div> {/* Name */} <span className={css({ ...fontBold, ...textBase, color: isArchived ? (isDark ? 'gray.500' : 'gray.500') : themed('text', isDark), })} > {student.name} </span> {/* Activity badges - shows what the student is currently doing */} {/* Relationship is shown via RelationshipBadge in top-left corner */} {(activity?.status === 'practicing' || activity?.status === 'learning' || relationship?.isPresent) && ( <div data-element="activity-badges" className={css({ display: 'flex', flexWrap: 'wrap', justifyContent: 'center', gap: '4px', marginTop: '2px', })} > {/* Practicing badge - highest priority */} {activity?.status === 'practicing' && ( <span data-status="practicing" className={css({ display: 'inline-flex', alignItems: 'center', gap: '3px', padding: '2px 6px', borderRadius: '10px', fontSize: '10px', fontWeight: 'medium', bg: isDark ? 'blue.900' : 'blue.100', color: isDark ? 'blue.300' : 'blue.700', animation: 'pulse 2s infinite', })} > <span>📝</span> <span>Practicing</span> </span> )} {/* Learning badge */} {activity?.status === 'learning' && ( <span data-status="learning" className={css({ display: 'inline-flex', alignItems: 'center', gap: '3px', padding: '2px 6px', borderRadius: '10px', fontSize: '10px', fontWeight: 'medium', bg: isDark ? 'purple.900' : 'purple.100', color: isDark ? 'purple.300' : 'purple.700', animation: 'pulse 2s infinite', })} > <span>📚</span> <span>Learning</span> </span> )} {/* Present badge - show when in classroom but not actively practicing/learning */} {relationship?.isPresent && activity?.status !== 'practicing' && activity?.status !== 'learning' && ( <span data-status="present" className={css({ display: 'inline-flex', alignItems: 'center', gap: '3px', padding: '2px 6px', borderRadius: '10px', fontSize: '10px', fontWeight: 'medium', bg: isDark ? 'green.900' : 'green.100', color: isDark ? 'green.300' : 'green.700', })} > <span>🟢</span> <span>Present</span> </span> )} </div> )} {/* Activity progress indicator - show when practicing */} {activity?.status === 'practicing' && activity.sessionProgress && ( <div data-element="session-progress" className={css({ display: 'flex', alignItems: 'center', gap: '4px', fontSize: '10px', color: isDark ? 'gray.400' : 'gray.500', marginTop: '2px', })} > <span> Problem {activity.sessionProgress.current + 1} of {activity.sessionProgress.total} </span> </div> )} {/* Level badge */} <span className={css(badgeStyles(isDark, 'neutral'))}>{levelLabel}</span> {/* Mastery progress bar (if available) */} {student.masteryPercent !== undefined && ( <div className={css({ ...progressBarContainerStyles(isDark, 'sm'), width: '100%', })} > <div className={css(progressBarFillStyles(isDark, 'success'))} style={{ width: `${student.masteryPercent}%` }} /> </div> )} {/* Intervention badge (if needing attention) */} {student.intervention && ( <div data-element="intervention-badge" data-intervention-type={student.intervention.type} data-intervention-severity={student.intervention.severity} className={css({ display: 'flex', alignItems: 'center', gap: '4px', padding: '4px 8px', borderRadius: '6px', fontSize: '0.6875rem', fontWeight: 'medium', backgroundColor: student.intervention.severity === 'high' ? isDark ? 'red.900/60' : 'red.100' : student.intervention.severity === 'medium' ? isDark ? 'orange.900/60' : 'orange.100' : isDark ? 'blue.900/60' : 'blue.100', color: student.intervention.severity === 'high' ? isDark ? 'red.300' : 'red.700' : student.intervention.severity === 'medium' ? isDark ? 'orange.300' : 'orange.700' : isDark ? 'blue.300' : 'blue.700', marginTop: '4px', })} > <span>{student.intervention.icon}</span> <span>{student.intervention.message}</span> </div> )} </Link> {/* Enrollment action buttons (for enrollment requests) */} {enrollmentActions && student.enrollmentRequestId && ( <div data-element="enrollment-actions" className={css({ display: 'flex', gap: '8px', width: '100%', marginTop: '8px', })} > <button type="button" onClick={(e) => { e.stopPropagation() enrollmentActions.onDeny(student.enrollmentRequestId!) }} disabled={ enrollmentActions.approvingId === student.enrollmentRequestId || enrollmentActions.denyingId === student.enrollmentRequestId } data-action="deny-enrollment" className={css({ flex: 1, padding: '8px 12px', backgroundColor: isDark ? 'gray.700' : 'gray.200', color: isDark ? 'gray.300' : 'gray.700', border: 'none', borderRadius: '6px', fontSize: '0.8125rem', fontWeight: 'medium', cursor: 'pointer', transition: 'all 0.15s ease', _hover: { backgroundColor: isDark ? 'gray.600' : 'gray.300' }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} > {enrollmentActions.denyingId === student.enrollmentRequestId ? 'Denying...' : 'Deny'} </button> <button type="button" onClick={(e) => { e.stopPropagation() enrollmentActions.onApprove(student.enrollmentRequestId!) }} disabled={ enrollmentActions.approvingId === student.enrollmentRequestId || enrollmentActions.denyingId === student.enrollmentRequestId } data-action="approve-enrollment" className={css({ flex: 1, padding: '8px 12px', backgroundColor: isDark ? 'green.700' : 'green.500', color: 'white', border: 'none', borderRadius: '6px', fontSize: '0.8125rem', fontWeight: 'bold', cursor: 'pointer', transition: 'all 0.15s ease', _hover: { backgroundColor: isDark ? 'green.600' : 'green.600' }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} > {enrollmentActions.approvingId === student.enrollmentRequestId ? 'Approving...' : 'Approve'} </button> </div> )} </div> ) } interface AddStudentButtonProps { onClick: () => void } /** * Button to add a new student */ function AddStudentButton({ onClick }: AddStudentButtonProps) { const { resolvedTheme } = useTheme() const isDark = resolvedTheme === 'dark' return ( <button type="button" onClick={onClick} data-action="add-student" className={css({ ...centerStack, justifyContent: 'center', ...gapSm, ...paddingMd, ...roundedLg, ...transitionNormal, border: '2px dashed', borderColor: themed('border', isDark), backgroundColor: themed('surfaceMuted', isDark), cursor: 'pointer', minWidth: '100px', minHeight: '140px', _hover: { borderColor: 'green.400', backgroundColor: isDark ? 'green.900/30' : 'green.50', }, })} > <span className={css({ fontSize: '2rem', color: isDark ? 'green.400' : 'green.600', })} > + </span> <span className={css({ ...textSm, color: themed('textMuted', isDark), textAlign: 'center', })} > Add Student </span> </button> ) } interface StudentSelectorProps { students: StudentWithProgress[] /** Optional callback when student is selected (Link handles navigation) */ onSelectStudent?: (student: StudentWithProgress) => void onToggleSelection: (student: StudentWithProgress) => void onAddStudent?: () => void title?: string selectedIds?: Set<string> /** Hide the add student button (e.g., when showing filtered subsets) */ hideAddButton?: boolean /** Callback when observe session is clicked */ onObserveSession?: (sessionId: string) => void /** Enrollment actions (approve/deny) - shows buttons on cards with enrollmentRequestId */ enrollmentActions?: EnrollmentActions /** Compact mode - minimal styling, no wrapper padding, for inline display */ compact?: boolean } /** * StudentSelector - Select which student is practicing today * * Displays all available students (players) with their current * curriculum level and progress. Clicking a student navigates * to their practice page at /practice/[studentId]. * * Checkboxes are always visible for multi-select. When any student * is selected, a bulk action bar appears. */ export function StudentSelector({ students, onSelectStudent, onToggleSelection, onAddStudent, title = 'Who is practicing today?', selectedIds = new Set(), hideAddButton = false, onObserveSession, enrollmentActions, compact = false, }: StudentSelectorProps) { const { resolvedTheme } = useTheme() const isDark = resolvedTheme === 'dark' // QuickLook/Notes modal state (unified NotesModal with tabs) const [modalOpen, setModalOpen] = useState(false) const [selectedStudent, setSelectedStudent] = useState<StudentWithProgress | null>(null) const [sourceBounds, setSourceBounds] = useState<DOMRect | null>(null) // Ref map for keyboard navigation const cardRefsRef = useRef<Map<string, HTMLDivElement>>(new Map()) // Student lookup for quick access by ID const studentMap = useRef<Map<string, StudentWithProgress>>(new Map()) useEffect(() => { studentMap.current.clear() for (const student of students) { studentMap.current.set(student.id, student) } }, [students]) // Register card ref callback const handleRegisterRef = useCallback((studentId: string, ref: HTMLDivElement | null) => { if (ref) { cardRefsRef.current.set(studentId, ref) } else { cardRefsRef.current.delete(studentId) } }, []) const handleOpenQuickLook = useCallback((student: StudentWithProgress, bounds: DOMRect) => { setSelectedStudent(student) setSourceBounds(bounds) setModalOpen(true) }, []) const handleCloseModal = useCallback(() => { setModalOpen(false) }, []) // Keyboard navigation when modal is open useEffect(() => { if (!modalOpen || !selectedStudent) return const handleKeyDown = (e: KeyboardEvent) => { // Only handle arrow keys if (!['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) return // Don't interfere with text input (notes editing) if (e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLInputElement) { return } // Don't interfere with dropdown menu navigation (Radix UI) if ( e.target instanceof HTMLElement && (e.target.closest('[data-radix-menu-content]') || e.target.getAttribute('role') === 'menuitem' || e.target.getAttribute('role') === 'menu') ) { return } e.preventDefault() const direction = e.key.replace('Arrow', '').toLowerCase() as 'up' | 'down' | 'left' | 'right' const next = findNextStudent(selectedStudent.id, direction, cardRefsRef.current) if (next) { const nextStudent = studentMap.current.get(next.studentId) if (nextStudent) { setSelectedStudent(nextStudent) setSourceBounds(next.bounds) } } } window.addEventListener('keydown', handleKeyDown) return () => window.removeEventListener('keydown', handleKeyDown) }, [modalOpen, selectedStudent]) // Compact mode: just render cards inline without wrapper styling if (compact) { return ( <> {students.map((student) => ( <StudentCard key={student.id} student={student} onSelect={onSelectStudent} onToggleSelection={onToggleSelection} onOpenQuickLook={handleOpenQuickLook} isSelected={selectedIds.has(student.id)} onObserveSession={onObserveSession} onRegisterRef={handleRegisterRef} enrollmentActions={enrollmentActions} /> ))} {/* Student QuickLook/Notes Modal (unified with tabs) */} {selectedStudent && ( <NotesModal isOpen={modalOpen} student={selectedStudent} sourceBounds={sourceBounds} onClose={handleCloseModal} onObserveSession={onObserveSession} /> )} </> ) } return ( <> <div data-component="student-selector" className={css({ ...centerStack, ...gapLg, ...paddingLg, })} > {/* Title */} <h2 className={css({ fontSize: '1.5rem', ...fontBold, color: themed('text', isDark), })} > {title} </h2> {/* Student grid */} <div className={css({ ...wrap, justifyContent: 'center', ...gapMd, })} > {students.map((student) => ( <StudentCard key={student.id} student={student} onSelect={onSelectStudent} onToggleSelection={onToggleSelection} onOpenQuickLook={handleOpenQuickLook} isSelected={selectedIds.has(student.id)} onObserveSession={onObserveSession} onRegisterRef={handleRegisterRef} enrollmentActions={enrollmentActions} /> ))} {!hideAddButton && onAddStudent && <AddStudentButton onClick={onAddStudent} />} </div> </div> {/* Student QuickLook/Notes Modal (unified with tabs) */} {selectedStudent && ( <NotesModal isOpen={modalOpen} student={selectedStudent} sourceBounds={sourceBounds} onClose={handleCloseModal} onObserveSession={onObserveSession} /> )} </> ) } export default StudentSelector |