From 26d371307a6637b0363c32d81d54ee5e792feae6 Mon Sep 17 00:00:00 2001 From: itsvick Date: Thu, 5 Dec 2024 17:35:34 +0530 Subject: [PATCH] Issue #PS-0000 fix: Updated course-hierarchy --- src/pages/course-hierarchy/[identifier].tsx | 95 ++++++++++++--------- 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/src/pages/course-hierarchy/[identifier].tsx b/src/pages/course-hierarchy/[identifier].tsx index 3e75207..3b23c15 100644 --- a/src/pages/course-hierarchy/[identifier].tsx +++ b/src/pages/course-hierarchy/[identifier].tsx @@ -16,56 +16,69 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import ResourceCard from '@/components/ResourceCard'; const RecursiveAccordion = ({ data }: { data: any[] }) => { - let router = useRouter(); + const router = useRouter(); const renderAccordion = (nodes: any[], level = 0) => { - return nodes.map((node, index) => ( - - {level === 0 ? ( - <> - {/* Render level 0 name as heading */} - - {node.name} - - {/* Render children as accordions */} - {node.children && renderAccordion(node.children, level + 1)} - - ) : node.contentType === 'Resource' ? ( - - - - - + const resourceNodes = nodes.filter(node => node.contentType === 'Resource'); + const nonResourceNodes = nodes.filter(node => node.contentType !== 'Resource'); - ) : ( - - }> - - {node?.name} - - - - {/* Recursively render children */} - {node?.children && renderAccordion(node?.children, level + 1)} - - + return ( + <> + {resourceNodes.length > 0 && ( + + {resourceNodes.map((node, index) => ( + + + + ))} + )} - - )); + + {nonResourceNodes.map((node, index) => ( + + {level === 0 ? ( + <> + + {node.name} + + {node.children && renderAccordion(node.children, level + 1)} + + ) : ( + + }> + + {node?.name} + + + + {node?.children && renderAccordion(node?.children, level + 1)} + + + )} + + ))} + + ); }; return {renderAccordion(data)}; }; + export default function CourseHierarchy() { const router = useRouter(); const [doId, setDoId] = useState(null);