feat: 优化Sidebar组件,支持onClick回调和外部链接导航;更新repos页面,持久化开发者过滤器状态

This commit is contained in:
xiongxiao
2026-03-20 23:00:02 +08:00
committed by cnb
parent 389f7a7ad2
commit ef08303182
3 changed files with 24 additions and 28 deletions

View File

@@ -1,7 +1,5 @@
import { QueryRouterServer } from '@kevisual/router/browser'
import { useContextKey } from '@kevisual/context'
import { useGiteaConfigStore } from '@/pages/config/gitea/store'
import { Gitea } from '@kevisual/gitea';
export const app = useContextKey('app', new QueryRouterServer())
// 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'
setTimeout(() => {
import(/* @vite-ignore */url)
}, 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'
}
})
})
}, 2000)

View File

@@ -1,5 +1,4 @@
'use client'
import { useNavigate, useLocation } from '@tanstack/react-router'
import { useState } from 'react'
import {
@@ -23,6 +22,8 @@ export interface NavItem {
badge?: string
hidden?: boolean
children?: NavItem[]
external?: boolean
onClick?: () => void
}
export interface SidebarProps {
@@ -71,10 +72,20 @@ export function Sidebar({
}
const handleNavClick = (item: NavItem) => {
// 优先执行 onClick 回调
if (item.onClick) {
item.onClick()
return
}
if (item.isDeveloping) {
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 })
} else {
navigate({ href: item.path })
}
}

View File

@@ -24,20 +24,15 @@ export const App = () => {
setShowCreateDialog: state.setShowCreateDialog,
})))
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 me = useLayoutStore(state => state.me)
const configStore = useConfigStore(useShallow(state => ({ checkConfig: state.checkConfig })))
useEffect(() => {
refresh({ showTips: false })
}, [])
useEffect(() => {
if (me && me.id) {
configStore.checkConfig({ isUser: true, reload: true })
}
}, [me])
const appList = useMemo(() => {
const sortedList = [...list].sort((a, b) => {
const aActive = workspaceList.some(ws => ws.slug === a.path)
@@ -136,7 +131,11 @@ export const App = () => {
<Checkbox
id="filter-dev"
checked={filterDev}
onCheckedChange={(checked) => setFilterDev(checked === true)}
onCheckedChange={(checked) => {
const value = checked === true
setFilterDev(value)
localStorage.setItem('repos-filter-dev', String(value))
}}
/>
<label
htmlFor="filter-dev"