CourseScraper completely done
'
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Course } from 'src/shared/types/Course';
|
||||
import { Course, CourseRow } from 'src/shared/types/Course';
|
||||
import { SiteSupport } from 'src/views/lib/getSiteSupport';
|
||||
import { Button } from '../common/Button/Button';
|
||||
|
||||
interface Props {
|
||||
support: SiteSupport;
|
||||
course: Course;
|
||||
element: HTMLTableRowElement;
|
||||
onClick: (course: Course) => void;
|
||||
onClick: (...args: any[]) => any;
|
||||
}
|
||||
|
||||
/**
|
||||
* This component is injected into each row of the course catalog table.
|
||||
* @returns a react portal to the new td in the column or null if the column has not been created yet.
|
||||
*/
|
||||
export default function TableRow({ support, element, onClick }: Props): JSX.Element | null {
|
||||
export default function TableRow({ support, course, element, onClick }: Props): JSX.Element | null {
|
||||
const [container, setContainer] = useState<HTMLTableCellElement | null>(null);
|
||||
const [course, setCourse] = useState<Course | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const portalContainer = document.createElement('td');
|
||||
@@ -25,17 +25,9 @@ export default function TableRow({ support, element, onClick }: Props): JSX.Elem
|
||||
setContainer(portalContainer);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setCourse(course);
|
||||
}, [element]);
|
||||
|
||||
if (!container || !course) {
|
||||
if (!container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleOnClick = () => {
|
||||
onClick(course);
|
||||
};
|
||||
|
||||
return ReactDOM.createPortal(<Button onClick={handleOnClick}>Plus</Button>, container);
|
||||
return ReactDOM.createPortal(<Button onClick={onClick}>Plus</Button>, container);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user