feat(header): move mobile reports into the More menu and compact the header

This commit is contained in:
Chris Scott committed 2026-10-18 19:27:03 -04:00
1 parent 7f5c242fe0
commit db40b71108
9 files changed
+232 -66

No files matched your search

@@ -0,0 +1,52 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import { ContextUsageIndicator } from './ContextUsageIndicator'
const mocks = vi.hoisted(() => ({
useContextUsage: vi.fn(),
useMobile: vi.fn(),
}))
vi.mock('@/hooks/useContextUsage', () => ({
useContextUsage: mocks.useContextUsage,
}))
vi.mock('@/hooks/useMobile', () => ({
useMobile: mocks.useMobile,
}))
function renderIndicator() {
return render(<ContextUsageIndicator sessionID="ses_1" isConnected={true} />)
}
describe('ContextUsageIndicator', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('renders tokens and percentage on desktop', () => {
mocks.useMobile.mockReturnValue(false)
mocks.useContextUsage.mockReturnValue({ usage: { totalTokens: 1234, usagePercentage: 42 }, isLoading: false })
renderIndicator()
expect(screen.getByText('1,234 (42%)')).toBeInTheDocument()
expect(screen.queryByText('42%')).not.toBeInTheDocument()
})
it('renders only the percentage on mobile', () => {
mocks.useMobile.mockReturnValue(true)
mocks.useContextUsage.mockReturnValue({ usage: { totalTokens: 1234, usagePercentage: 42 }, isLoading: false })
renderIndicator()
expect(screen.getByText('42%')).toBeInTheDocument()
expect(screen.queryByText('1,234 (42%)')).not.toBeInTheDocument()
})
it('renders only the token count on mobile without a percentage', () => {
mocks.useMobile.mockReturnValue(true)
mocks.useContextUsage.mockReturnValue({ usage: { totalTokens: 1234, usagePercentage: null }, isLoading: false })
renderIndicator()
expect(screen.getByText('1,234')).toBeInTheDocument()
})
})
@@ -1,4 +1,5 @@
import { useContextUsage } from '@/hooks/useContextUsage'
import { useMobile } from '@/hooks/useMobile'
interface ContextUsageIndicatorProps {
directory?: string
@@ -22,6 +23,7 @@ export function ContextUsageIndicator({
revertMessageID,
}: ContextUsageIndicatorProps) {
const { usage, isLoading } = useContextUsage(sessionID, directory, revertMessageID)
const isMobile = useMobile()
if (isLoading) {
return (
@@ -43,14 +45,18 @@ export function ContextUsageIndicator({
return null
}
const tokenText = usage.usagePercentage === null
const compactText = usage.usagePercentage === null
? usage.totalTokens.toLocaleString()
: `${usage.usagePercentage}%`
const fullText = usage.usagePercentage === null
? usage.totalTokens.toLocaleString()
: `${usage.totalTokens.toLocaleString()} (${usage.usagePercentage}%)`
return (
<div className="flex items-center gap-2">
<span className={`text-xs font-medium whitespace-nowrap ${getUsageTextColor(usage.usagePercentage ?? 0)}`}>
{tokenText}
{isMobile ? compactText : fullText}
</span>
</div>
)