mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
inspect path by breadcrumbs
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import { useContext } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
import Link from 'next/link'
|
||||
import UserContext from './user/context'
|
||||
|
||||
export default function Breadcrumbs({ label }: { label: string }) {
|
||||
export default function Breadcrumbs() {
|
||||
const { username, role } = useContext(UserContext)
|
||||
const router = useRouter()
|
||||
|
||||
if (!label) {
|
||||
const breadcrumbs = router.asPath.replace(/^\//, '').split('/')
|
||||
|
||||
if (!breadcrumbs.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
// TODO: translate routes
|
||||
// TODO: make entries linkable
|
||||
return (
|
||||
<div className="flex flex-row items-center px-3 py-1 text-white text-base bg-blue-400 rounded-b-sm">
|
||||
{role === 'admin' && (
|
||||
@@ -22,10 +28,16 @@ export default function Breadcrumbs({ label }: { label: string }) {
|
||||
<a className="font-extrabold">Home</a>
|
||||
</Link>
|
||||
</h2>
|
||||
{'>'}
|
||||
<h2 className="mx-1 flex-grow">
|
||||
<span className="font-extrabold">{label}</span>
|
||||
</h2>
|
||||
{breadcrumbs.map((breadcrumb) => {
|
||||
return (
|
||||
<>
|
||||
{'>'}
|
||||
<h2 className="mx-1">
|
||||
<span className="font-extrabold">{breadcrumb}</span>
|
||||
</h2>
|
||||
</>
|
||||
)
|
||||
})}
|
||||
</>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ import Link from 'next/link'
|
||||
import Logo from './logo'
|
||||
import Breadcrumbs from './breadcrumbs'
|
||||
|
||||
export default function Header({ label }: { label?: string }) {
|
||||
export default function Header() {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -20,7 +20,7 @@ export default function Header({ label }: { label?: string }) {
|
||||
</h1>
|
||||
<Logo className="w-40 flex-shrink-0" />
|
||||
</div>
|
||||
<Breadcrumbs label={label} />
|
||||
<Breadcrumbs />
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user