mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-11 03:46:49 -07:00
refactor(cli): only increment tips counter when visible
This commit is contained in:
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user