Skip to content

Commit

Permalink
fix: hide breadcrumbs on the main page
Browse files Browse the repository at this point in the history
  • Loading branch information
pure-js committed Sep 25, 2023
1 parent 2f55297 commit 07f01fc
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 23 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"gh-pages": "^6.0.0",
"msw": "^1.2.2",
"postcss": "^8.4.18",
"postcss-nesting": "12.0.1",
"prettier": "3.0.3",
"standard-version": "^9.5.0",
"storybook": "^7.1.0",
Expand Down
23 changes: 23 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
plugins: {
"postcss-nesting": {},
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
...(process.env.NODE_ENV === 'production' ? { cssnano: {} } : {}),
Expand Down
8 changes: 5 additions & 3 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { Outlet } from 'react-router-dom';
import { Outlet, useLocation } from 'react-router-dom';
import { GrowthBook, GrowthBookProvider } from '@growthbook/growthbook-react';

import Header from '@components/Header';
Expand All @@ -18,6 +18,8 @@ const growthbook = new GrowthBook({
});

function App() {
const location = useLocation();

useEffect(() => {
// eslint-disable-next-line no-console
console.log(`App version: ${APP_VERSION}`);
Expand All @@ -43,12 +45,12 @@ function App() {
browser: 'foo',
url: 'foo',
});
}, []);
}, [location]);

return (
<GrowthBookProvider growthbook={growthbook}>
<Header />
<Breadcrumbs />
{ location.pathname !== '/' && <Breadcrumbs /> }
<Alert message="" />
<Outlet />
</GrowthBookProvider>
Expand Down
5 changes: 0 additions & 5 deletions src/components/Breadcrumbs.css

This file was deleted.

11 changes: 6 additions & 5 deletions src/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { useMatches } from "react-router-dom";
import './Breadcrumbs.css';

import classes from './breadcrumbs.module.css';

export function Breadcrumbs() {
let matches = useMatches();
let crumbs = matches
const matches = useMatches();
const crumbs = matches
// first get rid of any matches that don't have handle and crumb
.filter((match) => Boolean(match.handle?.crumb))
// now map them into an array of elements, passing the loader
// data to each one
.map((match) => match.handle.crumb(match.data));

return (
<ol className="breadcrumbs">
<ol className={classes.breadcrumbs}>
{crumbs.map((crumb, index) => (
<li key={index}>{crumb}</li>
<li className={classes.crumb} key={index}>{crumb}</li>

Check failure on line 17 in src/components/Breadcrumbs.tsx

View workflow job for this annotation

GitHub Actions / eslint (18)

Do not use Array index in keys
))}
</ol>
);
Expand Down
18 changes: 18 additions & 0 deletions src/components/breadcrumbs.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.breadcrumbs {
display: flex;
flex-direction: row;
gap: .4rem;
}

.crumb {
&::after {
content: '>';
margin-left: .4rem;
}

&:last-child {
&::after {
content: '';
}
}
}
14 changes: 4 additions & 10 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const router = createBrowserRouter(
{
path: '/',
element: <App />,
loader: ({ params }) => {
return params;
},
loader: ({ params }) => params,
handle: {
crumb: () => <Link to="/">Home</Link>,
},
Expand Down Expand Up @@ -50,19 +48,15 @@ const router = createBrowserRouter(
},
{
path: 'users',
loader: ({ params }) => {
return params;
},
loader: ({ params }) => params,
handle: {
crumb: () => <p>Users</p>,
crumb: () => <span>Users</span>,
},
children: [
{
path: ':userName',
element: <UserInfo />,
loader: ({ params }) => {
return params;
},
loader: ({ params }) => params,
handle: {
crumb: (data) => <span>{data.userName}</span>,
},
Expand Down

0 comments on commit 07f01fc

Please sign in to comment.