fix: instructor formatting errors (#425)
* fix: instructor formatting errors * refactor: simplify logic in Instructor toString, remove unused formatters * refactor: remove "unnecessary" else's after returns I think it looks worse like this but whatever
This commit is contained in:
@@ -16,25 +16,6 @@ export default class Instructor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the URL to the instructor's directory page on the UT Directory website
|
|
||||||
*
|
|
||||||
* @returns A URL string to the instructor's directory page
|
|
||||||
*/
|
|
||||||
getDirectoryUrl(): string {
|
|
||||||
const name = this.toString({
|
|
||||||
format: 'full_name',
|
|
||||||
case: 'capitalize',
|
|
||||||
});
|
|
||||||
|
|
||||||
const url = new URL('https://directory.utexas.edu/index.php');
|
|
||||||
url.searchParams.set('q', name);
|
|
||||||
url.searchParams.set('scope', 'faculty/staff');
|
|
||||||
url.searchParams.set('submit', 'Search');
|
|
||||||
|
|
||||||
return url.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a string representation of the instructor
|
* Get a string representation of the instructor
|
||||||
*
|
*
|
||||||
@@ -43,43 +24,43 @@ export default class Instructor {
|
|||||||
*/
|
*/
|
||||||
toString(options: InstructorFormatOptions): string {
|
toString(options: InstructorFormatOptions): string {
|
||||||
const { firstName, lastName, fullName } = this;
|
const { firstName, lastName, fullName } = this;
|
||||||
const { format, case: caseType } = options;
|
const { format } = options;
|
||||||
|
|
||||||
const process = (str: string) => {
|
switch (format) {
|
||||||
if (caseType === 'lowercase') {
|
case 'first_last':
|
||||||
return str.toLowerCase();
|
if (firstName && lastName) {
|
||||||
}
|
return `${capitalize(firstName)} ${capitalize(lastName)}`;
|
||||||
if (caseType === 'uppercase') {
|
|
||||||
return str.toUpperCase();
|
|
||||||
}
|
|
||||||
return capitalize(str);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (format === 'abbr' && firstName && lastName && firstName[0]) {
|
|
||||||
return `${process(firstName[0])}. ${process(lastName)}`;
|
|
||||||
}
|
|
||||||
if (format === 'full_name' && fullName) {
|
|
||||||
return process(fullName);
|
|
||||||
}
|
|
||||||
if (format === 'first_last' && firstName && lastName) {
|
|
||||||
return `${process(firstName)} ${process(lastName)}`;
|
|
||||||
}
|
|
||||||
if (format === 'last' && lastName) {
|
|
||||||
return process(lastName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lastName) {
|
||||||
|
return capitalize(lastName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fullName) {
|
||||||
|
return fullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
case 'last':
|
||||||
|
if (lastName) {
|
||||||
|
return capitalize(lastName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fullName) {
|
||||||
|
return fullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
default:
|
||||||
throw new Error(`Invalid Instructor String format: ${format}`);
|
throw new Error(`Invalid Instructor String format: ${format}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for how to format the instructor string
|
* Options for how to format the instructor string
|
||||||
*/
|
*/
|
||||||
type InstructorFormatOptions = {
|
type InstructorFormatOptions = {
|
||||||
/** How do you want the names of the professors formatted */
|
/** How do you want the names of the professors formatted */
|
||||||
format: 'abbr' | 'first_last' | 'last' | 'full_name';
|
format: 'first_last' | 'last';
|
||||||
/**
|
|
||||||
* What the case of the string should be
|
|
||||||
*/
|
|
||||||
case: 'capitalize' | 'lowercase' | 'uppercase';
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export default function PopupCourseBlock({
|
|||||||
<Text className={clsx('flex-1 py-3.5 truncate', fontColor)} variant='h1-course'>
|
<Text className={clsx('flex-1 py-3.5 truncate', fontColor)} variant='h1-course'>
|
||||||
<span className='px-0.5 font-450'>{formattedUniqueId}</span> {course.department} {course.number}
|
<span className='px-0.5 font-450'>{formattedUniqueId}</span> {course.department} {course.number}
|
||||||
{course.instructors.length > 0 ? <> – </> : ''}
|
{course.instructors.length > 0 ? <> – </> : ''}
|
||||||
{course.instructors.map(v => v.toString({ format: 'last', case: 'capitalize' })).join('; ')}
|
{course.instructors.map(v => v.toString({ format: 'last' })).join('; ')}
|
||||||
</Text>
|
</Text>
|
||||||
{enableCourseStatusChips && course.status !== Status.OPEN && (
|
{enableCourseStatusChips && course.status !== Status.OPEN && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ export default function HeadingAndActions({ course, activeSchedule, onClose }: H
|
|||||||
const formattedUniqueId = uniqueId.toString().padStart(5, '0');
|
const formattedUniqueId = uniqueId.toString().padStart(5, '0');
|
||||||
const isInCalendar = useCalendar();
|
const isInCalendar = useCalendar();
|
||||||
|
|
||||||
const getInstructorFullName = (instructor: Instructor) =>
|
const getInstructorFullName = (instructor: Instructor) => instructor.toString({ format: 'first_last' });
|
||||||
instructor.toString({ format: 'first_last', case: 'capitalize' });
|
|
||||||
|
|
||||||
const handleCopy = () => {
|
const handleCopy = () => {
|
||||||
navigator.clipboard.writeText(formattedUniqueId);
|
navigator.clipboard.writeText(formattedUniqueId);
|
||||||
|
|||||||
@@ -98,9 +98,7 @@ function extractCourseInfo(course: Course) {
|
|||||||
|
|
||||||
if (course.instructors.length > 0) {
|
if (course.instructors.length > 0) {
|
||||||
courseDeptAndInstr += ' \u2013 ';
|
courseDeptAndInstr += ' \u2013 ';
|
||||||
courseDeptAndInstr += course.instructors
|
courseDeptAndInstr += course.instructors.map(instructor => instructor.toString({ format: 'last' })).join('; ');
|
||||||
.map(instructor => instructor.toString({ format: 'last', case: 'capitalize' }))
|
|
||||||
.join('; ');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { status, courseDeptAndInstr, meetings, course };
|
return { status, courseDeptAndInstr, meetings, course };
|
||||||
|
|||||||
Reference in New Issue
Block a user