add course button onclick handlers
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import addCourse from 'src/pages/background/lib/addCourse';
|
||||||
|
import openNewTab from 'src/pages/background/util/openNewTab';
|
||||||
import { Course } from 'src/shared/types/Course';
|
import { Course } from 'src/shared/types/Course';
|
||||||
|
import { UserSchedule } from 'src/shared/types/UserSchedule';
|
||||||
import Add from '~icons/material-symbols/add';
|
import Add from '~icons/material-symbols/add';
|
||||||
import CalendarMonth from '~icons/material-symbols/calendar-month';
|
import CalendarMonth from '~icons/material-symbols/calendar-month';
|
||||||
import CloseIcon from '~icons/material-symbols/close';
|
import CloseIcon from '~icons/material-symbols/close';
|
||||||
@@ -15,6 +18,8 @@ import Text from '../../common/Text/Text';
|
|||||||
interface CourseHeadingAndActionsProps {
|
interface CourseHeadingAndActionsProps {
|
||||||
/* The course to display */
|
/* The course to display */
|
||||||
course: Course;
|
course: Course;
|
||||||
|
/* The active schedule */
|
||||||
|
activeSchedule: UserSchedule;
|
||||||
/* The function to call when the popup should be closed */
|
/* The function to call when the popup should be closed */
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
@@ -25,8 +30,8 @@ interface CourseHeadingAndActionsProps {
|
|||||||
* @param {CourseHeadingAndActionsProps} props - The component props.
|
* @param {CourseHeadingAndActionsProps} props - The component props.
|
||||||
* @returns {JSX.Element} The rendered component.
|
* @returns {JSX.Element} The rendered component.
|
||||||
*/
|
*/
|
||||||
const CourseHeadingAndActions = ({ course, onClose }: CourseHeadingAndActionsProps) => {
|
const CourseHeadingAndActions = ({ course, onClose, activeSchedule }: CourseHeadingAndActionsProps) => {
|
||||||
const { courseName, department, number, uniqueId, instructors, flags, schedule } = course;
|
const { courseName, department, number: courseNumber, uniqueId, instructors, flags, schedule, semester } = course;
|
||||||
const instructorString = instructors
|
const instructorString = instructors
|
||||||
.map(instructor => {
|
.map(instructor => {
|
||||||
const { firstName, lastName } = instructor;
|
const { firstName, lastName } = instructor;
|
||||||
@@ -39,12 +44,28 @@ const CourseHeadingAndActions = ({ course, onClose }: CourseHeadingAndActionsPro
|
|||||||
navigator.clipboard.writeText(uniqueId.toString());
|
navigator.clipboard.writeText(uniqueId.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpenRateMyProf = () => {
|
const handleOpenRateMyProf = async () => {
|
||||||
instructors.forEach(instructor => {
|
const openTabs = instructors.map(instructor => {
|
||||||
const { fullName } = instructor;
|
const { fullName } = instructor;
|
||||||
const url = `https://www.ratemyprofessors.com/search/professors/1255?q=${fullName}`;
|
const url = `https://www.ratemyprofessors.com/search/professors/1255?q=${fullName}`;
|
||||||
window.open(url, '_blank')?.focus();
|
return openNewTab(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await Promise.all(openTabs);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOpenCES = () => {
|
||||||
|
// TODO: not implemented
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOpenPastSyllabi = async () => {
|
||||||
|
const firstInstructor = instructors[0];
|
||||||
|
const url = `https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?year=&semester=${semester}&department=${department}&course_number=${courseNumber}&course_title=${courseName}&unique=${uniqueId}&instructor_first=${firstInstructor.firstName}&instructor_last=${firstInstructor.lastName}&course_type=In+Residence&search=Search`;
|
||||||
|
await openNewTab(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAddCourse = async () => {
|
||||||
|
await addCourse(activeSchedule.name, course);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -56,12 +77,12 @@ const CourseHeadingAndActions = ({ course, onClose }: CourseHeadingAndActionsPro
|
|||||||
</Text>
|
</Text>
|
||||||
<Text variant='h1' className='flex-1 whitespace-nowrap'>
|
<Text variant='h1' className='flex-1 whitespace-nowrap'>
|
||||||
{' '}
|
{' '}
|
||||||
({department} {number})
|
({department} {courseNumber})
|
||||||
</Text>
|
</Text>
|
||||||
<Button color='ut-burntorange' variant='single' icon={Copy} onClick={handleCopy}>
|
<Button color='ut-burntorange' variant='single' icon={Copy} onClick={handleCopy}>
|
||||||
{uniqueId}
|
{uniqueId}
|
||||||
</Button>
|
</Button>
|
||||||
<button className='btn bg-transparent p-0'>
|
<button className='btn bg-transparent p-0' onClick={onClose}>
|
||||||
<CloseIcon className='h-7 w-7' />
|
<CloseIcon className='h-7 w-7' />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -98,13 +119,13 @@ const CourseHeadingAndActions = ({ course, onClose }: CourseHeadingAndActionsPro
|
|||||||
<Button variant='outline' color='ut-blue' icon={Reviews} onClick={handleOpenRateMyProf}>
|
<Button variant='outline' color='ut-blue' icon={Reviews} onClick={handleOpenRateMyProf}>
|
||||||
RateMyProf
|
RateMyProf
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='outline' color='ut-teal' icon={Mood}>
|
<Button variant='outline' color='ut-teal' icon={Mood} onClick={handleOpenCES}>
|
||||||
CES
|
CES
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='outline' color='ut-orange' icon={Description}>
|
<Button variant='outline' color='ut-orange' icon={Description} onClick={handleOpenPastSyllabi}>
|
||||||
Past Syllabi
|
Past Syllabi
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='filled' color='ut-green' icon={Add}>
|
<Button variant='filled' color='ut-green' icon={Add} onClick={handleAddCourse}>
|
||||||
Add Course
|
Add Course
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ interface CoursePopup2Props {
|
|||||||
const CoursePopup2 = ({ course, activeSchedule, onClose }: CoursePopup2Props) => (
|
const CoursePopup2 = ({ course, activeSchedule, onClose }: CoursePopup2Props) => (
|
||||||
<Popup overlay className='px-6' onClose={onClose}>
|
<Popup overlay className='px-6' onClose={onClose}>
|
||||||
<div className='flex flex-col'>
|
<div className='flex flex-col'>
|
||||||
<CourseHeadingAndActions course={course} onClose={onClose} />
|
<CourseHeadingAndActions course={course} onClose={onClose} activeSchedule={activeSchedule} />
|
||||||
</div>
|
</div>
|
||||||
</Popup>
|
</Popup>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user