feat: add 'new search' link to the course catalog page (#456)
Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
37bd7e79d9
commit
ca5e4c13d3
@@ -2,6 +2,7 @@ import type { Course, ScrapedRow } from '@shared/types/Course';
|
||||
import ExtensionRoot from '@views/components/common/ExtensionRoot/ExtensionRoot';
|
||||
import AutoLoad from '@views/components/injected/AutoLoad/AutoLoad';
|
||||
import CourseCatalogInjectedPopup from '@views/components/injected/CourseCatalogInjectedPopup/CourseCatalogInjectedPopup';
|
||||
import NewSearchLink from '@views/components/injected/NewSearchLink';
|
||||
import RecruitmentBanner from '@views/components/injected/RecruitmentBanner/RecruitmentBanner';
|
||||
import TableHead from '@views/components/injected/TableHead';
|
||||
import TableRow from '@views/components/injected/TableRow/TableRow';
|
||||
@@ -61,6 +62,7 @@ export default function CourseCatalogMain({ support }: Props): JSX.Element | nul
|
||||
|
||||
return (
|
||||
<ExtensionRoot>
|
||||
<NewSearchLink />
|
||||
<RecruitmentBanner />
|
||||
<TableHead>Plus</TableHead>
|
||||
{rows.map(
|
||||
|
||||
49
src/views/components/injected/NewSearchLink.tsx
Normal file
49
src/views/components/injected/NewSearchLink.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
/**
|
||||
* This creates a 'Begin a new search' link above the course catalog table.
|
||||
*
|
||||
* @returns a react portal to the new link container or null if the container is not found.
|
||||
*/
|
||||
export default function NewSearchLink() {
|
||||
const [container, setContainer] = useState<HTMLElement | null>(null);
|
||||
const newContainerId = 'ut-registration-plus-new-search-link';
|
||||
|
||||
const searchLink = document.querySelector('#bottom_nav > p:nth-child(2)');
|
||||
const linkContent = {
|
||||
href: searchLink?.querySelector('a')?.href,
|
||||
title: searchLink?.querySelector('a')?.title,
|
||||
text: searchLink?.querySelector('a')?.textContent,
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (document.getElementById(newContainerId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const innerBody = document.querySelector('#inner_body');
|
||||
if (!innerBody) {
|
||||
return;
|
||||
}
|
||||
|
||||
const containerElement = document.createElement('div');
|
||||
containerElement.setAttribute('id', newContainerId);
|
||||
|
||||
innerBody.prepend(containerElement);
|
||||
setContainer(containerElement);
|
||||
}, []);
|
||||
|
||||
if (!container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createPortal(
|
||||
<p>
|
||||
<a href={linkContent.href} title={linkContent.title}>
|
||||
{linkContent.text}
|
||||
</a>
|
||||
</p>,
|
||||
container
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user