generated from kevisual/vite-react-template
feat: 优化Sidebar组件,支持onClick回调和外部链接导航;更新repos页面,持久化开发者过滤器状态
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import { QueryRouterServer } from '@kevisual/router/browser'
|
import { QueryRouterServer } from '@kevisual/router/browser'
|
||||||
import { useContextKey } from '@kevisual/context'
|
import { useContextKey } from '@kevisual/context'
|
||||||
import { useGiteaConfigStore } from '@/pages/config/gitea/store'
|
|
||||||
import { Gitea } from '@kevisual/gitea';
|
|
||||||
export const app = useContextKey('app', new QueryRouterServer())
|
export const app = useContextKey('app', new QueryRouterServer())
|
||||||
|
|
||||||
// import '@kevisual/cnb-ai'
|
// import '@kevisual/cnb-ai'
|
||||||
@@ -9,16 +7,4 @@ export const app = useContextKey('app', new QueryRouterServer())
|
|||||||
const url = 'https://kevisual.cn/root/cnb-ai/dist/app.js'
|
const url = 'https://kevisual.cn/root/cnb-ai/dist/app.js'
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
import(/* @vite-ignore */url)
|
import(/* @vite-ignore */url)
|
||||||
}, 2000)
|
}, 2000)
|
||||||
|
|
||||||
export const gitea = useContextKey('gitea', () => {
|
|
||||||
const state = useGiteaConfigStore.getState()
|
|
||||||
const config = state.config || {}
|
|
||||||
return new Gitea({
|
|
||||||
token: config.GITEA_TOKEN,
|
|
||||||
baseURL: config.GITEA_URL,
|
|
||||||
cors: {
|
|
||||||
baseUrl: 'https://cors.kevisual.cn'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useNavigate, useLocation } from '@tanstack/react-router'
|
import { useNavigate, useLocation } from '@tanstack/react-router'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import {
|
import {
|
||||||
@@ -23,6 +22,8 @@ export interface NavItem {
|
|||||||
badge?: string
|
badge?: string
|
||||||
hidden?: boolean
|
hidden?: boolean
|
||||||
children?: NavItem[]
|
children?: NavItem[]
|
||||||
|
external?: boolean
|
||||||
|
onClick?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SidebarProps {
|
export interface SidebarProps {
|
||||||
@@ -71,10 +72,20 @@ export function Sidebar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleNavClick = (item: NavItem) => {
|
const handleNavClick = (item: NavItem) => {
|
||||||
|
// 优先执行 onClick 回调
|
||||||
|
if (item.onClick) {
|
||||||
|
item.onClick()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (item.isDeveloping) {
|
if (item.isDeveloping) {
|
||||||
setDevelopingDialog({ open: true, title: item.title })
|
setDevelopingDialog({ open: true, title: item.title })
|
||||||
} else {
|
} else if (item.external && item.path.startsWith('http')) {
|
||||||
|
window.open(item.path, '_blank')
|
||||||
|
} else if (item.path.startsWith('/')) {
|
||||||
navigate({ to: item.path })
|
navigate({ to: item.path })
|
||||||
|
} else {
|
||||||
|
navigate({ href: item.path })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,20 +24,15 @@ export const App = () => {
|
|||||||
setShowCreateDialog: state.setShowCreateDialog,
|
setShowCreateDialog: state.setShowCreateDialog,
|
||||||
})))
|
})))
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const [filterDev, setFilterDev] = useState(false)
|
const [filterDev, setFilterDev] = useState(() => {
|
||||||
|
const saved = localStorage.getItem('repos-filter-dev')
|
||||||
|
return saved === 'true'
|
||||||
|
})
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const me = useLayoutStore(state => state.me)
|
|
||||||
const configStore = useConfigStore(useShallow(state => ({ checkConfig: state.checkConfig })))
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refresh({ showTips: false })
|
refresh({ showTips: false })
|
||||||
}, [])
|
}, [])
|
||||||
useEffect(() => {
|
|
||||||
if (me && me.id) {
|
|
||||||
configStore.checkConfig({ isUser: true, reload: true })
|
|
||||||
}
|
|
||||||
}, [me])
|
|
||||||
|
|
||||||
|
|
||||||
const appList = useMemo(() => {
|
const appList = useMemo(() => {
|
||||||
const sortedList = [...list].sort((a, b) => {
|
const sortedList = [...list].sort((a, b) => {
|
||||||
const aActive = workspaceList.some(ws => ws.slug === a.path)
|
const aActive = workspaceList.some(ws => ws.slug === a.path)
|
||||||
@@ -136,7 +131,11 @@ export const App = () => {
|
|||||||
<Checkbox
|
<Checkbox
|
||||||
id="filter-dev"
|
id="filter-dev"
|
||||||
checked={filterDev}
|
checked={filterDev}
|
||||||
onCheckedChange={(checked) => setFilterDev(checked === true)}
|
onCheckedChange={(checked) => {
|
||||||
|
const value = checked === true
|
||||||
|
setFilterDev(value)
|
||||||
|
localStorage.setItem('repos-filter-dev', String(value))
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
htmlFor="filter-dev"
|
htmlFor="filter-dev"
|
||||||
|
|||||||
Reference in New Issue
Block a user