Skip to content

Commit

Permalink
feat: close: #250 add breadcrumbs (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinamagichub authored Sep 25, 2023
1 parent 5018647 commit 2f55297
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GrowthBook, GrowthBookProvider } from '@growthbook/growthbook-react';

import Header from '@components/Header';
import Alert from '@components/Alert';
import Breadcrumbs from '@components/Breadcrumbs';

Check failure on line 7 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / eslint (18)

Using exported name 'Breadcrumbs' as identifier for default export

// Create a GrowthBook instance
const growthbook = new GrowthBook({
Expand All @@ -23,8 +24,7 @@ function App() {

// Load feature definitions from API
fetch(
`https://cdn.growthbook.io/api/features/${
import.meta.env.VITE_GROWTH_BOOK_KEY
`https://cdn.growthbook.io/api/features/${import.meta.env.VITE_GROWTH_BOOK_KEY
}`,
)
.then((res) => res.json())
Expand All @@ -48,6 +48,7 @@ function App() {
return (
<GrowthBookProvider growthbook={growthbook}>
<Header />
<Breadcrumbs />
<Alert message="" />
<Outlet />
</GrowthBookProvider>
Expand Down
5 changes: 5 additions & 0 deletions src/components/Breadcrumbs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.breadcrumbs {
display: flex;
flex-direction: row;
gap: 5px;
}
22 changes: 22 additions & 0 deletions src/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useMatches } from "react-router-dom";
import './Breadcrumbs.css';

export function Breadcrumbs() {
let matches = useMatches();

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

View workflow job for this annotation

GitHub Actions / eslint (18)

'matches' is never reassigned. Use 'const' instead
let crumbs = matches

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

View workflow job for this annotation

GitHub Actions / eslint (18)

'crumbs' is never reassigned. Use 'const' instead
// 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">
{crumbs.map((crumb, index) => (
<li key={index}>{crumb}</li>

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

View workflow job for this annotation

GitHub Actions / eslint (18)

Do not use Array index in keys
))}
</ol>
);
}

export default Breadcrumbs;
20 changes: 19 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { lazy, StrictMode, Suspense } from 'react';
import { createRoot } from 'react-dom/client';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { createBrowserRouter, RouterProvider, Link } from 'react-router-dom';

import './index.css';

Expand All @@ -20,6 +20,12 @@ const router = createBrowserRouter(
{
path: '/',
element: <App />,
loader: ({ params }) => {

Check failure on line 23 in src/index.jsx

View workflow job for this annotation

GitHub Actions / eslint (18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return params;
},
handle: {
crumb: () => <Link to="/">Home</Link>,
},
children: [
{
path: '/',
Expand All @@ -44,10 +50,22 @@ const router = createBrowserRouter(
},
{
path: 'users',
loader: ({ params }) => {

Check failure on line 53 in src/index.jsx

View workflow job for this annotation

GitHub Actions / eslint (18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return params;
},
handle: {
crumb: () => <p>Users</p>,
},
children: [
{
path: ':userName',
element: <UserInfo />,
loader: ({ params }) => {

Check failure on line 63 in src/index.jsx

View workflow job for this annotation

GitHub Actions / eslint (18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return params;
},
handle: {
crumb: (data) => <span>{data.userName}</span>,
},
},
],
},
Expand Down

0 comments on commit 2f55297

Please sign in to comment.