Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ctrl+click to the "View more info for this class" button, remove "back to search results" url. #238

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions components/ClassPage/PageContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRouter } from 'next/router';

Check warning on line 1 in components/ClassPage/PageContent.tsx

View workflow job for this annotation

GitHub Actions / lint

'useRouter' is defined but never used
import React, { ReactElement } from 'react';
import { GetClassPageInfoQuery } from '../../generated/graphql';
import ClassPageInfoBody from './ClassPageInfoBody';
Expand All @@ -23,8 +23,6 @@
classPageInfo,
isCoreq,
}: PageContentProps): ReactElement {
const router = useRouter();

// TODO: hacky front-end solution because for some reason allOccurrences includes
// termIds where there are no sections. This should probably be fixed on the backend.
if (classPageInfo && classPageInfo.class) {
Expand All @@ -40,9 +38,7 @@
<span className="coreqHeaderCourse">{` ${subject}${classId}`}</span>
</h2>
) : (
<div className="backToResults" onClick={() => router.back()}>
Back to Search Results
</div>
<></>
)}
{classPageInfo && classPageInfo.class && (
<div className="classPageInfoContent">
Expand Down
19 changes: 8 additions & 11 deletions components/ResultsPage/Results/CourseResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
// TODO (sam 2023-03-09): this is necessary because of `useShowAll`, which should likely not be coupled to courses.
const sortedSections = useMemo(
() => sortSections(course.sections, userInfo),
[course]
[course.sections, userInfo]
);
const { optionalDisplay } = useResultDetail(course);

Expand Down Expand Up @@ -124,17 +124,14 @@
)}
</div>
<div className="SearchResult__panel--right">
<div
onClick={() =>
router.push(
`/${campus}/${termId}/classPage/${course.subject}/${course.classId}`
)
}
>
<div className="view-more-info-container">
<IconNotepad className="notepad-icon" />
<div className="view-more-info-container">
<IconNotepad className="notepad-icon" />
<a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use instead of an tag, since it works with the React router and gives us this functionality still. I think with Next it also prerenders the pages that are being linked, so theres little to no waiting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what should we use instead? If you’re referring to a Link tag, unfortunately that doesn’t allow ctrl clicking.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops yea I was talking about Link. Apparently someone had a similar issue (vercel/next.js#7218), and the solution was to just put the href in the Link tag. If that doesn't work I'd be ok with the plain a tag.

className="view-more-info-link"
href={`/${campus}/${termId}/classPage/${course.subject}/${course.classId}`}
>
<span>View more info for this class</span>
</div>
</a>
</div>

<SignUpForNotifications
Expand Down Expand Up @@ -214,7 +211,7 @@
const [showCoreq, setShowCoreq] = useState(false);
const sortedSections = useMemo(
() => sortSections(course.sections, userInfo),
[course]

Check warning on line 214 in components/ResultsPage/Results/CourseResult.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has a missing dependency: 'userInfo'. Either include it or remove the dependency array
);
const { showAll, setShowAll, renderedSections, hideShowAll } = useShowAll(
sortedSections
Expand Down
46 changes: 25 additions & 21 deletions pages/[campus]/[termId]/classPage/[subject]/[classId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,6 @@ export default function Page(): ReactElement {
return `/${newCampus}/${t}/classPage/${subject}/${classId}${window.location.search}`;
};

const loadClassPageInfo = async (): Promise<void> => {
const classPage = await gqlClient.getClassPageInfo({ subject, classId });
if ((subject || classId) && !classPage.class) {
router.push('/404');
}
// assume coreq values will never be nested
const coreqs: CourseReq[] = classPage.class
? classPage.class.latestOccurrence.coreqs.values
: [];

const coreqInfoArray = await pMap(coreqs, async (coreqVal) => {
return await gqlClient.getClassPageInfo({
subject: coreqVal.subject,
classId: coreqVal.classId,
});
});
setClassPageInfo(classPage);
setCoreqInfo(coreqInfoArray);
};

useEffect(() => {
fetchUserInfo();
}, []);
Expand All @@ -72,8 +52,32 @@ export default function Page(): ReactElement {
};

useEffect(() => {
const loadClassPageInfo = async (): Promise<void> => {
if (subject && classId) {
const classPage = await gqlClient.getClassPageInfo({
subject,
classId,
});
if ((subject || classId) && !classPage.class) {
router.push('/404');
}
// assume coreq values will never be nested
const coreqs: CourseReq[] = classPage.class
? classPage.class.latestOccurrence.coreqs.values
: [];

const coreqInfoArray = await pMap(coreqs, async (coreqVal) => {
return await gqlClient.getClassPageInfo({
subject: coreqVal.subject,
classId: coreqVal.classId,
});
});
setClassPageInfo(classPage);
setCoreqInfo(coreqInfoArray);
}
};
loadClassPageInfo();
}, [subject, classId]);
}, [subject, classId, router]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is router required here as a dependency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we get graphql errors otherwise.


if (!termId || !campus) return null;
return (
Expand Down
7 changes: 7 additions & 0 deletions styles/results/_SearchResult.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
top: 24px;
left: -10px;
background: Colors.$Navy;

& > div {
border-color: transparent transparent Colors.$Navy transparent;
left: 12px;
Expand Down Expand Up @@ -135,6 +136,7 @@
margin-top: 10px;
margin-bottom: 10px;
cursor: pointer;

&:hover {
background: Colors.$Off_White;
}
Expand All @@ -148,6 +150,11 @@
line-height: 25px;
}
}

.view-more-info-link {
color: Colors.$Black;
}

.notepad-icon {
margin-right: 8px;
}
Expand Down
Loading