Skip to content

Commit

Permalink
Make it so you can't click on the operators
Browse files Browse the repository at this point in the history
  • Loading branch information
39bytes committed Aug 5, 2023
1 parent 475ff5d commit a1f9c80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 12 additions & 7 deletions client/src/components/CourseGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import VisGraph, { GraphData, Node, Edge } from 'react-vis-graph-wrapper';
import { v4 as uuidv4 } from 'uuid';

import { useDarkMode } from '../hooks/useDarkMode';
import { courseIdToUrlParam } from '../lib/utils';
import { courseIdToUrlParam, isValidCourseCode } from '../lib/utils';
import { Course } from '../model/Course';
import { ReqNode } from '../model/Requirements';

Expand Down Expand Up @@ -76,8 +76,8 @@ export const CourseGraph = ({ course }: CourseGraphProps) => {

const leading = course.leadingTo.map((leading) => {
return {
id: leading,
label: leading,
id: addSpace(leading),
label: addSpace(leading),
};
});

Expand Down Expand Up @@ -108,11 +108,16 @@ export const CourseGraph = ({ course }: CourseGraphProps) => {
const navigateToCourse = (nodes: string[]) => {
if (nodes.length === 0) return;
const node = graphNodes.find((node) => node.id === nodes[0]);
if (node && node.id) {
navigate(
`/course/${courseIdToUrlParam(node.id.toString().replace(' ', ''))}`
);
if (!node || !node.id) {
return;
}

if (!isValidCourseCode(node.id as string)) {
return;
}
navigate(
`/course/${courseIdToUrlParam(node.id.toString().replace(' ', ''))}`
);
};

return (
Expand Down
4 changes: 4 additions & 0 deletions client/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ export const capitalize = (s: string): string => {
export const punctuate = (s: string): string => {
return s.charAt(s.length - 1) === '.' ? s : s + '.';
};

export const isValidCourseCode = (s: string) => {
return /^(([A-Z0-9]){4} [0-9]{3}(D1|D2|N1|N2|J1|J2|J3)?)$/.test(s);
};

0 comments on commit a1f9c80

Please sign in to comment.