Skip to content

Commit

Permalink
refactor: simplify context
Browse files Browse the repository at this point in the history
  • Loading branch information
Razboy20 committed May 21, 2024
1 parent 249e835 commit ed0aad4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/views/components/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import CalendarHeader from '@views/components/calendar/CalenderHeader';
import ImportantLinks from '@views/components/calendar/ImportantLinks';
import Divider from '@views/components/common/Divider';
import CourseCatalogInjectedPopup from '@views/components/injected/CourseCatalogInjectedPopup/CourseCatalogInjectedPopup';
import type { CalendarData } from '@views/contexts/CalendarContext';
import { CalendarContext } from '@views/contexts/CalendarContext';
import { useFlattenedCourseSchedule } from '@views/hooks/useFlattenedCourseSchedule';
import { MessageListener } from 'chrome-extension-toolkit';
import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useState } from 'react';

import CalendarFooter from './CalendarFooter';
import TeamLinks from './TeamLinks';
Expand Down Expand Up @@ -65,10 +64,8 @@ export default function Calendar(): JSX.Element {
if (course) setShowPopup(true);
}, [course]);

const contextValue = useMemo<CalendarData>(() => ({ isInCalendar: true }), []);

return (
<CalendarContext.Provider value={contextValue}>
<CalendarContext.Provider value>
<div className='h-full w-full flex flex-col'>
<CalendarHeader
onSidebarToggle={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function HeadingAndActions({ course, activeSchedule, onClose }: H
const { courseName, department, number: courseNumber, uniqueId, instructors, flags, schedule } = course;
const courseAdded = activeSchedule.courses.some(ourCourse => ourCourse.uniqueId === uniqueId);
const formattedUniqueId = uniqueId.toString().padStart(5, '0');
const { isInCalendar } = useCalendar();
const isInCalendar = useCalendar();

const getInstructorFullName = (instructor: Instructor) => {
const { firstName = '', lastName = '' } = instructor;
Expand Down
11 changes: 1 addition & 10 deletions src/views/contexts/CalendarContext.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { createContext, useContext } from 'react';

/**
* Data for the calendar.
*/
export type CalendarData = {
isInCalendar: boolean;
};

/**
* Context for the calendar.
*/
export const CalendarContext = createContext<CalendarData>({
isInCalendar: false,
});
export const CalendarContext = createContext(false);

/**
* @returns The calendar context.
Expand Down

0 comments on commit ed0aad4

Please sign in to comment.