From ccd08bc0f03cb59b351c19d78ac0f937a5270368 Mon Sep 17 00:00:00 2001 From: Wolfboy248 Date: Mon, 25 Aug 2025 11:13:20 +0200 Subject: Moved breadcrum navigation into its own component --- .../src/components/BreadcrumbNav/BreadcrumbNav.tsx | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 frontend/src/components/BreadcrumbNav/BreadcrumbNav.tsx (limited to 'frontend/src/components/BreadcrumbNav/BreadcrumbNav.tsx') diff --git a/frontend/src/components/BreadcrumbNav/BreadcrumbNav.tsx b/frontend/src/components/BreadcrumbNav/BreadcrumbNav.tsx new file mode 100644 index 0000000..7c4af15 --- /dev/null +++ b/frontend/src/components/BreadcrumbNav/BreadcrumbNav.tsx @@ -0,0 +1,72 @@ +import React from "react"; +import { Link, useLocation } from "react-router-dom"; + +import styles from "./BreadcrumbNav.module.css"; + +export interface Breadcrumb { + to: string; + label: string; +}; + +interface BreadcrumbNavProps { + chapter?: Breadcrumb; +}; + +const BreadcrumbNav: React.FC = ({ chapter }) => { + const [breadcrumbs, setBreadcrumbs] = React.useState([]); + + const path = useLocation(); + + React.useEffect(() => { + let _paths = path.pathname.split("/").filter(Boolean); + console.log(_paths); + let _breadcrumbs: Breadcrumb[] = []; + + if (_paths.length >= 2) { + _breadcrumbs.push({ + to: "/games", + label: "Games List" + }) + + // To test 3 crumbs + // _breadcrumbs.push({ + // to: "/games", + // label: "Test" + // }) + + if (_paths[0] == "maps") { + if (chapter) { + _breadcrumbs.push({ + to: chapter.to, + label: chapter.label + }); + } + } + } + + setBreadcrumbs(_breadcrumbs); + }, [path]) + + return ( + + ) +} + +export default BreadcrumbNav; -- cgit v1.2.3