Skip to content

Commit ca829ac

Browse files
authored
fix: links/client side navigation (#433)
1 parent a979ffb commit ca829ac

File tree

7 files changed

+25
-24
lines changed

7 files changed

+25
-24
lines changed

site/src/component/PrereqTree/PrereqTree.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Grid, Popup } from 'semantic-ui-react';
44
import type { Prerequisite, PrerequisiteTree } from 'peterportal-api-next-types';
55

66
import { CourseGQLData, CourseLookup } from '../../types/types';
7+
import { Link } from 'react-router-dom';
78

89
interface NodeProps {
910
node: string;
@@ -26,14 +27,14 @@ const Node: FC<NodeProps> = (props) => {
2627
<Popup
2728
trigger={
2829
!props.label.startsWith('AP ') ? (
29-
<a
30-
href={'/course/' + props.label.split('(')[0].replace(/\s+/g, '')}
30+
<Link
31+
to={'/course/' + props.label.split('(')[0].replace(/\s+/g, '')}
3132
role="button"
3233
style={{ padding: '0.5rem' }}
3334
className={`node ui button`}
3435
>
3536
{props.label}
36-
</a>
37+
</Link>
3738
) : (
3839
<button style={{ padding: '0.5rem' }} className={`node ui button`}>{`${props.label}`}</button>
3940
)

site/src/component/Review/SubReview.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ const SubReview: FC<SubReviewProps> = ({ review, course, professor, colors, colo
9595
<h3 className="subreview-identifier">
9696
{professor && (
9797
<Link to={{ pathname: `/course/${review.courseID}` }}>
98-
{professor.courses[review.courseID].department + ' ' + professor.courses[review.courseID].courseNumber}
98+
{professor.courses[review.courseID]?.department + ' ' + professor.courses[review.courseID]?.courseNumber}
9999
</Link>
100100
)}
101101
{course && (
102102
<Link to={{ pathname: `/professor/${review.professorID}` }}>
103-
{Object.values(course.instructors)?.find(({ ucinetid }) => ucinetid === review.professorID)?.name}
103+
{course.instructors[review.professorID]?.name}
104104
</Link>
105105
)}
106106
{!course && !professor && (

site/src/component/SearchPopup/SearchPopup.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import searching from '../../asset/searching.webp';
88
import { useAppSelector } from '../../store/hooks';
99
import { selectCourse, selectProfessor } from '../../store/slices/popupSlice';
1010
import { CourseGQLData, ProfessorGQLData, SearchType, ScoreData } from '../../types/types';
11+
import { Link } from 'react-router-dom';
1112

1213
interface InfoData {
1314
title: string;
@@ -75,11 +76,11 @@ const SearchPopupContent: FC<SearchPopupProps> = (props) => {
7576
<div className="search-popup-header">
7677
<h2 className="search-popup-id">
7778
{props.name}
78-
<a href={`/${props.searchType}/${props.id}`}>
79+
<Link to={`/${props.searchType}/${props.id}`}>
7980
<Button type="button" className="search-popup-more btn btn-outline-primary">
8081
More Information
8182
</Button>
82-
</a>
83+
</Link>
8384
</h2>
8485
<h5 className="search-popup-title">{props.title}</h5>
8586
</div>
@@ -110,7 +111,9 @@ const SearchPopupContent: FC<SearchPopupProps> = (props) => {
110111
<span className="search-popup-carousel-score">{score.score == -1 ? '?' : score.score}</span>
111112
<span className="search-popup-carousel-max-score">/ 5.0</span>
112113
</div>
113-
<a href={`/${props.searchType == 'course' ? 'professor' : 'course'}/${score.key}`}>{score.name}</a>
114+
<Link to={`/${props.searchType == 'course' ? 'professor' : 'course'}/${score.key}`}>
115+
{score.name}
116+
</Link>
114117
</div>
115118
))}
116119
</Carousel>

site/src/pages/CoursePage/index.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@ const CoursePage: FC = () => {
2424
const [error, setError] = useState('');
2525

2626
useEffect(() => {
27-
// make a gql query if directly landed on this page
28-
if (id !== undefined && (courseGQLData == null || courseGQLData.id != id)) {
27+
if (id !== undefined) {
2928
searchAPIResult('course', id).then((course) => {
30-
console.log('COURSE', course);
3129
if (course) {
3230
dispatch(setCourse(course as CourseGQLData));
31+
setError('');
3332
} else {
3433
setError(`Course ${id} does not exist!`);
3534
}
3635
});
3736
}
38-
}, []);
37+
}, [dispatch, id]);
3938

4039
// if course does not exists
4140
if (error) {
@@ -65,15 +64,15 @@ const CoursePage: FC = () => {
6564
<h2>🌲 Prerequisite Tree</h2>
6665
</div>
6766
<Divider />
68-
<PrereqTree {...courseGQLData} />
67+
<PrereqTree key={courseGQLData.id} {...courseGQLData} />
6968
</div>
7069

7170
<div className="course-page-section">
7271
<div>
7372
<h2>🗓️ Schedule of Classes</h2>
7473
</div>
7574
<Divider />
76-
<Schedule courseID={courseGQLData.department + ' ' + courseGQLData.courseNumber} />
75+
<Schedule key={courseGQLData.id} courseID={courseGQLData.department + ' ' + courseGQLData.courseNumber} />
7776
</div>
7877

7978
<div className="course-page-section">
@@ -89,7 +88,7 @@ const CoursePage: FC = () => {
8988
<h2>💬 Reviews</h2>
9089
</div>
9190
<Divider />
92-
<Review course={courseGQLData} />
91+
<Review key={courseGQLData.id} course={courseGQLData} />
9392
</div>
9493
</div>
9594
</div>

site/src/pages/ProfessorPage/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ const ProfessorPage: FC = () => {
2222
const [error, setError] = useState('');
2323

2424
useEffect(() => {
25-
// make a gql query if directly landed on this page
26-
if (id !== undefined && (professorGQLData == null || professorGQLData.ucinetid != id)) {
25+
if (id !== undefined) {
2726
searchAPIResult('professor', id).then((professor) => {
2827
if (professor) {
2928
dispatch(setProfessor(professor as ProfessorGQLData));
29+
setError('');
3030
} else {
3131
setError(`Professor ${id} does not exist!`);
3232
}
3333
});
3434
}
35-
}, []);
35+
}, [dispatch, id]);
3636

3737
// if professor does not exists
3838
if (error) {

site/src/pages/RoadmapPage/Course.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,13 @@ const Course: FC<CourseProps> = (props) => {
6666
</Popover>
6767
);
6868

69-
const courseRoute = () => {
70-
return '/course/' + props.department.replace(/\s+/g, '') + props.courseNumber.replace(/\s+/g, '');
71-
};
69+
const courseRoute = '/course/' + props.department.replace(/\s+/g, '') + props.courseNumber.replace(/\s+/g, '');
7270

7371
return (
7472
<div className={`course ${requiredCourses ? 'invalid' : ''}`}>
7573
<div className="course-card-top">
7674
<div className="course-and-info">
77-
<a className="name" href={courseRoute()} target="_blank" rel="noopener noreferrer">
75+
<a className="name" href={courseRoute} target="_blank" rel="noopener noreferrer">
7876
{department + ' ' + courseNumber}
7977
</a>
8078
<OverlayTrigger trigger={['hover', 'focus']} placement="auto" overlay={CoursePopover} delay={100}>

site/src/pages/SearchPage/ProfessorHitItem.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC } from 'react';
22
import './HitItem.scss';
3-
import { useNavigate } from 'react-router-dom';
3+
import { Link, useNavigate } from 'react-router-dom';
44
import { useAppDispatch, useAppSelector } from '../../store/hooks';
55
import { setProfessor } from '../../store/slices/popupSlice';
66

@@ -65,7 +65,7 @@ const ProfessorHitItem: FC<ProfessorHitItemProps> = (props: ProfessorHitItemProp
6565
return (
6666
<span key={`professor-hit-item-course-${index}`}>
6767
{index ? ', ' : ''}
68-
<a href={'/course/' + item.replace(/\s+/g, '')}>{item}</a>
68+
<Link to={'/course/' + item.replace(/\s+/g, '')}>{item}</Link>
6969
</span>
7070
);
7171
})}

0 commit comments

Comments
 (0)