From 2d940493a3cbd9d8fe2a7a37183c0878781b94d8 Mon Sep 17 00:00:00 2001 From: Sriram Hariharan Date: Fri, 3 Mar 2023 23:53:54 -0600 Subject: [PATCH] beginning course scraping from row, and created assets folder with departments.json --- src/assets/json/departments.json | 221 ++++++++++++++++++++ src/views/components/CourseCatalogMain.tsx | 10 +- src/views/components/injected/TableHead.tsx | 18 +- src/views/components/injected/TableRow.tsx | 30 ++- 4 files changed, 262 insertions(+), 17 deletions(-) create mode 100644 src/assets/json/departments.json diff --git a/src/assets/json/departments.json b/src/assets/json/departments.json new file mode 100644 index 00000000..49188ee2 --- /dev/null +++ b/src/assets/json/departments.json @@ -0,0 +1,221 @@ +[ + "ACC", + "ADV", + "ASE", + "AFR", + "AFS", + "ASL", + "AMS", + "AHC", + "ANT", + "ALD", + "ARA", + "ARE", + "ARI", + "ARC", + "AED", + "ARH", + "ART", + "AET", + "AAS", + "ANS", + "AST", + "BSN", + "BEN", + "BCH", + "BIO", + "BME", + "BDP", + "B A", + "BAX", + "BGS", + "CHE", + "CH", + "CHI", + "C E", + "CLA", + "C C", + "CGS", + "COM", + "CLD", + "CMS", + "CRP", + "C L", + "COE", + "CSE", + "C S", + "CON", + "CTI", + "CRW", + "CDI", + "EDC", + "CZ", + "DAN", + "DSC", + "D S", + "DES", + "DEV", + "D B", + "DRS", + "DCH", + "ECO", + "ELP", + "EDP", + "E E", + "ECE", + "EER", + "EMA", + "ENM", + "E M", + "E S", + "E", + "ESL", + "ENS", + "EVE", + "EVS", + "EUP", + "EUS", + "FIN", + "F A", + "FLU", + "FR", + "F H", + "G E", + "GRG", + "GEO", + "GER", + "GSD", + "GOV", + "GRS", + "GK", + "GUI", + "HAR", + "H S", + "HCT", + "HED", + "HEB", + "HIN", + "HIS", + "HDF", + "HDO", + "H E", + "HMN", + "ILA", + "I", + "ISP", + "INF", + "ITD", + "I B", + "IRG", + "ISL", + "ITL", + "ITC", + "JPN", + "J S", + "J", + "KIN", + "KOR", + "LAR", + "LTC", + "LAT", + "LAL", + "LAS", + "LAW", + "LEB", + "L A", + "LAH", + "LIN", + "MAL", + "MAN", + "MIS", + "MFG", + "MNS", + "MKT", + "MSE", + "M", + "M E", + "MDV", + "MAS", + "MEL", + "MES", + "M S", + "MOL", + "MUS", + "NSC", + "N S", + "NEU", + "NOR", + "N", + "NTR", + "OBO", + "OPR", + "O M", + "ORI", + "ORG", + "PER", + "PRS", + "PGE", + "PGS", + "PHM", + "PHL", + "PED", + "P S", + "PHY", + "PIA", + "POL", + "POR", + "PRC", + "PSY", + "P A", + "PBH", + "P R", + "RIM", + "RTF", + "R E", + "R S", + "RHE", + "R M", + "RUS", + "REE", + "SAN", + "SAX", + "STC", + "STM", + "S C", + "SEL", + "S S", + "S W", + "SOC", + "SPN", + "SPC", + "SED", + "SLH", + "STA", + "SDS", + "SUS", + "SWE", + "TAM", + "TXA", + "T D", + "TRO", + "TRU", + "TBA", + "TUR", + "T C", + "UKR", + "UGS", + "UDN", + "URB", + "URD", + "UTS", + "UTL", + "VIA", + "VIO", + "V C", + "VAS", + "VOI", + "WGS", + "WRT", + "YID", + "YOR" +] \ No newline at end of file diff --git a/src/views/components/CourseCatalogMain.tsx b/src/views/components/CourseCatalogMain.tsx index 09b61561..b0b740f0 100644 --- a/src/views/components/CourseCatalogMain.tsx +++ b/src/views/components/CourseCatalogMain.tsx @@ -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([]); - const [selectedCourse, setSelectedCourse] = React.useState(null); + const [selectedCourse, setSelectedCourse] = useState(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 (
Plus {rows.map(row => ( - + ))} {isScrolling &&
Scrolling...
}
diff --git a/src/views/components/injected/TableHead.tsx b/src/views/components/injected/TableHead.tsx index fe0d5611..dcd4796e 100644 --- a/src/views/components/injected/TableHead.tsx +++ b/src/views/components/injected/TableHead.tsx @@ -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(null); + const [container, setContainer] = useState(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({children}, portalContainer); + return ReactDOM.createPortal({children}, container); } diff --git a/src/views/components/injected/TableRow.tsx b/src/views/components/injected/TableRow.tsx index 223f2c97..73478a27 100644 --- a/src/views/components/injected/TableRow.tsx +++ b/src/views/components/injected/TableRow.tsx @@ -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(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(null); + const [course, setCourse] = useState(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(, portalContainer); + const handleOnClick = () => { + onClick(course); + }; + + return ReactDOM.createPortal(, container); +} + +function scrapeCourseFromRow(row): Course { + return null as any; }