fix: injected course popup storybook
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
"react": "^18.2.0",
|
||||
"react-devtools-core": "^5.0.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-window": "^1.8.10",
|
||||
"sass": "^1.71.1",
|
||||
"sql.js": "1.10.2",
|
||||
"styled-components": "^6.1.8",
|
||||
|
||||
2491
pnpm-lock.yaml
generated
2491
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
import { Course, Status } from '@shared/types/Course';
|
||||
import { UserSchedule } from '@shared/types/UserSchedule';
|
||||
import type { Meta, StoryObj } from '@storybook/react';
|
||||
import { Serialized } from 'chrome-extension-toolkit';
|
||||
import type { Serialized } from 'chrome-extension-toolkit';
|
||||
import React from 'react';
|
||||
import { CourseMeeting, DAY_MAP } from 'src/shared/types/CourseMeeting';
|
||||
import { CourseSchedule } from 'src/shared/types/CourseSchedule';
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react';
|
||||
import type { Serialized } from 'chrome-extension-toolkit';
|
||||
import { Course, Status } from 'src/shared/types/Course';
|
||||
import { CourseMeeting, DAY_MAP } from 'src/shared/types/CourseMeeting';
|
||||
import { CourseSchedule } from 'src/shared/types/CourseSchedule';
|
||||
import Instructor from 'src/shared/types/Instructor';
|
||||
|
||||
import { UserSchedule } from 'src/shared/types/UserSchedule';
|
||||
import CourseCatalogInjectedPopup from 'src/views/components/injected/CourseCatalogInjectedPopup/CourseCatalogInjectedPopup';
|
||||
|
||||
const exampleCourse: Course = new Course({
|
||||
@@ -51,11 +52,19 @@ const exampleCourse: Course = new Course({
|
||||
},
|
||||
});
|
||||
|
||||
const exampleSchedule = new UserSchedule({
|
||||
name: 'Example Schedule',
|
||||
courses: [exampleCourse],
|
||||
hours: 3,
|
||||
} as Serialized<UserSchedule>);
|
||||
|
||||
const meta: Meta<typeof CourseCatalogInjectedPopup> = {
|
||||
title: 'Components/Injected/CourseCatalogInjectedPopup',
|
||||
component: CourseCatalogInjectedPopup,
|
||||
argTypes: {
|
||||
onClose: { action: 'onClose' },
|
||||
activeSchedule: { control: 'object' },
|
||||
course: { control: 'object' },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -64,6 +73,7 @@ type Story = StoryObj<typeof CourseCatalogInjectedPopup>;
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
activeSchedule: exampleSchedule,
|
||||
course: exampleCourse,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,97 +1,154 @@
|
||||
import React from 'react';
|
||||
import { FaCalendarAlt, FaCog, FaRedo } from 'react-icons/fa'; // Added FaRedo for the refresh icon
|
||||
import { StatusIcon } from '@shared/util/icons';
|
||||
import React from 'react';
|
||||
// import { FaCalendarAlt, FaCog, FaRedo } from 'react-icons/fa'; // Added FaRedo for the refresh icon
|
||||
import { Status } from 'src/shared/types/Course';
|
||||
import { test_colors } from 'src/stories/components/PopupCourseBlock.stories';
|
||||
import logoImage from '../../assets/logo.png'; // Adjust the path as necessary
|
||||
import useSchedules from '../hooks/useSchedules';
|
||||
import { openTabFromContentScript } from '../lib/openNewTabFromContentScript';
|
||||
import Divider from './common/Divider/Divider';
|
||||
import ExtensionRoot from './common/ExtensionRoot/ExtensionRoot';
|
||||
import List from './common/List/List'; // Ensure this path is correctly pointing to your List component
|
||||
import PopupCourseBlock from './common/PopupCourseBlock/PopupCourseBlock';
|
||||
import Text from './common/Text/Text';
|
||||
import Divider from './common/Divider/Divider';
|
||||
import logoImage from '../../assets/logo.png'; // Adjust the path as necessary
|
||||
import List from './common/List/List'; // Ensure this path is correctly pointing to your List component
|
||||
import useSchedules from '../hooks/useSchedules';
|
||||
import { handleOpenCalendar } from './injected/CourseCatalogInjectedPopup/HeadingAndActions';
|
||||
import { openTabFromContentScript } from '../lib/openNewTabFromContentScript';
|
||||
|
||||
|
||||
export default function PopupMain() {
|
||||
const [activeSchedule] = useSchedules();
|
||||
const [activeSchedule] = useSchedules();
|
||||
|
||||
|
||||
const draggableElements = activeSchedule?.courses.map((course, i) => (
|
||||
<PopupCourseBlock
|
||||
key={course.uniqueId}
|
||||
course={course}
|
||||
colors={test_colors[i]}
|
||||
/>
|
||||
const draggableElements = activeSchedule?.courses.map((course, i) => (
|
||||
<PopupCourseBlock key={course.uniqueId} course={course} colors={test_colors[i]} />
|
||||
));
|
||||
|
||||
const handleOpenOptions = async () => { // Not sure if it's bad practice to export this
|
||||
const handleOpenOptions = async () => {
|
||||
// Not sure if it's bad practice to export this
|
||||
const url = chrome.runtime.getURL('/src/pages/options/index.html');
|
||||
await openTabFromContentScript(url);
|
||||
};
|
||||
|
||||
return (
|
||||
<ExtensionRoot>
|
||||
<div className="mx-auto max-w-sm rounded-lg bg-white p-4 shadow-md">
|
||||
<div className="mb-2 flex items-center justify-between bg-white">
|
||||
<div className="flex items-center">
|
||||
<img src={logoImage} alt="Logo" style={{ width: '40px', height: '40px', marginRight: '8px' }} />
|
||||
<div className='mx-auto max-w-sm rounded-lg bg-white p-4 shadow-md'>
|
||||
<div className='mb-2 flex items-center justify-between bg-white'>
|
||||
<div className='flex items-center'>
|
||||
<img src={logoImage} alt='Logo' style={{ width: '40px', height: '40px', marginRight: '8px' }} />
|
||||
<div>
|
||||
<Text as="div" variant="h1-course" style={{ color: '#bf5700', fontSize: '1.3rem' }}>UT Registration</Text>
|
||||
<Text as="div" variant="h1-course" style={{ color: '#f8971f', fontSize: '1.3rem' }}>Plus</Text>
|
||||
<Text as='div' variant='h1-course' style={{ color: '#bf5700', fontSize: '1.3rem' }}>
|
||||
UT Registration
|
||||
</Text>
|
||||
<Text as='div' variant='h1-course' style={{ color: '#f8971f', fontSize: '1.3rem' }}>
|
||||
Plus
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<button style={{ backgroundColor: '#bf5700', borderRadius: '8px', padding: '8px' }} onClick={handleOpenCalendar}>
|
||||
<FaCalendarAlt color="white" />
|
||||
<div className='flex items-center'>
|
||||
<button
|
||||
style={{ backgroundColor: '#bf5700', borderRadius: '8px', padding: '8px' }}
|
||||
onClick={handleOpenCalendar}
|
||||
>
|
||||
{/* <FaCalendarAlt color='white' /> */}
|
||||
</button>
|
||||
<button style={{ backgroundColor: 'white', marginLeft: '10px', borderRadius: '8px', padding: '8px', boxShadow: '0px 2px 4px rgba(0, 0, 0, 0.1)' }}
|
||||
onClick = {handleOpenOptions}>
|
||||
<FaCog color="#C05621" />
|
||||
<button
|
||||
style={{
|
||||
backgroundColor: 'white',
|
||||
marginLeft: '10px',
|
||||
borderRadius: '8px',
|
||||
padding: '8px',
|
||||
boxShadow: '0px 2px 4px rgba(0, 0, 0, 0.1)',
|
||||
}}
|
||||
onClick={handleOpenOptions}
|
||||
>
|
||||
{/* <FaCog color='#C05621' /> */}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<Divider color="#E2E8F0" type="solid" style={{ margin: '1rem 0' }} />
|
||||
<div className="mb-4 rounded-lg bg-white p-2 text-left shadow-inner" style={{ backgroundColor: 'white', border: '1px solid #FBD38D', borderRadius: '0.5rem' }}>
|
||||
<Text as="div" variant="h2-course" style={{ color: '#DD6B20', fontSize: '1.2rem' }}>MAIN SCHEDULE:</Text>
|
||||
<Divider color='#E2E8F0' type='solid' style={{ margin: '1rem 0' }} />
|
||||
<div
|
||||
className='mb-4 rounded-lg bg-white p-2 text-left shadow-inner'
|
||||
style={{ backgroundColor: 'white', border: '1px solid #FBD38D', borderRadius: '0.5rem' }}
|
||||
>
|
||||
<Text as='div' variant='h2-course' style={{ color: '#DD6B20', fontSize: '1.2rem' }}>
|
||||
MAIN SCHEDULE:
|
||||
</Text>
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'start', color: '#333f48' }}>
|
||||
<Text as="div" variant="h1" style={{ fontSize: '1.2rem', fontWeight: 'bold', marginRight: '0.5rem' }}>22 HOURS</Text>
|
||||
<Text as="div" variant="h2-course" style={{ fontSize: '1.2rem' }}>8 Courses</Text>
|
||||
<Text
|
||||
as='div'
|
||||
variant='h1'
|
||||
style={{ fontSize: '1.2rem', fontWeight: 'bold', marginRight: '0.5rem' }}
|
||||
>
|
||||
22 HOURS
|
||||
</Text>
|
||||
<Text as='div' variant='h2-course' style={{ fontSize: '1.2rem' }}>
|
||||
8 Courses
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
{/* Integrate the List component here */}
|
||||
{activeSchedule ? <List
|
||||
draggableElements={draggableElements}
|
||||
itemHeight={100} // Adjust based on your content size
|
||||
listHeight={500} // Adjust based on total height you want for the list
|
||||
listWidth={350} // Adjust based on your layout/design
|
||||
gap={12} // Spacing between items
|
||||
/> : null}
|
||||
<div className="mt-4 flex justify-between border-t border-gray-200 p-4 text-xs">
|
||||
<div className="flex items-center">
|
||||
<div style={{ backgroundColor: '#6B7280', padding: '1px', borderRadius: '4px', marginRight: '3px', marginLeft: '8px' }}>
|
||||
<StatusIcon status={Status.WAITLISTED} className="h-5 w-5 text-white" />
|
||||
{activeSchedule ? (
|
||||
<List
|
||||
draggableElements={draggableElements}
|
||||
itemHeight={100} // Adjust based on your content size
|
||||
listHeight={500} // Adjust based on total height you want for the list
|
||||
listWidth={350} // Adjust based on your layout/design
|
||||
gap={12} // Spacing between items
|
||||
/>
|
||||
) : null}
|
||||
<div className='mt-4 flex justify-between border-t border-gray-200 p-4 text-xs'>
|
||||
<div className='flex items-center'>
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: '#6B7280',
|
||||
padding: '1px',
|
||||
borderRadius: '4px',
|
||||
marginRight: '3px',
|
||||
marginLeft: '8px',
|
||||
}}
|
||||
>
|
||||
<StatusIcon status={Status.WAITLISTED} className='h-5 w-5 text-white' />
|
||||
</div>
|
||||
<Text as="span" variant="mini">WAITLISTED</Text>
|
||||
<Text as='span' variant='mini'>
|
||||
WAITLISTED
|
||||
</Text>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<div style={{ backgroundColor: '#6B7280', padding: '1px', borderRadius: '4px', marginRight: '3px', marginLeft: '8px' }}>
|
||||
<StatusIcon status={Status.CLOSED} className="h-5 w-5 text-white" />
|
||||
<div className='flex items-center'>
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: '#6B7280',
|
||||
padding: '1px',
|
||||
borderRadius: '4px',
|
||||
marginRight: '3px',
|
||||
marginLeft: '8px',
|
||||
}}
|
||||
>
|
||||
<StatusIcon status={Status.CLOSED} className='h-5 w-5 text-white' />
|
||||
</div>
|
||||
<Text as="span" variant="mini">CLOSED</Text>
|
||||
<Text as='span' variant='mini'>
|
||||
CLOSED
|
||||
</Text>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<div style={{ backgroundColor: '#6B7280', padding: '1px', borderRadius: '4px', marginRight: '3px', marginLeft: '8px' }}>
|
||||
<StatusIcon status={Status.CANCELLED} className="h-5 w-5 text-white" />
|
||||
<div className='flex items-center'>
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: '#6B7280',
|
||||
padding: '1px',
|
||||
borderRadius: '4px',
|
||||
marginRight: '3px',
|
||||
marginLeft: '8px',
|
||||
}}
|
||||
>
|
||||
<StatusIcon status={Status.CANCELLED} className='h-5 w-5 text-white' />
|
||||
</div>
|
||||
<Text as="span" variant="mini">CANCELLED</Text>
|
||||
<Text as='span' variant='mini'>
|
||||
CANCELLED
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-2 text-center text-xs">
|
||||
<div className="inline-flex items-center justify-center">
|
||||
<Text as="div" variant="mini">DATA UPDATED ON: 12:00 AM 02/01/2024</Text>
|
||||
<FaRedo className="ml-2 h-4 w-4 text-gray-600" />
|
||||
<div className='mt-2 text-center text-xs'>
|
||||
<div className='inline-flex items-center justify-center'>
|
||||
<Text as='div' variant='mini'>
|
||||
DATA UPDATED ON: 12:00 AM 02/01/2024
|
||||
</Text>
|
||||
{/* <FaRedo className='ml-2 h-4 w-4 text-gray-600' /> */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { DragDropContext, Draggable, Droppable } from '@hello-pangea/dnd';
|
||||
import React, { ReactElement, useCallback, useState } from 'react';
|
||||
import type { ReactElement } from 'react';
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { areEqual } from 'react-window';
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import clsx from 'clsx';
|
||||
import React, { PropsWithChildren, useCallback } from 'react';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import React, { useCallback } from 'react';
|
||||
|
||||
import styles from './Popup.module.scss';
|
||||
|
||||
interface Props {
|
||||
@@ -19,8 +21,6 @@ export default function Popup({ onClose, children, className, style, testId, ove
|
||||
const containerRef = React.useRef<HTMLDivElement>(null);
|
||||
const bodyRef = React.useRef<HTMLDivElement>(null);
|
||||
|
||||
|
||||
|
||||
const handleClickOutside = useCallback(
|
||||
(event: MouseEvent) => {
|
||||
if (!bodyRef.current) return;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import Popup from '@views/components/common/Popup/Popup';
|
||||
import React from 'react';
|
||||
import { Course } from 'src/shared/types/Course';
|
||||
import { UserSchedule } from 'src/shared/types/UserSchedule';
|
||||
import type { Course } from 'src/shared/types/Course';
|
||||
import type { UserSchedule } from 'src/shared/types/UserSchedule';
|
||||
|
||||
import Description from './Description';
|
||||
import GradeDistribution from './GradeDistribution';
|
||||
import HeadingAndActions from './HeadingAndActions';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import clsx from 'clsx';
|
||||
import React from 'react';
|
||||
|
||||
import Text from '../../common/Text/Text';
|
||||
|
||||
interface DescriptionProps {
|
||||
|
||||
@@ -3,8 +3,8 @@ import Text from '@views/components/common/Text/Text';
|
||||
import Highcharts from 'highcharts';
|
||||
import HighchartsReact from 'highcharts-react-official';
|
||||
import React from 'react';
|
||||
import { Course } from 'src/shared/types/Course';
|
||||
import { Distribution, LetterGrade } from 'src/shared/types/Distribution';
|
||||
import type { Course } from 'src/shared/types/Course';
|
||||
import type { Distribution, LetterGrade } from 'src/shared/types/Distribution';
|
||||
import { colors } from 'src/shared/util/themeColors';
|
||||
import {
|
||||
NoDataError,
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Button } from '@views/components/common/Button/Button';
|
||||
import { Chip, flagMap } from '@views/components/common/Chip/Chip';
|
||||
import Divider from '@views/components/common/Divider/Divider';
|
||||
import Text from '@views/components/common/Text/Text';
|
||||
import React, { useState } from 'react';
|
||||
import addCourse from 'src/pages/background/lib/addCourse';
|
||||
import removeCourse from 'src/pages/background/lib/removeCourse';
|
||||
import type { Course } from 'src/shared/types/Course';
|
||||
import type { UserSchedule } from 'src/shared/types/UserSchedule';
|
||||
import { openTabFromContentScript } from 'src/views/lib/openNewTabFromContentScript';
|
||||
import { Course } from 'src/shared/types/Course';
|
||||
import { UserSchedule } from 'src/shared/types/UserSchedule';
|
||||
|
||||
import Add from '~icons/material-symbols/add';
|
||||
import Remove from '~icons/material-symbols/remove';
|
||||
import CalendarMonth from '~icons/material-symbols/calendar-month';
|
||||
import CloseIcon from '~icons/material-symbols/close';
|
||||
import Copy from '~icons/material-symbols/content-copy';
|
||||
import Description from '~icons/material-symbols/description';
|
||||
import Mood from '~icons/material-symbols/mood';
|
||||
import Remove from '~icons/material-symbols/remove';
|
||||
import Reviews from '~icons/material-symbols/reviews';
|
||||
|
||||
interface HeadingAndActionProps {
|
||||
@@ -26,7 +27,8 @@ interface HeadingAndActionProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const handleOpenCalendar = async () => { // Not sure if it's bad practice to export this
|
||||
export const handleOpenCalendar = async () => {
|
||||
// Not sure if it's bad practice to export this
|
||||
const url = chrome.runtime.getURL('calendar.html');
|
||||
await openTabFromContentScript(url);
|
||||
};
|
||||
@@ -41,7 +43,7 @@ const HeadingAndActions: React.FC<HeadingAndActionProps> = ({ course, onClose, a
|
||||
const { courseName, department, number: courseNumber, uniqueId, instructors, flags, schedule } = course;
|
||||
const [courseAdded, setCourseAdded] = useState<boolean>(
|
||||
activeSchedule.courses.some(course => course.uniqueId === uniqueId)
|
||||
);
|
||||
);
|
||||
|
||||
const instructorString = instructors
|
||||
.map(instructor => {
|
||||
@@ -74,8 +76,7 @@ const HeadingAndActions: React.FC<HeadingAndActionProps> = ({ course, onClose, a
|
||||
const handleAddOrRemoveCourse = async () => {
|
||||
if (!courseAdded) {
|
||||
await addCourse(activeSchedule.name, course);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
await removeCourse(activeSchedule.name, course);
|
||||
}
|
||||
setCourseAdded(!courseAdded);
|
||||
@@ -137,7 +138,12 @@ const HeadingAndActions: React.FC<HeadingAndActionProps> = ({ course, onClose, a
|
||||
<Button variant='outline' color='ut-orange' icon={Description} onClick={handleOpenPastSyllabi}>
|
||||
Past Syllabi
|
||||
</Button>
|
||||
<Button variant='filled' color={!courseAdded ? 'ut-green' : 'ut-red'} icon={!courseAdded ? Add : Remove} onClick={handleAddOrRemoveCourse}>
|
||||
<Button
|
||||
variant='filled'
|
||||
color={!courseAdded ? 'ut-green' : 'ut-red'}
|
||||
icon={!courseAdded ? Add : Remove}
|
||||
onClick={handleAddOrRemoveCourse}
|
||||
>
|
||||
{!courseAdded ? 'Add Course' : 'Remove Course'}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user