Skip to content

Commit

Permalink
♻️ - refactor: semi automatic breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Jun 18, 2024
1 parent 665b69a commit 0a988c9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
26 changes: 23 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import { Logo, NavigationContext, Outline } from "@maykin-ui/admin-ui";
import {
BreadcrumbItem,
Logo,
NavigationContext,
Outline,
formatMessage,
} from "@maykin-ui/admin-ui";
import React from "react";
import { Outlet, useNavigate } from "react-router-dom";
import { Outlet, useMatches, useNavigate } from "react-router-dom";

import "./App.css";

function App() {
const navigate = useNavigate();
const matches = useMatches();
const match = matches[matches.length - 1];
const handle = match?.handle as Record<string, unknown>;

const breadcrumbItems = (handle?.breadcrumbItems || []) as BreadcrumbItem[];
const lastBreadcrumbItem = breadcrumbItems[breadcrumbItems.length - 1];

if (lastBreadcrumbItem) {
lastBreadcrumbItem.label = formatMessage(
lastBreadcrumbItem.label,
match?.params as Record<string, string>,
);
}

return (
<div className="App">
<NavigationContext.Provider
value={{
breadcrumbItems,
primaryNavigationItems: [
<Logo
key="logo"
Expand All @@ -20,7 +40,7 @@ function App() {
{
children: <Outline.HomeIcon />,
title: "Home",
onClick: () => navigate("/"),
onClick: () => navigate("/destruction-lists/"),
},
{
children: <Outline.PlusCircleIcon />,
Expand Down
43 changes: 42 additions & 1 deletion frontend/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { BreadcrumbItem } from "@maykin-ui/admin-ui";
import "@maykin-ui/admin-ui/style";
import * as React from "react";
import * as ReactDOM from "react-dom/client";
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import {
Navigate,
RouterProvider,
createBrowserRouter,
} from "react-router-dom";

import App from "./App";
import "./index.css";
Expand Down Expand Up @@ -29,20 +34,56 @@ const router = createBrowserRouter([
children: [
{
path: "/",
element: <Navigate to="/destruction-lists"></Navigate>,
},
{
path: "/destruction-lists",
loader: landingLoader,
element: <Landing />,
handle: {
breadcrumbItems: [
{
label: "Vernietigingslijsten",
href: "/destruction-lists",
},
] as BreadcrumbItem[],
},
},
{
path: "/destruction-lists/create",
element: <DestructionListCreatePage />,
action: destructionListCreateAction,
loader: destructionListCreateLoader,
handle: {
breadcrumbItems: [
{
label: "Vernietigingslijsten",
href: "/destruction-lists",
},
{
label: "Aanmaken",
href: "/destruction-lists/create",
},
] as BreadcrumbItem[],
},
},
{
path: "/destruction-lists/:uuid",
element: <DestructionListDetailPage />,
action: destructionListUpdateAction,
loader: destructionListDetailLoader,
handle: {
breadcrumbItems: [
{
label: "Vernietigingslijsten",
href: "/destruction-lists",
},
{
label: "{uuid}",
href: "/destruction-lists/create",
},
] as BreadcrumbItem[],
},
},
{
path: "/destruction-lists/:uuid/review",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ export function DestructionListDetailPage() {

return (
<div className="destruction-list-detail">
<CardBaseTemplate
breadcrumbItems={[
{ label: "Vernietigingslijsten", href: "destruction-lists/" },
{ label: destructionList.name, href: "#" },
]}
>
<CardBaseTemplate>
<Body>
<H1>{destructionList.name}</H1>
<P>
Expand Down

0 comments on commit 0a988c9

Please sign in to comment.