beginning course scraping from row, and created assets folder with departments.json
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useMemo } from 'react';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Course } from 'src/shared/types/Course';
|
||||
import useInfiniteScroll from '../hooks/useInfiniteScroll';
|
||||
@@ -16,7 +16,7 @@ interface Props {
|
||||
*/
|
||||
export default function CourseCatalogMain({ support }: Props) {
|
||||
const [rows, setRows] = React.useState<HTMLTableRowElement[]>([]);
|
||||
const [selectedCourse, setSelectedCourse] = React.useState<Course | null>(null);
|
||||
const [selectedCourse, setSelectedCourse] = useState<Course | null>(null);
|
||||
|
||||
const isScrolling = useInfiniteScroll(async () => {
|
||||
console.log('infinite scroll');
|
||||
@@ -32,11 +32,15 @@ export default function CourseCatalogMain({ support }: Props) {
|
||||
setRows(rows);
|
||||
}, []);
|
||||
|
||||
const handleRowButtonClick = (course: Course) => {
|
||||
setSelectedCourse(course);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<TableHead>Plus</TableHead>
|
||||
{rows.map(row => (
|
||||
<TableRow row={row} />
|
||||
<TableRow row={row} onClick={handleRowButtonClick} />
|
||||
))}
|
||||
{isScrolling && <div>Scrolling...</div>}
|
||||
</div>
|
||||
|
||||
@@ -3,23 +3,23 @@ import ReactDOM from 'react-dom';
|
||||
|
||||
/**
|
||||
* This adds a new column to the course catalog table header.
|
||||
* @returns
|
||||
* @returns a react portal to the new column or null if the column has not been created yet.
|
||||
*/
|
||||
export default function TableHead({ children }: PropsWithChildren) {
|
||||
const [portalContainer, setPortalContainer] = useState<HTMLTableCellElement | null>(null);
|
||||
const [container, setContainer] = useState<HTMLTableCellElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const portalContainer = document.createElement('th');
|
||||
portalContainer.setAttribute('scope', 'col');
|
||||
portalContainer.setAttribute('id', 'ut-registration-plus-table-head');
|
||||
const container = document.createElement('th');
|
||||
container.setAttribute('scope', 'col');
|
||||
container.setAttribute('id', 'ut-registration-plus-table-head');
|
||||
const lastTableHeadCell = document.querySelector('table thead th:last-child');
|
||||
lastTableHeadCell!.after(portalContainer);
|
||||
setPortalContainer(portalContainer);
|
||||
lastTableHeadCell!.after(container);
|
||||
setContainer(container);
|
||||
}, []);
|
||||
|
||||
if (!portalContainer) {
|
||||
if (!container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ReactDOM.createPortal(<span>{children}</span>, portalContainer);
|
||||
return ReactDOM.createPortal(<span>{children}</span>, container);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,44 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Course } from 'src/shared/types/Course';
|
||||
import { Button } from '../common/Button/Button';
|
||||
|
||||
interface Props {
|
||||
row: HTMLTableRowElement;
|
||||
onClick: (course: Course) => void;
|
||||
}
|
||||
|
||||
export default function TableRow({ row }: Props) {
|
||||
const [portalContainer, setPortalContainer] = useState<HTMLTableCellElement | null>(null);
|
||||
/**
|
||||
* 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 {
|
||||
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');
|
||||
lastTableCell!.after(portalContainer);
|
||||
setPortalContainer(portalContainer);
|
||||
setContainer(portalContainer);
|
||||
}, []);
|
||||
|
||||
if (!portalContainer) {
|
||||
useEffect(() => {
|
||||
const course = scrapeCourseFromRow(row);
|
||||
setCourse(course);
|
||||
}, [row]);
|
||||
|
||||
if (!container || !course) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ReactDOM.createPortal(<Button>Plus</Button>, portalContainer);
|
||||
const handleOnClick = () => {
|
||||
onClick(course);
|
||||
};
|
||||
|
||||
return ReactDOM.createPortal(<Button onClick={handleOnClick}>Plus</Button>, container);
|
||||
}
|
||||
|
||||
function scrapeCourseFromRow(row): Course {
|
||||
return null as any;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user