MCPcopy Create free account
hub / github.com/code100x/cms / BreadCrumbComponent

Function BreadCrumbComponent

src/components/BreadCrumbComponent.tsx:16–126  ·  view source on GitHub ↗
({
  rest,
  course,
  fullCourseContent,
  courseContent,
  contentType,
}: {
  fullCourseContent: FullCourseContent[];
  rest: string[];
  course: any;
  contentType: any;
  courseContent: any;
})

Source from the content-addressed store, hash-verified

14import { Fragment, useMemo } from 'react';
15
16export default function BreadCrumbComponent({
17 rest,
18 course,
19 fullCourseContent,
20 courseContent,
21 contentType,
22}: {
23 fullCourseContent: FullCourseContent[];
24 rest: string[];
25 course: any;
26 contentType: any;
27 courseContent: any;
28}) {
29 const findChildContent = (contents: any, childId: any) => {
30 for (const content of contents) {
31 if (content.id === childId) {
32 return content;
33 } else if (content.children && content.children.length > 0) {
34 const childContent: any = findChildContent(content.children, childId);
35 if (childContent) {
36 return childContent;
37 }
38 }
39 }
40 return undefined;
41 };
42
43 const generateBreadcrumbs = useMemo(() => {
44 const breadcrumbs = [];
45
46 for (let i = 0; i < rest.length; i++) {
47 const childId = parseInt(rest[i], 10);
48
49 const childContent = findChildContent(fullCourseContent, childId);
50
51 if (childContent) {
52 breadcrumbs.push(childContent);
53 }
54 }
55 return breadcrumbs;
56 }, [rest, fullCourseContent, courseContent, contentType]);
57
58 return (
59 <>
60 <Breadcrumb>
61 <BreadcrumbList>
62 <BreadcrumbItem>
63 <BreadcrumbLink className="text-sm text-blue-600" asChild>
64 <Link href={'/'}>
65 <Home className="size-4" />
66 </Link>
67 </BreadcrumbLink>
68 </BreadcrumbItem>
69 <BreadcrumbSeparator />
70 <BreadcrumbItem>
71 {generateBreadcrumbs.length > 0 ? (
72 <BreadcrumbLink className="text-blue-600" asChild>
73 <Link

Callers

nothing calls this directly

Calls 1

findChildContentFunction · 0.85

Tested by

no test coverage detected