Skip to content

Commit

Permalink
Issue #PS-0000 fix: Updated course-hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Dec 5, 2024
1 parent 94ecbec commit 26d3713
Showing 1 changed file with 54 additions and 41 deletions.
95 changes: 54 additions & 41 deletions src/pages/course-hierarchy/[identifier].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<Box key={`${node.name}-${index}`} sx={{ marginBottom: '16px' }}>
{level === 0 ? (
<>
{/* Render level 0 name as heading */}
<Typography
variant="h1"
sx={{
marginBottom: '0.75rem',
fontWeight: 'bold',
borderBottom: '1px solid #ddd',
paddingBottom: '4px',
paddingLeft: '4px'
}}
>
{node.name}
</Typography>
{/* Render children as accordions */}
{node.children && renderAccordion(node.children, level + 1)}
</>
) : node.contentType === 'Resource' ? (
<Grid container>
<Grid item xs={6} md={4} lg={3} sx={{ mt: 2 }}>
<ResourceCard title={node?.name} resource={node?.resourceType} identifier={node?.identifier} mimeType={node?.mimeType} />
</Grid>
</Grid>
const resourceNodes = nodes.filter(node => node.contentType === 'Resource');
const nonResourceNodes = nodes.filter(node => node.contentType !== 'Resource');

) : (
<Accordion sx={{ marginLeft: `${(level - 1) * 2}px` }}>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="body1" fontWeight={600}>
{node?.name}
</Typography>
</AccordionSummary>
<AccordionDetails>
{/* Recursively render children */}
{node?.children && renderAccordion(node?.children, level + 1)}
</AccordionDetails>
</Accordion>
return (
<>
{resourceNodes.length > 0 && (
<Grid container spacing={2} sx={{ marginBottom: '16px' }}>
{resourceNodes.map((node, index) => (
<Grid item xs={6} md={4} lg={3} key={`${node.name}-${index}`}>
<ResourceCard
title={node?.name}
resource={node?.resourceType}
identifier={node?.identifier}
mimeType={node?.mimeType}
/>
</Grid>
))}
</Grid>
)}
</Box>
));

{nonResourceNodes.map((node, index) => (
<Box key={`${node.name}-${index}`} sx={{ marginBottom: '16px' }}>
{level === 0 ? (
<>
<Typography
variant="h1"
sx={{
marginBottom: '0.75rem',
fontWeight: 'bold',
borderBottom: '1px solid #ddd',
paddingBottom: '4px',
paddingLeft: '4px',
}}
>
{node.name}
</Typography>
{node.children && renderAccordion(node.children, level + 1)}
</>
) : (
<Accordion sx={{ marginLeft: `${(level - 1) * 2}px` }}>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="body1" fontWeight={600}>
{node?.name}
</Typography>
</AccordionSummary>
<AccordionDetails>
{node?.children && renderAccordion(node?.children, level + 1)}
</AccordionDetails>
</Accordion>
)}
</Box>
))}
</>
);
};

return <Box>{renderAccordion(data)}</Box>;
};


export default function CourseHierarchy() {
const router = useRouter();
const [doId, setDoId] = useState<string | null>(null);
Expand Down

0 comments on commit 26d3713

Please sign in to comment.