fix: render metrics and smooth route transitions
This commit is contained in:
1 parent
655783b724
commit
38824a0055
3 files changed
+72
-12
No files matched your search
@@ -35,6 +35,11 @@ export default function AdminLayout() {
|
||||
const [collapsed, setCollapsed] = useState(false)
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
function navigateWithTransition(path: string) {
|
||||
const startViewTransition = (document as unknown as { startViewTransition?: (callback: () => void) => void }).startViewTransition
|
||||
if (startViewTransition) startViewTransition(() => navigate(path))
|
||||
else navigate(path)
|
||||
}
|
||||
const outlet = useOutlet()
|
||||
|
||||
const selectedKey = menuItems.find(
|
||||
@@ -66,7 +71,7 @@ export default function AdminLayout() {
|
||||
</Text>
|
||||
</div>
|
||||
<Menu mode="inline" selectedKeys={[selectedKey]} items={menuItems}
|
||||
onClick={({ key }) => navigate(key)}
|
||||
onClick={({ key }) => navigateWithTransition(String(key))}
|
||||
style={{ border: 'none', marginTop: 8 }} />
|
||||
</Sider>
|
||||
<Layout>
|
||||
|
||||
@@ -62,12 +62,16 @@ export default function LiveBoard() {
|
||||
message.error('看板数据加载失败')
|
||||
} finally {
|
||||
try {
|
||||
const [metrics, nodeResponse] = await Promise.all([getSystemMetrics(), api.get<NodeMetric[]>('/nodes')])
|
||||
setSystemMetrics(metrics)
|
||||
setNodes(nodeResponse.data)
|
||||
setSystemMetrics(await getSystemMetrics())
|
||||
} catch {
|
||||
setSystemMetrics(null)
|
||||
}
|
||||
try {
|
||||
const nodeResponse = await api.get<NodeMetric[]>('/nodes')
|
||||
setNodes(nodeResponse.data)
|
||||
} catch {
|
||||
setNodes([])
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
@@ -176,4 +180,4 @@ export default function LiveBoard() {
|
||||
</Space>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user