split route and navbar

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

View File

@ -18,12 +18,19 @@ install `Taskfile` first with this command line:
```bash ```bash
npm install -g @go-task/cli npm install -g @go-task/cli
``` ```
more information : [Link](https://taskfile.dev/installation/)
install `pnpm` for front-end with command line: install `pnpm` for front-end with command line:
```bash ```bash
npm i pnpm -g npm i pnpm -g
``` ```
install `poetry` for back-end with command line:
```bash
curl -sSL https://install.python-poetry.org | python3 -
```
for more information please see here : [Link](https://python-poetry.org/docs/#installing-with-the-official-installer)
# Common CLI # Common CLI
### alembic ### alembic

View File

@ -3,6 +3,9 @@
"private": true, "private": true,
"version": "0.0.0", "version": "0.0.0",
"type": "module", "type": "module",
"engines": {
"node": ">=18.20.2"
},
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",

View File

@ -1,12 +1,33 @@
import { useSiteContext } from '@context/SiteContext' import { useSiteContext } from '@context/SiteContext'
import useAuth from '@hooks/useAuth' import useAuth from '@hooks/useAuth'
import { NAV_ROUTES } from '@routes/routes' import useLanguage from '@hooks/useLanguage'
import { A } from '@solidjs/router' 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 { For, Show } from 'solid-js'
import { Dynamic } from 'solid-js/web' import { Dynamic } from 'solid-js/web'
import './navbar.scss' 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() { export default function Navbar() {
const { store, setAuth } = useSiteContext() const { store, setAuth } = useSiteContext()
const { clickLogOut } = useAuth(setAuth) const { clickLogOut } = useAuth(setAuth)
@ -49,7 +70,7 @@ export default function Navbar() {
</div> </div>
</Show> </Show>
<ul class="scrollnavbar menu p-4 w-80 text-base-content py-6 px-4"> <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) =>
item.show && ( item.show && (
<li class="mb-2"> <li class="mb-2">

View File

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

View File

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

View File

@ -1,7 +1,7 @@
import path, { dirname } from 'path' import path, { dirname } from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
import { defineConfig, loadEnv } from 'vite' import { defineConfig, loadEnv } from 'vite'
import mkcert from 'vite-plugin-mkcert' // import mkcert from 'vite-plugin-mkcert'
import solid from 'vite-plugin-solid' import solid from 'vite-plugin-solid'
const _dirname = dirname(fileURLToPath(import.meta.url)) const _dirname = dirname(fileURLToPath(import.meta.url))
@ -28,9 +28,9 @@ export default defineConfig(({ mode }) => {
'@context': path.resolve(_dirname, './src/context'), '@context': path.resolve(_dirname, './src/context'),
}, },
}, },
plugins: [solid(), mkcert()], plugins: [solid()],
server: { server: {
https: true, https: false,
host: true, host: true,
port: 5001, port: 5001,
strictPort: true, strictPort: true,
@ -56,9 +56,10 @@ export default defineConfig(({ mode }) => {
'@context': path.resolve(_dirname, './src/context'), '@context': path.resolve(_dirname, './src/context'),
}, },
}, },
plugins: [solid(), mkcert()], // plugins: [solid(), mkcert()],
plugins: [solid()],
server: { server: {
https: true, https: false,
host: true, host: true,
port: 5001, port: 5001,
strictPort: true, strictPort: true,