Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyan321 committed Sep 30, 2024
1 parent 1ebfb9a commit 7393da9
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/layouts/app-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Outlet } from 'react-router-dom'

import BaseLayout from './base-layout'
import { SidebarLayout } from './side-bar'
import { SidebarLayout } from './sidebar'

const AppLayout = () => {
return (
Expand Down
9 changes: 0 additions & 9 deletions src/layouts/side-bar.tsx

This file was deleted.

14 changes: 14 additions & 0 deletions src/layouts/sidebar/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.root {
.content {
left: var(--w);

@apply transition-all duration-500;
@apply fixed inset-0 overflow-hidden;
}

@screen phone {
.content {
left: var(--sidebar-collapse-width) !important;
}
}
}
32 changes: 32 additions & 0 deletions src/layouts/sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { KBarWrapper } from '~/components/k-bar'
import { cn } from '~/utils'

import styles from './index.module.css'

const isInApiDebugMode =
localStorage.getItem('__api') ||
localStorage.getItem('__gateway') ||
sessionStorage.getItem('__api') ||
sessionStorage.getItem('__gateway') ||
window.injectData.PAGE_PROXY

export const SidebarLayout = () => {
return (
<KBarWrapper>
<div className={styles.root}>
{isInApiDebugMode ? (
<div
className={cn([
'bg-dark-800 z-2 fixed left-0 right-0 top-0 flex h-[40px] items-center whitespace-pre text-gray-400 transition-all duration-500',
window.injectData.PAGE_PROXY && 'bg-red-900',
])}
>
123
</div>
) : (
''
)}
</div>
</KBarWrapper>
)
}
2 changes: 1 addition & 1 deletion src/providers/initial-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const progress = new QProgress({ colorful: false, color: '#1a9cf3' })
export const InitialProvider = ({ children }) => {
const matches = useMatches()
const navigation = useNavigation()

const { handle, data } = matches[matches.length - 1] as any
const title = handle && handle.title(data)
useEffect(() => {
Expand All @@ -28,5 +27,6 @@ export const InitialProvider = ({ children }) => {
}, [navigation.state])

useAttachTokenFromQuery()

return <>{children}</>
}
4 changes: 2 additions & 2 deletions src/router/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHashRouter } from 'react-router-dom'
import { createBrowserRouter } from 'react-router-dom'

import { routes } from './route'

export const router = createHashRouter(routes)
export const router = createBrowserRouter(routes)
45 changes: 45 additions & 0 deletions src/store/slice/ui.slice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createSlice } from '@reduxjs/toolkit'

export interface ViewportRecord {
w: number
h: number
mobile: boolean
pad: boolean
hpad: boolean
wider: boolean
widest: boolean
phone: boolean
}

const initialState = {
viewport: {
w: 0,
h: 0,
mobile: false,
pad: false,
hpad: false,
wider: false,
widest: false,
phone: false,
},
sidebarWidth: 250,
sidebarCollapse: false,
isDark: false,
naiveUIDark: false,
}

export const uiSlice = createSlice({
name: 'ui',
initialState,
reducers: {
toggleDark(state) {
state.isDark = !state.isDark
},
updateViewport(state, action) {
state.viewport = action.payload
},
toggleSidebar(state, action) {
state.sidebarCollapse = action.payload
},
},
})

0 comments on commit 7393da9

Please sign in to comment.