AgentEvalTool/frontend/web/src/hooks/useOnTabActive.ts
sinohqb 9c564b575e feat(frontend): v0.4 login page, dashboard rebuild, reports UX, keep-alive refresh
- 登录页 + App 鉴权门 + X-Auth-Token 拦截器 + 菜单头部退出按钮
- 仪表盘重构:6 指标卡 / 趋势图 + 场景表现 / 最近记录 + 快捷操作 + 来源分布
- Reports 页重做:场景筛选、富选项下拉、allowClear、一键重置、同场景对比约束
- useOnTabActive:标签页激活自动刷新(根治 AI 助手评测记录"消失")
- ModelConfigs 12 列合并为 6 列;来源 Tag;chunk 告警阈值修正并记录原因
2026-07-28 17:41:08 +08:00

24 lines
694 B
TypeScript

import { useEffect, useRef } from 'react'
import { useTabStore } from '../stores/tabStore'
/**
* Keep-alive tabs never remount, so "load on mount" data goes stale.
* Fires `callback` every time the given tab path becomes active again
* (skips the initial mount, which pages already handle themselves).
*/
export function useOnTabActive(path: string, callback: () => void) {
const activeKey = useTabStore((s) => s.activeKey)
const first = useRef(true)
const cbRef = useRef(callback)
cbRef.current = callback
useEffect(() => {
if (activeKey !== path) return
if (first.current) {
first.current = false
return
}
cbRef.current()
}, [activeKey, path])
}