wip scraping infra

This commit is contained in:
Sriram Hariharan
2023-03-04 11:51:56 -06:00
parent 2d940493a3
commit c9684beb5b
6 changed files with 231 additions and 32 deletions

View File

@@ -1,10 +1,12 @@
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import { Course } from 'src/shared/types/Course';
import { SiteSupport } from 'src/views/lib/getSiteSupport';
import { Button } from '../common/Button/Button';
interface Props {
row: HTMLTableRowElement;
support: SiteSupport;
element: HTMLTableRowElement;
onClick: (course: Course) => void;
}
@@ -12,21 +14,20 @@ interface Props {
* 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({ row, onClick }: Props): JSX.Element | null {
export default function TableRow({ support, 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');
const lastTableCell = row.querySelector('td:last-child');
const lastTableCell = element.querySelector('td:last-child');
lastTableCell!.after(portalContainer);
setContainer(portalContainer);
}, []);
useEffect(() => {
const course = scrapeCourseFromRow(row);
setCourse(course);
}, [row]);
}, [element]);
if (!container || !course) {
return null;
@@ -38,7 +39,3 @@ export default function TableRow({ row, onClick }: Props): JSX.Element | null {
return ReactDOM.createPortal(<Button onClick={handleOnClick}>Plus</Button>, container);
}
function scrapeCourseFromRow(row): Course {
return null as any;
}