Skip to content

Commit

Permalink
feat: calendar matchings (#173)
Browse files Browse the repository at this point in the history
* feat: calendar matchings

* fix: build

* refactor: resolve pr comments

* fix: destrucure editorRef

---------

Co-authored-by: doprz <[email protected]>
  • Loading branch information
Razboy20 and doprz authored Mar 17, 2024
1 parent df18491 commit 791a42b
Show file tree
Hide file tree
Showing 23 changed files with 243 additions and 410 deletions.
2 changes: 1 addition & 1 deletion src/pages/calendar/CalendarMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';
*/
export default function CalendarMain() {
return (
<ExtensionRoot>
<ExtensionRoot className='h-full w-full'>
<Calendar />
</ExtensionRoot>
);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/calendar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<title>Calendar</title>
</head>

<body>
<body style="min-height: 100vh; height: 0; margin: 0">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<div id="root" style="height: 100%"></div>

<script src="./index.tsx" type="module"></script>
</body>
Expand Down
4 changes: 4 additions & 0 deletions src/stories/components/calendar/CalendarGridCell.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const meta = {
layout: 'centered',
tags: ['autodocs'],
},
args: {
row: 0,
col: 0,
},
} satisfies Meta<typeof CalendarCell>;

export default meta;
Expand Down
6 changes: 0 additions & 6 deletions src/stories/components/calendar/CalendarSchedules.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { CalendarSchedules } from '@views/components/calendar/CalendarSchedules/CalendarSchedules';
import React from 'react';

const meta = {
title: 'Components/Calendar/CalendarSchedules',
Expand All @@ -9,11 +8,6 @@ const meta = {
layout: 'centered',
tags: ['autodocs'],
},
render: args => (
<div>
<CalendarSchedules {...args} />
</div>
),
} satisfies Meta<typeof CalendarSchedules>;

export default meta;
Expand Down
13 changes: 2 additions & 11 deletions src/views/components/PopupMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import RefreshIcon from '~icons/material-symbols/refresh';
import SettingsIcon from '~icons/material-symbols/settings';

import CourseStatus from './common/CourseStatus/CourseStatus';
import { LogoIcon } from './common/LogoIcon';
import { SmallLogo } from './common/LogoIcon';
import PopupCourseBlock from './common/PopupCourseBlock/PopupCourseBlock';
import ScheduleDropdown from './common/ScheduleDropdown/ScheduleDropdown';
import ScheduleListItem from './common/ScheduleListItem/ScheduleListItem';
Expand Down Expand Up @@ -44,16 +44,7 @@ export default function PopupMain(): JSX.Element {
<div className='h-screen max-h-full flex flex-col bg-white'>
<div className='p-5 py-3.5'>
<div className='flex items-center justify-between bg-white'>
<div className='flex items-center gap-2'>
<LogoIcon />
<div className='flex flex-col'>
<span className='text-lg text-ut-burntorange font-medium leading-[18px]'>
UT Registration
<br />
</span>
<span className='text-lg text-ut-orange font-medium leading-[18px]'>Plus</span>
</div>
</div>
<SmallLogo />
<div className='flex items-center gap-2.5'>
<button className='bg-ut-burntorange px-2 py-1.25 btn' onClick={handleCalendarOpenOnClick}>
<CalendarIcon className='size-6 text-white' />
Expand Down
8 changes: 0 additions & 8 deletions src/views/components/calendar/Calendar/Calendar.module.scss

This file was deleted.

59 changes: 9 additions & 50 deletions src/views/components/calendar/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useFlattenedCourseSchedule } from '@views/hooks/useFlattenedCourseSched
import { MessageListener } from 'chrome-extension-toolkit';
import React, { useEffect, useRef, useState } from 'react';

import styles from './Calendar.module.scss';
/**
* A reusable chip component that follows the design system of the extension.
* @returns
Expand All @@ -33,8 +32,6 @@ export default function Calendar(): JSX.Element {
});

const [showPopup, setShowPopup] = useState<boolean>(course !== null);
const [sidebarWidth, setSidebarWidth] = useState('20%');
const [scale, setScale] = useState(1);

useEffect(() => {
const listener = new MessageListener<CalendarTabMessages>({
Expand All @@ -52,59 +49,21 @@ export default function Calendar(): JSX.Element {
return () => listener.unlisten();
}, [activeSchedule.courses]);

useEffect(() => {
const adjustLayout = () => {
const windowHeight = window.innerHeight;
const windowWidth = window.innerWidth;

const desiredCalendarHeight = 760;
const minSidebarWidthPixels = 230;

const scale = Math.min(1, windowHeight / desiredCalendarHeight);

const sidebarWidthPixels = Math.max(
windowWidth * scale - windowWidth + minSidebarWidthPixels,
minSidebarWidthPixels
);
const newSidebarWidth = `${(sidebarWidthPixels / windowWidth) * 100}%`;

setScale(scale);
setSidebarWidth(newSidebarWidth);
};

adjustLayout();

window.addEventListener('resize', adjustLayout);
return () => window.removeEventListener('resize', adjustLayout);
}, []);

useEffect(() => {
if (course) setShowPopup(true);
}, [course]);

const calendarContainerStyle = {
transform: `scale(${scale})`,
transformOrigin: 'top left',
marginTop: '-20px',
};

return (
<div className='h-screen flex flex-col' style={{ width: 'calc(100% - 1rem)' }}>
<div className='pl-5'>
<CalendarHeader />
</div>
<div className={`flex flex-grow flex-row overflow-hidden pl-4 ${styles.scrollableSchedules}`}>
<div className='sidebar-style' style={{ width: sidebarWidth, padding: '10px 15px 5px 5px' }}>
<div className={`mb-4 ${styles.scrollableLimit}`}>
<CalendarSchedules />
</div>
<Divider orientation='horizontal' size='100%' />
<div className='mt-4'>
<ImportantLinks />
</div>
<div className='h-full w-full flex flex-col'>
<CalendarHeader />
<div className='h-full flex flex-grow overflow-hidden pl-7.5'>
<div className='overflow-auto py-5'>
<CalendarSchedules />
<Divider orientation='horizontal' size='100%' className='my-5' />
<ImportantLinks />
</div>
<div className='flex flex-grow flex-col' style={calendarContainerStyle} ref={calendarRef}>
<div className='flex-grow overflow-auto'>
<div className='flex flex-grow flex-col' ref={calendarRef}>
<div className='flex-grow overflow-auto px-4 pt-6.5'>
<CalendarGrid courseCells={courseCells} setCourse={setCourse} />
</div>
<CalendarBottomBar calendarRef={calendarRef} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export default function CalendarCourseCell({

return (
<div
className={clsx('h-full w-full flex justify-center rounded p-2 cursor-pointer', fontColor, className)}
className={clsx(
'h-full min-w-full w-0 flex justify-center rounded p-2 cursor-pointer',
fontColor,
className
)}
style={{
backgroundColor: colors.primaryColor,
}}
Expand Down
139 changes: 0 additions & 139 deletions src/views/components/calendar/CalendarGrid/CalendarGrid.module.scss

This file was deleted.

Loading

0 comments on commit 791a42b

Please sign in to comment.