Skip to content

Commit 7d69784

Browse files
authored
Comments (#144)
* Comenting and lint clenup of prerequsitePresenter * fix
1 parent fff11a6 commit 7d69784

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

my-app/src/presenters/PrerequisitePresenter.jsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import '@xyflow/react/dist/style.css';
1616
import { model } from "../model";
1717

1818

19+
/*
20+
PrerequisitePresenter.jsx contains the logic for the graph that displays the prerequistes for each corse. To determine the positiosn of the cells it uses dagre.
21+
*/
22+
23+
24+
1925
export const PrerequisitePresenter = observer((props) => {
2026

2127
let uniqueCounter = 0;
@@ -50,6 +56,9 @@ export const PrerequisitePresenter = observer((props) => {
5056

5157
loadTree();
5258

59+
60+
61+
// Function for generating the node positions using dagre
5362
const getLayoutedElements = (nodes, edges, direction = 'LR') => {
5463
const isHorizontal = direction === 'LR';
5564
dagreGraph.setGraph({ rankdir: direction, nodesep: 30});
@@ -86,6 +95,9 @@ export const PrerequisitePresenter = observer((props) => {
8695
'LR' // force horizontal layout initially
8796
);
8897

98+
99+
100+
// get the poition of a node
89101
const getNodeAbsolutePosition = (nodeId) => {
90102
const nodeElement = document.querySelector(`[data-id="${nodeId}"]`);
91103
if (nodeElement) {
@@ -96,6 +108,8 @@ export const PrerequisitePresenter = observer((props) => {
96108
};
97109

98110

111+
112+
// handels the logic for when the user hovers a cell
99113
function handleMouseEnter(event, node) {
100114
if (node["data"]["label"] === "One of these" || node["data"]["label"] === "All of these" ||
101115
node["data"]["label"] === "No Prerequisites" || node["data"]["label"] === "Unable to load") {return;}
@@ -150,12 +164,15 @@ export const PrerequisitePresenter = observer((props) => {
150164

151165
}
152166

153-
167+
// handels the logic for when the user stops hovering a cell
154168
function handleMouseLeave(event, node) { // eslint-disable-line no-unused-vars
155169
hover_popup.style.display = "none";
156170
}
157171

172+
173+
//This function returnes the finished tree to the popup
158174
const Flow = () => {
175+
// eslint-disable-next-line no-unused-vars
159176
const [nodes, setNodes, onNodesChange] = useNodesState(layoutedNodes);
160177
const [edges, setEdges, onEdgesChange] = useEdgesState(layoutedEdges);
161178

@@ -198,14 +215,9 @@ export const PrerequisitePresenter = observer((props) => {
198215

199216
};
200217

201-
function setLabel(id, label) {
202-
setNodes((nodes) =>
203-
nodes.map((n) =>
204-
n.id === id ? { ...n, data: { ...n.data, label } } : n
205-
)
206-
);
207-
}
208218

219+
220+
//creates a node
209221
function createNode(id, name, node_type) {
210222
return {
211223
id: id,
@@ -226,15 +238,21 @@ export const PrerequisitePresenter = observer((props) => {
226238
}
227239
};
228240
}
241+
242+
//conects two nodes together with a line from node s to node t
229243
function createEdge(s, t) {
230244
return { id: s + " " + t, source: s, target: t, type: edgeType, animated: true };
231245
}
232246

233247

248+
249+
//coment internaly
250+
//reeds the model and converts it into the tree
234251
function prereq_convert(courses_taken, current_object, previous_key, previous_node_id) {
235-
let current_node = null; let last_course_num = null; let param_key = null;
252+
let current_node = null;
236253
try {
237254
current_object.length;
255+
// eslint-disable-next-line no-unused-vars
238256
} catch (err) {return;}
239257

240258
if (!Array.isArray(current_object)) { // Is object
@@ -437,6 +455,8 @@ export const PrerequisitePresenter = observer((props) => {
437455

438456
}
439457

458+
459+
//generates tree return eligebility
440460
function generateTree(courses_taken, prereqs) {
441461
prereq_convert(courses_taken, prereqs, null, props.selectedCourse.code);
442462
let key = Object.keys(prereqs);
@@ -450,6 +470,7 @@ export const PrerequisitePresenter = observer((props) => {
450470
}
451471

452472

473+
//eror handeling and data checking
453474
function loadTree() {
454475

455476
if (!props.selectedCourse?.prerequisites || props.selectedCourse.prerequisites.length == 0) {
@@ -468,6 +489,7 @@ export const PrerequisitePresenter = observer((props) => {
468489
courses_taken.push(local[i]?.id)
469490
}
470491
}
492+
//console.log(local);
471493
let eligible = generateTree(courses_taken, copy);
472494
if (eligible) {
473495
root["style"]["backgroundColor"] = "lightgreen";
@@ -487,7 +509,6 @@ export const PrerequisitePresenter = observer((props) => {
487509

488510
}
489511

490-
/* return <PrerequisiteTreeView initialNodes={initialNodes} initialEdges={initialEdges} /> */
491512
return <Flow />
492513
});
493514

my-app/src/views/PrerequisiteTreeView.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import React from "react";
22
import ReactFlow, { MiniMap, Controls, Background } from "reactflow";
33
import "reactflow/dist/style.css";
44

5+
6+
// redundent file functionality exist in PrerequisitePresenter.jsx
7+
58
function PrerequisiteTreeView(props) {
69
return (
710
<div className="w-full h-[500px] rounded-lg">

0 commit comments

Comments
 (0)