import React from 'react'; import { Course } from 'src/shared/types/Course'; import { UserSchedule } from 'src/shared/types/UserSchedule'; import Card from 'src/views/components/common/Card/Card'; import Icon from 'src/views/components/common/Icon/Icon'; import Link from 'src/views/components/common/Link/Link'; import Text from 'src/views/components/common/Text/Text'; import CourseButtons from './CourseButtons/CourseButtons'; import styles from './CourseHeader.module.scss'; type Props = { course: Course; activeSchedule?: UserSchedule; onClose: () => void; }; /** * This component displays the header of the course info popup. * It displays the course name, unique id, instructors, and schedule, all formatted nicely. */ export default function CourseHeader({ course, activeSchedule, onClose }: Props) { const getBuildingUrl = (building?: string): string | undefined => { if (!building) return undefined; return `https://utdirect.utexas.edu/apps/campus/buildings/nlogon/maps/UTM/${building}/`; }; return (
{course.courseName} ({course.department} {course.number}) #{course.uniqueId}
{`with ${!course.instructors.length ? 'TBA' : ''}`} {course.instructors.map((instructor, index) => { const name = instructor.toString({ format: 'first_last', case: 'capitalize', }); const url = instructor.getDirectoryUrl(); const numInstructors = course.instructors.length; const isLast = course.instructors.length > 1 && index === course.instructors.length - 1; return ( <> {numInstructors > 1 && index === course.instructors.length - 1 ? '& ' : ''} {name} {numInstructors > 2 && !isLast ? ', ' : ''} ); })} {course.schedule.meetings.map(meeting => ( {meeting.getDaysString({ format: 'long', separator: 'short', })} {' at '} {meeting.getTimeString({ separator: 'to', capitalize: true, })} {' in '} {meeting.location?.building ?? 'TBA'} ))}
); }