split route and navbar

This commit is contained in:
2024-06-06 11:10:24 +00:00
parent 56fc427eae
commit 0ea7ba1a39
7 changed files with 58 additions and 50 deletions

View File

@ -1,12 +1,33 @@
import { useSiteContext } from '@context/SiteContext'
import useAuth from '@hooks/useAuth'
import { NAV_ROUTES } from '@routes/routes'
import useLanguage from '@hooks/useLanguage'
import { A } from '@solidjs/router'
import { IconLogout, IconTriangle } from '@tabler/icons-solidjs'
import { IconDashboard, IconLogout, IconTriangle } from '@tabler/icons-solidjs'
import UserHelper from '@utils/auth'
import { For, Show } from 'solid-js'
import { Dynamic } from 'solid-js/web'
import './navbar.scss'
const language = useLanguage()
const userHelper = new UserHelper()
console.log(userHelper.isAdmin)
const NAV_ITEM = [
{
path: '/dashboard',
show: false,
icon: IconDashboard,
text: language?.ui.dashboard,
},
{
path: '/ware-house',
show: true,
icon: IconDashboard,
text: language?.ui.houses,
},
]
export default function Navbar() {
const { store, setAuth } = useSiteContext()
const { clickLogOut } = useAuth(setAuth)
@ -49,7 +70,7 @@ export default function Navbar() {
</div>
</Show>
<ul class="scrollnavbar menu p-4 w-80 text-base-content py-6 px-4">
<For each={NAV_ROUTES}>
<For each={NAV_ITEM}>
{(item) =>
item.show && (
<li class="mb-2">

View File

@ -1,4 +1,3 @@
import { NAV_ROUTES } from '@routes/routes'
import { useNavigate } from '@solidjs/router'
import { onMount } from 'solid-js'
@ -6,8 +5,8 @@ export default function Home() {
const navigate = useNavigate()
onMount(() => {
const first = NAV_ROUTES.filter((item) => item.show)[0]?.path || '/me'
navigate(first, { replace: true })
// const first = NAV_ROUTES.filter((item) => item.show)[0]?.path || '/me'
navigate('/me', { replace: true })
})
return <></>

View File

@ -1,4 +1,3 @@
import { NAV_ROUTES } from '@routes/routes'
import { useNavigate } from '@solidjs/router'
import { onMount } from 'solid-js'
@ -6,8 +5,7 @@ export default function WareHouse() {
const navigate = useNavigate()
onMount(() => {
const first = NAV_ROUTES.filter((item) => item.show)[0]?.path || '/me'
navigate(first, { replace: true })
navigate('/me', { replace: true })
})
return <></>

View File

@ -1,47 +1,26 @@
import useLanguage from '@hooks/useLanguage'
import { IconDashboard } from '@tabler/icons-solidjs'
import UserHelper from '@utils/auth'
import { lazy } from 'solid-js'
const language = useLanguage()
const userHelper = new UserHelper()
console.log(userHelper.isAdmin)
export const NAV_ROUTES = [
{
path: '/dashboard',
components: lazy(() => import('@pages/Dashboard')),
filter: {},
show: false,
icon: IconDashboard,
text: language?.ui.dashboard,
},
{
path: '/profile',
components: lazy(() => import('@pages/Profile')),
filter: {},
show: true,
icon: IconDashboard,
text: language?.ui.profile,
},
{
path: '/ware-house',
components: lazy(() => import('@pages/WareHouse')),
filter: {},
show: true,
icon: IconDashboard,
text: language?.ui.houses,
},
]
export const ROUTES = [
{
path: '/',
components: lazy(() => import('@pages/Home')),
filter: {},
},
...NAV_ROUTES,
{
path: '/dashboard',
components: lazy(() => import('@pages/Dashboard')),
filter: {},
},
{
path: '/profile',
components: lazy(() => import('@pages/Profile')),
filter: {},
},
{
path: '/ware-house',
components: lazy(() => import('@pages/WareHouse')),
filter: {},
},
{
path: '/me',
components: lazy(() => import('@pages/Profile')),