* fix: update CourseCellColorPicker.tsx background to white * feat: add color picker to CalendarCourseCell component * feat: add color picker functionality to update course colors * fix: type issues with storybook components * feat: add useColorPicker hook, isValidHexColor and updateCourseColors utilities * refactor: color picker logic and UI components * refactor: update useFlattenedCourseSchedule hook to include courseID property * refactor: update storybook calendar components with updated props * refactor: update color picker ui logic to account for position of cell * fix: revert back to error handling for invalid rgb * refactor: update jsdocs * refactor: integrate ColorPickerContext into Calendar components and update props * refactor: integrate ColorPickerContext into Calendar components and update related props * refactor: change JSDocs comments and remove unused color inversion state * refactor: update story components * feat: add functionality for selecting secondary course colors * refactor: enhance HexColorEditor to dynamically adjust tag icon color based on preview color * refactor: simplify JSDoc comment in useColorPicker hook * fix: revert Button component * refactor: update CalendarCourseCell component positioning and styling * fix: correct types in color.ts * feat: add getDarkerShade function to compute darker shades of hex colors * feat: add shadow to color picker button * fix: update button size in ColorPatch component * feat: implement debounced input for hex color editor and add useDebounce hook * chore: utilize the logical and && operator instead of the ternary operator * fix: imports and palette icon * refactor: remove unused import * fix: bug when course add fails with custom colors * chore: run lint * chore: run check-types * feat: add HSL color type and conversion functions * refactor: rename colorway to theme * fix: hide color picker on screenshot * fix: undo important syntax * refactor: rename SomeFunction to DebouncedCallback * refactor: remove inner function * refactor: update return type to DebouncedCallback * fix: adjust sizes for hash and palette button * feat: create tests for hexToHSL and isValidHexColor * refactor: update parameter type to use HexColor * fix: increase size of palette button * fix: update dependency array for hex code debounce * fix: change colorPickerRef element ref --------- Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
208 lines
9.2 KiB
TypeScript
208 lines
9.2 KiB
TypeScript
import { ArrowUpRight, CalendarDots, ChatText, Copy, FileText, Minus, Plus, Smiley, X } from '@phosphor-icons/react';
|
|
import { background } from '@shared/messages';
|
|
import type { Course } from '@shared/types/Course';
|
|
import type Instructor from '@shared/types/Instructor';
|
|
import type { UserSchedule } from '@shared/types/UserSchedule';
|
|
import { Button } from '@views/components/common/Button';
|
|
import { Chip, coreMap, flagMap } from '@views/components/common/Chip';
|
|
import Divider from '@views/components/common/Divider';
|
|
import Link from '@views/components/common/Link';
|
|
import Text from '@views/components/common/Text/Text';
|
|
import { useCalendar } from '@views/contexts/CalendarContext';
|
|
import React from 'react';
|
|
|
|
import DisplayMeetingInfo from './DisplayMeetingInfo';
|
|
|
|
const { openNewTab, addCourse, removeCourse, openCESPage } = background;
|
|
|
|
/**
|
|
* Capitalizes the first letter of a string and converts the rest of the letters to lowercase.
|
|
*
|
|
* @param str - The string to be capitalized.
|
|
* @returns The capitalized string.
|
|
*/
|
|
const capitalizeString = (str: string) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
|
|
interface HeadingAndActionProps {
|
|
/* The course to display */
|
|
course: Course;
|
|
/* The active schedule */
|
|
activeSchedule: UserSchedule;
|
|
/* The function to call when the popup should be closed */
|
|
onClose: () => void;
|
|
}
|
|
|
|
/**
|
|
* Renders the heading component for the CoursePopup component.
|
|
*
|
|
* @param course - The course object containing course details.
|
|
* @param activeSchedule - The active schedule object.
|
|
* @param onClose - The function to close the popup.
|
|
* @returns The rendered component.
|
|
*/
|
|
export default function HeadingAndActions({ course, activeSchedule, onClose }: HeadingAndActionProps): JSX.Element {
|
|
const { courseName, department, number: courseNumber, uniqueId, instructors, flags, core } = course;
|
|
const courseAdded = activeSchedule.courses.some(ourCourse => ourCourse.uniqueId === uniqueId);
|
|
const formattedUniqueId = uniqueId.toString().padStart(5, '0');
|
|
const isInCalendar = useCalendar();
|
|
|
|
const getInstructorFullName = (instructor: Instructor) => instructor.toString({ format: 'first_last' });
|
|
|
|
const handleCopy = () => {
|
|
navigator.clipboard.writeText(formattedUniqueId);
|
|
};
|
|
|
|
const handleOpenRateMyProf = async () => {
|
|
const openTabs = instructors.map(instructor => {
|
|
const instructorSearchTerm = getInstructorFullName(instructor);
|
|
instructorSearchTerm.replace(' ', '+');
|
|
const url = `https://www.ratemyprofessors.com/search/professors/1255?q=${instructorSearchTerm}`;
|
|
return openNewTab({ url });
|
|
});
|
|
await Promise.all(openTabs);
|
|
};
|
|
|
|
const handleOpenCES = async () => {
|
|
const openTabs = instructors.map(instructor => {
|
|
let { firstName = '', lastName = '' } = instructor;
|
|
firstName = capitalizeString(firstName);
|
|
lastName = capitalizeString(lastName);
|
|
return openCESPage({ instructorFirstName: firstName, instructorLastName: lastName });
|
|
});
|
|
await Promise.all(openTabs);
|
|
};
|
|
|
|
const handleOpenPastSyllabi = async () => {
|
|
for (const instructor of instructors) {
|
|
let { firstName = '', lastName = '' } = instructor;
|
|
firstName = capitalizeString(firstName);
|
|
lastName = capitalizeString(lastName);
|
|
const url = `https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?year=&semester=&department=${department}&course_number=${courseNumber}&course_title=&unique=&instructor_first=${firstName}&instructor_last=${lastName}&course_type=In+Residence&search=Search`;
|
|
openNewTab({ url });
|
|
}
|
|
|
|
// Show the course's syllabi when no instructors listed
|
|
if (instructors.length === 0) {
|
|
const url = `https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?year=&semester=&department=${department}&course_number=${courseNumber}&course_title=&unique=&instructor_first=&instructor_last=&course_type=In+Residence&search=Search`;
|
|
openNewTab({ url });
|
|
}
|
|
};
|
|
|
|
const handleAddOrRemoveCourse = async () => {
|
|
if (!activeSchedule) return;
|
|
if (!courseAdded) {
|
|
addCourse({ course, scheduleId: activeSchedule.id });
|
|
} else {
|
|
removeCourse({ course, scheduleId: activeSchedule.id });
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className='w-full px-2 pb-3 pt-5 text-ut-black'>
|
|
<div className='flex flex-col'>
|
|
<div className='flex items-center gap-1'>
|
|
<Text variant='h1' className='truncate text-theme-black'>
|
|
{courseName}
|
|
</Text>
|
|
<Text variant='h1' className='flex-1 whitespace-nowrap text-theme-black'>
|
|
({department} {courseNumber})
|
|
</Text>
|
|
<Button color='ut-burntorange' variant='minimal' icon={Copy} onClick={handleCopy}>
|
|
{formattedUniqueId}
|
|
</Button>
|
|
<button className='bg-transparent p-0 text-ut-black btn' onClick={onClose}>
|
|
<X className='h-6 w-6' />
|
|
</button>
|
|
</div>
|
|
<div className='flex items-center gap-2'>
|
|
{instructors.length > 0 ? (
|
|
<Text variant='h4' as='p'>
|
|
with{' '}
|
|
{instructors
|
|
.map(instructor => (
|
|
<Link
|
|
key={instructor.fullName}
|
|
variant='h4'
|
|
href={`https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?year=&semester=&course_title=&unique=&instructor_first=${instructor.firstName}&instructor_last=${instructor.lastName}&course_type=In+Residence&search=Search`}
|
|
className='link'
|
|
>
|
|
{getInstructorFullName(instructor)}
|
|
</Link>
|
|
))
|
|
.flatMap((el, i) => (i === 0 ? [el] : [', ', el]))}
|
|
</Text>
|
|
) : (
|
|
<Text variant='h4' as='p'>
|
|
(No instructor has been provided)
|
|
</Text>
|
|
)}
|
|
<div className='flex items-center gap-1'>
|
|
{flags.map((flag: string) => (
|
|
<Chip
|
|
key={flagMap[flag as keyof typeof flagMap]}
|
|
label={flagMap[flag as keyof typeof flagMap]}
|
|
variant='flag'
|
|
/>
|
|
))}
|
|
{core.map((coreVal: string) => (
|
|
<Chip
|
|
key={coreMap[coreVal as keyof typeof coreMap]}
|
|
label={coreMap[coreVal as keyof typeof coreMap]}
|
|
variant='core'
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
<DisplayMeetingInfo course={course} />
|
|
</div>
|
|
<div className='my-3 flex flex-wrap items-center gap-x-3.75 gap-y-2.5'>
|
|
<Button
|
|
variant='filled'
|
|
color='ut-burntorange'
|
|
icon={isInCalendar ? ArrowUpRight : CalendarDots}
|
|
onClick={() => {
|
|
if (isInCalendar) {
|
|
openNewTab({
|
|
url: course.url,
|
|
});
|
|
} else {
|
|
background.switchToCalendarTab({});
|
|
}
|
|
}}
|
|
/>
|
|
<Divider size='1.75rem' orientation='vertical' />
|
|
<Button
|
|
variant='outline'
|
|
color='ut-blue'
|
|
icon={ChatText}
|
|
onClick={handleOpenRateMyProf}
|
|
disabled={instructors.length === 0}
|
|
>
|
|
RateMyProf
|
|
</Button>
|
|
<Button
|
|
variant='outline'
|
|
color='ut-teal'
|
|
icon={Smiley}
|
|
onClick={handleOpenCES}
|
|
disabled={instructors.length === 0}
|
|
>
|
|
CES
|
|
</Button>
|
|
<Button variant='outline' color='ut-orange' icon={FileText} onClick={handleOpenPastSyllabi}>
|
|
Past Syllabi
|
|
</Button>
|
|
<Button
|
|
variant='filled'
|
|
color={!courseAdded ? 'ut-green' : 'theme-red'}
|
|
icon={!courseAdded ? Plus : Minus}
|
|
onClick={handleAddOrRemoveCourse}
|
|
>
|
|
{!courseAdded ? 'Add Course' : 'Remove Course'}
|
|
</Button>
|
|
</div>
|
|
<Divider orientation='horizontal' size='100%' />
|
|
</div>
|
|
);
|
|
}
|