refactor(cli): only increment tips counter when visible

This commit is contained in:
Keith Guerin
2026-03-30 16:07:57 -07:00
parent bf48644640
commit d7396b53e3
3 changed files with 23 additions and 6 deletions
+5 -3
View File
@@ -62,7 +62,10 @@ export const AppHeader = ({ version, showDetails = true }: AppHeaderProps) => {
const { terminalWidth, bannerData, bannerVisible, updateInfo } = useUIState();
const { bannerText } = useBanner(bannerData);
const { showTips } = useTips();
const isTipsVisible = !(
settings.merged.ui.hideTips || config.getScreenReader()
);
const { showTips } = useTips({ isVisible: isTipsVisible });
const authType = config.getContentGeneratorConfig()?.authType;
const loggedOut = !authType;
@@ -159,8 +162,7 @@ export const AppHeader = ({ version, showDetails = true }: AppHeaderProps) => {
/>
)}
{!(settings.merged.ui.hideTips || config.getScreenReader()) &&
showTips && <Tips config={config} />}
{isTipsVisible && showTips && <Tips config={config} />}
</Box>
);
};
+10
View File
@@ -14,6 +14,7 @@ import { useTips } from './useTips.js';
describe('useTips()', () => {
beforeEach(() => {
vi.clearAllMocks();
persistentStateMock.setData({ tipsShown: undefined });
});
it('should return false and call set(1) if state is undefined', async () => {
@@ -44,4 +45,13 @@ describe('useTips()', () => {
expect(persistentStateMock.set).not.toHaveBeenCalled();
expect(persistentStateMock.get('tipsShown')).toBe(10);
});
it('should NOT increment if isVisible is false', async () => {
const { result } = await renderHookWithProviders(() =>
useTips({ isVisible: false }),
);
expect(result.current.showTips).toBe(true);
expect(persistentStateMock.set).not.toHaveBeenCalled();
});
});
+8 -3
View File
@@ -11,16 +11,21 @@ interface UseTipsResult {
showTips: boolean;
}
export function useTips(): UseTipsResult {
interface UseTipsOptions {
isVisible?: boolean;
}
export function useTips(options: UseTipsOptions = {}): UseTipsResult {
const { isVisible = true } = options;
const [tipsCount] = useState(() => persistentState.get('tipsShown') ?? 0);
const showTips = tipsCount < 10;
useEffect(() => {
if (showTips) {
if (showTips && isVisible) {
persistentState.set('tipsShown', tipsCount + 1);
}
}, [tipsCount, showTips]);
}, [tipsCount, showTips, isVisible]);
return { showTips };
}