Skip to content

Commit

Permalink
feat: relinking addCourse function to the button fingers crossed
Browse files Browse the repository at this point in the history
  • Loading branch information
DereC4 committed Nov 14, 2024
1 parent 44bcf07 commit 1c41cdb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/shared/messages/UserScheduleMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface UserScheduleMessages {
* @param data the schedule id and course to add
*/
addCourse: (data: { scheduleId: string; course: Course }) => void;
/**
* Adds a course by URL
* @param data
* @returns Response of the requested course URL
*/
addCourseByURL: (data: { url: string; method: string; body?: string; response: 'json' | 'text' }) => string;
/**
* Remove a course from a schedule
* @param data the schedule id and course to remove
Expand Down Expand Up @@ -44,11 +50,4 @@ export interface UserScheduleMessages {
* @returns undefined if successful, otherwise an error message
*/
renameSchedule: (data: { scheduleId: string; newName: string }) => string | undefined;

/**
* Adds a course by URL
* @param data
* @returns
*/
addCourseByURL: (data: { url: string; method: string; body?: string; response: 'json' | 'text' }) => string;
}
9 changes: 3 additions & 6 deletions src/views/components/injected/AddAllButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { background } from '@shared/messages';
import type { Course } from '@shared/types/Course';
// import { addCourseByUrl } from '@shared/util/courseUtils';
import { addCourseByURL } from '@pages/background/lib/addCourseByURL';
import { Button } from '@views/components/common/Button';
import ExtensionRoot from '@views/components/common/ExtensionRoot/ExtensionRoot';
import useSchedules from '@views/hooks/useSchedules';
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';

const { openNewTab, addCourse, removeCourse, openCESPage } = background;

/**
* @todo Inject the button into page https://my.utexas.edu/student/student/index
* @todo figure out how to get ActiveSchedule in here
Expand All @@ -20,6 +16,7 @@ const { openNewTab, addCourse, removeCourse, openCESPage } = background;
*/
export default function InjectedButton(): JSX.Element | null {
const [container, setContainer] = useState<HTMLDivElement | null>(null);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [activeSchedule, _] = useSchedules();

// const removeDuplicates = (courseIds: string[], courses: string[]) => {
Expand Down Expand Up @@ -54,7 +51,7 @@ export default function InjectedButton(): JSX.Element | null {
const uniqueAnchorTags = new Set(anchorTags.map(a => a.href));

uniqueAnchorTags.forEach(a => {
// addCourseByUrl(a, activeSchedule);
addCourseByURL(activeSchedule, a);
});

// const courses = Array.from(anchorTags).map(x => x.innerText.trim());
Expand Down

0 comments on commit 1c41cdb

Please sign in to comment.