Skip to content

Commit

Permalink
refactor(NavbarWithAuth.tsx): remove unnecessary isLoading variable a…
Browse files Browse the repository at this point in the history
…nd match statement

The isLoading variable and the match statement are no longer needed as the useAuthorization hook no longer returns an isLoading property. The code has been simplified to directly use the isAuthorized property to determine whether to display the authorized or unauthorized Navbar component.
  • Loading branch information
ktun95 committed Feb 16, 2024
1 parent b059139 commit e6aa653
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions apps/dicty-frontpage/src/app/layout/NavbarWithAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import { Navbar, formatNavbarData } from "@dictybase/navbar"
import { match } from "ts-pattern"
import { displayOnAuthorized, useAuthorization, authNavbarData } from "auth"
import { Loader } from "../../common/components/Loader"
import { navTheme } from "../../common/utils/themes"

const authorizedRoles = ["content-admin"]

const NavbarWithAuth = () => {
const { isAuthorized, isLoading } = useAuthorization({
const { isAuthorized } = useAuthorization({
entries: authorizedRoles,
})

return match(isLoading)
.with(true, () => <Loader />)
.with(false, () =>
displayOnAuthorized({
isAuthorized,
authorized: (
<Navbar items={formatNavbarData(authNavbarData)} theme={navTheme} />
),
unauthorized: <Navbar theme={navTheme} />,
}),
)
.exhaustive()
return displayOnAuthorized({
isAuthorized,
authorized: (
<Navbar items={formatNavbarData(authNavbarData)} theme={navTheme} />
),
unauthorized: <Navbar theme={navTheme} />,
})
}

export { NavbarWithAuth }

0 comments on commit e6aa653

Please sign in to comment.