Skip to content
Open
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
12 changes: 11 additions & 1 deletion src/components/CourseNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ export default function CourseNode({ data }: NodeProps<CourseNodeType>) {
const { selectedCourse, highlightedSet } = useExplorerStore();
const dimmed = selectedCourse !== null && !highlightedSet.has(data.code);

const year = data.code.charAt(5);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR looks good overall! One small robustness suggestion: right now this assumes that the "year" of the course will always be at index 5, which is true for subjects with 4 letter subject codes (e.g. COMP 1405).

However, if we expand to more subjects related to COMP, there are some 3 letter subject codes (e.g. BIT, IMD, NET etc.).

To always get the first digit in the course code, regardless of how long the subject code is, using regex would be better here. Something like:
data.code.match(/\d/)?.[0];

(Not 100% sure that's the right regex so I'd check it with some examples to confirm)


const borderColour =
year === "1" ? "border-green-500" :
year === "2" ? "border-blue-500" :
year === "3" ? "border-yellow-500" :
year === "4" ? "border-red-500" :
"border-gray-300";


return (
<div
className="flex flex-col justify-center rounded border border-gray-300 bg-white px-3 py-2 shadow-sm transition-opacity duration-150"
className={`flex flex-col justify-center rounded border ${borderColour} bg-white px-3 py-2 shadow-sm transition-opacity duration-150`}
style={{ width: 180, height: 60, opacity: dimmed ? 0.25 : 1 }}
>
<Handle type="target" position={Position.Top} />
Expand Down
Loading