-
Notifications
You must be signed in to change notification settings - Fork 31
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 pre-/post-requisite tree under each class #188
Changes from 61 commits
1fe1bab
77252cd
99d6421
a85c07f
90cdc26
62757ec
cad2d2d
80c0f9f
25d847a
8291273
d282973
4819f35
5e36e55
1c68659
ebbb419
101a1f5
e33d68b
8c158e0
b967bcc
d79cff6
7dd2456
7c7c496
47fb612
14ede1c
380ff71
554b2a9
3688001
b4bd11d
bf146fd
16babe7
e20f5e0
8395f96
79b60f6
09ecb36
0aaad61
79252e9
0b6b2b7
b77dcde
91a9c75
913d0bd
0b1a467
6fc686a
f6d22dd
a0f01d5
426cd74
e352eb1
760978d
6884b59
6fbcbe7
a75d38d
21021d3
5d45e93
b2968ad
8b6ae54
175b792
a315151
85cf02e
f4a66ad
936a778
3ad0863
d092d75
ed85d6e
51c89f2
775832b
2c6d7cb
9ff32b3
e95d672
0b6c7e0
f452805
6740e36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from "react"; | ||
import Link from "next/link"; | ||
import { useFetchCourseInfo } from "~/app/api/course"; | ||
|
||
interface TreeNode { | ||
courseID: string; | ||
postreqs?: TreeNode[]; | ||
} | ||
|
||
interface Props { | ||
courseID: string; | ||
} | ||
|
||
export const PostReqCourses = ({ courseID }: Props) => { | ||
const { isPending: isCourseInfoPending, data: info } = useFetchCourseInfo(courseID); | ||
|
||
if (isCourseInfoPending || !info) { | ||
return null; | ||
} | ||
|
||
// Recursive function to render only the child branches | ||
const renderTree = (nodes: TreeNode[]) => { | ||
return ( | ||
<div className="flex flex-col"> | ||
{nodes.map((node) => ( | ||
<div key={node.courseID} className="flex items-center"> | ||
{/* Half vertical line for the first prereq in the list */} | ||
{nodes && nodes.length > 1 && nodes.indexOf(node) === 0 && ( | ||
<div className="w-[1px] h-[20px] bg-[#d1d5db] mt-[20px]"></div> | ||
)} | ||
|
||
{/* Normal vertical Line connector */} | ||
{nodes && nodes.length > 1 && nodes.indexOf(node) !== 0 && nodes.indexOf(node) !== nodes.length - 1 && ( | ||
<div className="w-[1px] bg-[#d1d5db] self-stretch"></div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally it would be nicer to use w-1/w-0.5 instead of hard coding pixels |
||
)} | ||
|
||
{/* Half vertical line for the last prereq in the list */} | ||
{nodes && nodes.length > 1 && nodes.indexOf(node) === nodes.length - 1 && ( | ||
<div className="w-[1px] h-[20px] bg-[#d1d5db] mb-[20px]"></div> | ||
)} | ||
|
||
{/* Line connector */} | ||
<div className="w-[20px] h-[1px] bg-[#d1d5db]"></div> | ||
|
||
{/* Course ID button */} | ||
<button | ||
onClick={() => window.location.href = `/course/${node.courseID}`} | ||
className="font-normal text-center px-2 py-1 text-base bg-[#f9fafb] text-[#111827] border border-[#d1d5db] rounded shadow cursor-pointer no-underline min-w-[80px] inline mt-[2px] mb-[2px]" | ||
> | ||
{node.courseID} | ||
</button> | ||
|
||
{/* Render child nodes recursively */} | ||
{node.postreqs && renderTree(node.postreqs)} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
// Transform fetched data into a tree structure excluding the parent node | ||
const childNodes: TreeNode[] = info.postreqs?.map((postreq: string) => ({ | ||
courseID: postreq, | ||
})) || []; | ||
|
||
return ( | ||
<div> | ||
{childNodes.length > 0 ? ( | ||
renderTree(childNodes) | ||
) : ( | ||
<div className="italic text-[#000000] text-center text-base font-bold"> | ||
No further post-requisites | ||
</div> | ||
|
||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default PostReqCourses; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from "react"; | ||
import { useFetchCourseInfo } from "~/app/api/course"; | ||
|
||
interface TreeNode { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice use define TreeNode in a few files, would be good to put one standard definition in apps/types |
||
courseID: string; | ||
prereqs?: TreeNode[]; | ||
} | ||
|
||
interface Props { | ||
courseID: string; | ||
} | ||
|
||
export const PreReqCourses = ({ courseID }: Props) => { | ||
const { isPending: isCourseInfoPending, data: info } = useFetchCourseInfo(courseID); | ||
|
||
if (isCourseInfoPending || !info) { | ||
return null; | ||
} | ||
|
||
// Recursive function to render only the child branches | ||
const renderTree = (nodes: TreeNode[]) => { | ||
return ( | ||
<div className="flex flex-col"> | ||
{nodes.map((node) => ( | ||
<div key={node.courseID} className="flex items-center"> | ||
{/* Course ID button */} | ||
<button | ||
onClick={() => (window.location.href = `/course/${node.courseID}`)} | ||
className="font-normal text-center px-2 py-1 text-base bg-[#f9fafb] text-[#111827] border border-[#d1d5db] rounded shadow cursor-pointer no-underline min-w-[80px] inline mt-[2px] mb-[2px]" | ||
> | ||
{node.courseID} | ||
</button> | ||
|
||
{/* Line connector */} | ||
<div className="w-[20px] h-[1px] bg-[#d1d5db]"></div> | ||
|
||
{/* Half vertical line for the first prereq in the list */} | ||
{nodes && nodes.length > 1 && nodes.indexOf(node) === 0 && ( | ||
<div className="w-[1px] h-[20px] bg-[#d1d5db] mt-[20px]"></div> | ||
)} | ||
|
||
{/* Normal vertical Line connector */} | ||
{nodes && nodes.length > 1 && nodes.indexOf(node) !== 0 && nodes.indexOf(node) !== nodes.length - 1 && ( | ||
<div className="w-[1px] bg-[#d1d5db] self-stretch"></div> | ||
)} | ||
|
||
{/* Half vertical line for the last prereq in the list */} | ||
{nodes && nodes.length > 1 && nodes.indexOf(node) === nodes.length - 1 && ( | ||
<div className="w-[1px] h-[20px] bg-[#d1d5db] mb-[20px]"></div> | ||
)} | ||
|
||
{/* Render child nodes recursively */} | ||
{node.prereqs && renderTree(node.prereqs)} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
// Transform fetched data into a tree structure excluding the parent node | ||
const childNodes: TreeNode[] = info.prereqs?.map((prereq: string) => ({ | ||
courseID: prereq, | ||
})) || []; | ||
|
||
return ( | ||
<div> | ||
{childNodes.length > 0 ? ( | ||
renderTree(childNodes) | ||
) : ( | ||
<div className="italic text-[#000000] text-center text-base font-bold"> | ||
No further prerequisites | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default PreReqCourses; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from "react"; | ||
import { Card } from "./Card"; | ||
import ReqTreeDetail from "./ReqTreeDetail"; | ||
|
||
interface TreeNode { | ||
courseID: string; | ||
prereqs?: TreeNode[]; | ||
postreqs?: TreeNode[]; | ||
coreqs?: Array<{ courseID: string }>; // Ensure coreqs are included | ||
} | ||
|
||
interface ReqTreeCardProps { | ||
courseID: string; | ||
prereqs: string[]; | ||
postreqs: string[]; | ||
coreqs: string[]; // Ensure coreqs are included | ||
} | ||
|
||
const ReqTreeCard: React.FC<ReqTreeCardProps> = ({ courseID, prereqs, postreqs, coreqs }) => { | ||
const hasNoRequisites = prereqs.length === 0 && postreqs.length === 0 && coreqs.length === 0; | ||
|
||
const buildTree = (id: string, prereqList: string[], postreqList: string[], coreqList: string[]): TreeNode => { | ||
return { | ||
courseID: id, | ||
prereqs: prereqList.map((prereq) => ({ courseID: prereq })), | ||
postreqs: postreqList.map((postreq) => ({ courseID: postreq })), | ||
coreqs: coreqList.map((coreq) => ({ courseID: coreq })), // Ensure coreqs are included | ||
}; | ||
}; | ||
|
||
const tree = buildTree(courseID, prereqs, postreqs, coreqs); | ||
|
||
return ( | ||
<Card> | ||
<Card.Header>Requisite Tree</Card.Header> | ||
{hasNoRequisites ? ( | ||
<div className="italic text-[#6b7280] p-[20px] text-center"> | ||
There are no prerequisites, corequisites, or postrequisites for this course. | ||
</div> | ||
) : ( | ||
<ReqTreeDetail root={tree} /> | ||
)} | ||
|
||
</Card> | ||
); | ||
}; | ||
|
||
export default ReqTreeCard; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this endpoint being used? I don’t see it being used so if it’s not it would be best to remove the dead code