mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-24 04:47:03 +00:00
feat(web): align session rows and connection banners with native apps
- Agent icon spans both lines with a presence badge (pulsing while a turn or background work runs); no dimmed rows or row spinners - Unread is a semibold title plus accent time instead of a dot; pending requests are amber hand/bubble symbols, keeping one dot per row - Reconnecting/syncing banners appear after 2s; reconnecting is neutral, amber stays for offline
This commit is contained in:
+10
-4
@@ -9,6 +9,7 @@ import { useAuth } from '@/hooks/useAuth'
|
||||
import { useAuthSource } from '@/hooks/useAuthSource'
|
||||
import { useServerUrl } from '@/hooks/useServerUrl'
|
||||
import { useSSE } from '@/hooks/useSSE'
|
||||
import { useDelayedFlag } from '@/hooks/useDelayedFlag'
|
||||
import { useSessions } from '@/hooks/queries/useSessions'
|
||||
import { useReconnectingState } from '@/hooks/useReconnectingState'
|
||||
import { useSyncingState } from '@/hooks/useSyncingState'
|
||||
@@ -45,6 +46,8 @@ import type { SyncEvent } from '@/types/api'
|
||||
type ToastEvent = Extract<SyncEvent, { type: 'toast' }>
|
||||
|
||||
const REQUIRE_SERVER_URL = requireHubUrlForLogin()
|
||||
/** Matches the native apps: transient connection states show after 2s. */
|
||||
const CONNECTION_STATUS_DELAY_MS = 2_000
|
||||
|
||||
function withPwaBanner(content: ReactNode) {
|
||||
return (
|
||||
@@ -398,6 +401,9 @@ function AppInner() {
|
||||
)
|
||||
const sseEnabled = Boolean(api && token)
|
||||
const showReconnectingBanner = sseDisconnected && !isSyncing
|
||||
// Transient states wait before showing; quick reconnects never flash.
|
||||
const revealReconnecting = useDelayedFlag(showReconnectingBanner, CONNECTION_STATUS_DELAY_MS)
|
||||
const revealSyncing = useDelayedFlag(isSyncing, CONNECTION_STATUS_DELAY_MS)
|
||||
|
||||
const { subscriptionId: globalSubscriptionId } = useSSE({
|
||||
enabled: sseEnabled,
|
||||
@@ -515,12 +521,12 @@ function AppInner() {
|
||||
<AppContextProvider value={{ api, token, baseUrl, titleSuggestionAvailable }}>
|
||||
<VoiceProvider>
|
||||
<PwaUpdateBannerWithStatusOffset
|
||||
isSyncing={isSyncing}
|
||||
isReconnecting={showReconnectingBanner}
|
||||
isSyncing={revealSyncing}
|
||||
isReconnecting={revealReconnecting}
|
||||
/>
|
||||
<SyncingBanner isSyncing={isSyncing} />
|
||||
<SyncingBanner isSyncing={revealSyncing} />
|
||||
<ReconnectingBanner
|
||||
isReconnecting={showReconnectingBanner}
|
||||
isReconnecting={revealReconnecting}
|
||||
reason={sseDisconnectReason}
|
||||
/>
|
||||
<VoiceErrorBanner />
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Spinner } from '@/components/Spinner'
|
||||
import { useTranslation } from '@/lib/use-translation'
|
||||
|
||||
function getReasonLabel(reason: string, t: (key: string) => string): string {
|
||||
@@ -36,11 +37,13 @@ export function ReconnectingBanner({
|
||||
return null
|
||||
}
|
||||
|
||||
// Neutral like SyncingBanner: reconnecting is routine. Amber is reserved
|
||||
// for being offline (OfflineBanner). App delays this by 2s.
|
||||
return (
|
||||
<div className="fixed top-0 left-0 right-0 bg-amber-500 text-white text-center pb-2 pt-[calc(env(safe-area-inset-top)+0.5rem)] text-sm font-medium z-50 flex items-center justify-center gap-2">
|
||||
<span className="animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full" />
|
||||
<div className="fixed top-0 left-0 right-0 bg-[var(--app-banner-bg)] text-[var(--app-banner-text)] text-center pb-2 pt-[calc(env(safe-area-inset-top)+0.5rem)] text-sm font-medium z-50 flex items-center justify-center gap-2 border-b border-[var(--app-divider)]">
|
||||
<Spinner size="sm" label={null} className="text-[var(--app-banner-text)]" />
|
||||
{t('reconnecting.message')}
|
||||
{reasonLabel ? <span className="opacity-90">({reasonLabel})</span> : null}
|
||||
{reasonLabel ? <span className="text-[var(--app-hint)]">({reasonLabel})</span> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import type { PendingRequest, SessionSummary } from '@/types/api'
|
||||
import type { SessionAttention } from '@/lib/sessionAttention'
|
||||
import { getSessionAttentionLabelKey } from '@/lib/sessionAttention'
|
||||
import { useTranslation } from '@/lib/use-translation'
|
||||
import { HoverTooltip, SESSION_ROW_TOOLTIP_FOCUS_CLASS } from '@/components/HoverTooltip'
|
||||
import { LoaderIcon } from '@/components/icons'
|
||||
import { HandIcon, LoaderIcon, MessageIcon } from '@/components/icons'
|
||||
|
||||
const ATTENTION_DOT_CLASS: Record<Exclude<SessionAttention['kind'], 'background'>, string> = {
|
||||
permission: 'bg-amber-500 animate-pulse',
|
||||
input: 'bg-blue-500',
|
||||
unread: 'bg-[var(--app-link)]'
|
||||
/**
|
||||
* Pending-request symbol: amber hand (permission) or bubble (input). Symbols,
|
||||
* not dots, so the row's presence badge stays its only dot.
|
||||
*/
|
||||
export function SessionRequestIcon(props: { kind: 'permission' | 'input'; label?: string }) {
|
||||
const Icon = props.kind === 'permission' ? HandIcon : MessageIcon
|
||||
return (
|
||||
<span
|
||||
className="inline-flex shrink-0 text-[var(--app-badge-warning-text)]"
|
||||
title={props.label}
|
||||
aria-label={props.label}
|
||||
>
|
||||
<Icon className="h-3.5 w-3.5" />
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
/** Row spinner: green while a turn runs, blue while only background work runs. */
|
||||
@@ -18,7 +30,8 @@ export function SessionSpinner(props: { background?: boolean }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Visible attention dot + hover tooltip explaining the indicator.
|
||||
* Visible attention symbol (or a caller-provided `target`, e.g. the row's
|
||||
* agent icon) + hover tooltip explaining the indicator.
|
||||
*
|
||||
* The tooltip body composes from `summary.pendingRequests` (capped oldest-first;
|
||||
* see `PENDING_REQUEST_SUMMARY_CAP` in `@hapi/protocol`) for permission / input
|
||||
@@ -29,15 +42,17 @@ export function SessionAttentionIndicator(props: {
|
||||
summary: SessionSummary
|
||||
label: string
|
||||
tooltipId: string
|
||||
target?: ReactNode
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const dot = props.attention.kind === 'background' ? (
|
||||
const kind = props.attention.kind
|
||||
const dot = props.target ?? (kind === 'background' ? (
|
||||
<SessionSpinner background />
|
||||
) : kind === 'unread' ? (
|
||||
<span className="inline-flex h-2 w-2 shrink-0 rounded-full bg-[var(--app-link)]" />
|
||||
) : (
|
||||
<span
|
||||
className={`inline-flex h-2 w-2 shrink-0 rounded-full ${ATTENTION_DOT_CLASS[props.attention.kind]}`}
|
||||
/>
|
||||
)
|
||||
<SessionRequestIcon kind={kind} />
|
||||
))
|
||||
|
||||
return (
|
||||
<HoverTooltip
|
||||
|
||||
@@ -49,21 +49,42 @@ describe('SessionRowSummary background status', () => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('draws the background spinner with the thinking spinner markup, only in blue', () => {
|
||||
const background = renderSummary(false).container.querySelector('svg.animate-spin-slow')
|
||||
it('marks running and background work on the presence badge, without spinners', () => {
|
||||
const background = renderSummary(false).container
|
||||
const backgroundBadge = background.querySelector('[data-testid="session-presence"]')
|
||||
expect(backgroundBadge).toHaveClass('bg-blue-400', 'animate-pulse')
|
||||
expect(background.querySelector('svg.animate-spin-slow')).toBeNull()
|
||||
cleanup()
|
||||
|
||||
const thinking = render(
|
||||
<I18nProvider>
|
||||
<SessionRowSummary session={makeSummary({ thinking: true, backgroundTaskCount: 0 })} />
|
||||
</I18nProvider>
|
||||
).container.querySelector('svg.animate-spin-slow')
|
||||
|
||||
).container
|
||||
expect(thinking.querySelector('[data-testid="session-presence"]'))
|
||||
.toHaveClass('bg-[var(--app-badge-success-text)]', 'animate-pulse')
|
||||
expect(screen.queryByText('Running', { exact: true })).not.toBeInTheDocument()
|
||||
expect(background?.outerHTML.replace('text-blue-400', 'text-[var(--app-badge-success-text)]'))
|
||||
.toBe(thinking?.outerHTML)
|
||||
cleanup()
|
||||
|
||||
const idle = render(
|
||||
<I18nProvider>
|
||||
<SessionRowSummary session={makeSummary({ backgroundTaskCount: 0 })} />
|
||||
</I18nProvider>
|
||||
).container
|
||||
expect(idle.querySelector('[data-testid="session-presence"]')).not.toHaveClass('animate-pulse')
|
||||
})
|
||||
|
||||
it('shows a detailed background dot with the task-count tooltip in Extended mode', () => {
|
||||
it('does not dim disconnected rows or show them a presence badge', () => {
|
||||
const { container } = render(
|
||||
<I18nProvider>
|
||||
<SessionRowSummary session={makeSummary({ active: false, backgroundTaskCount: 0 })} />
|
||||
</I18nProvider>
|
||||
)
|
||||
expect(container.querySelector('.opacity-50')).toBeNull()
|
||||
expect(container.querySelector('[data-testid="session-presence"]')).toBeNull()
|
||||
})
|
||||
|
||||
it('shows a detailed background tooltip on the agent icon in Extended mode', () => {
|
||||
renderSummary(true)
|
||||
|
||||
expect(screen.queryByText('Running', { exact: true })).not.toBeInTheDocument()
|
||||
@@ -89,7 +110,8 @@ describe('SessionRowSummary background status', () => {
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
expect(screen.queryByRole('tooltip', { hidden: true })).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('New activity')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Background demo')).toHaveClass('font-normal')
|
||||
|
||||
markSessionUnread(session.id)
|
||||
view.rerender(
|
||||
@@ -102,10 +124,10 @@ describe('SessionRowSummary background status', () => {
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity')
|
||||
expectUnread()
|
||||
})
|
||||
|
||||
it('keeps an explicit unread dot across newer activity', () => {
|
||||
it('keeps an explicit unread mark across newer activity', () => {
|
||||
const session = makeSummary({
|
||||
id: 'selected-unread',
|
||||
active: false,
|
||||
@@ -126,7 +148,7 @@ describe('SessionRowSummary background status', () => {
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity')
|
||||
expectUnread()
|
||||
|
||||
view.rerender(
|
||||
<I18nProvider>
|
||||
@@ -139,10 +161,10 @@ describe('SessionRowSummary background status', () => {
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity')
|
||||
expectUnread()
|
||||
})
|
||||
|
||||
it('keeps the thinking spinner beside an explicit unread dot', () => {
|
||||
it('marks unread without a dot while the presence badge keeps pulsing', () => {
|
||||
const session = makeSummary({
|
||||
id: 'selected-thinking-unread',
|
||||
thinking: true,
|
||||
@@ -162,11 +184,14 @@ describe('SessionRowSummary background status', () => {
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity')
|
||||
expect(container.querySelector('svg.animate-spin-slow.text-\\[var\\(--app-badge-success-text\\)\\]')).not.toBeNull()
|
||||
expectUnread()
|
||||
const dots = container.querySelectorAll('.rounded-full')
|
||||
expect(dots).toHaveLength(1)
|
||||
expect(dots[0]).toHaveAttribute('data-testid', 'session-presence')
|
||||
expect(dots[0]).toHaveClass('animate-pulse')
|
||||
})
|
||||
|
||||
it('shows unseen output from a running session without hiding its spinner', () => {
|
||||
it('shows unseen output from a running session', () => {
|
||||
const session = makeSummary({ id: 'running-unread', backgroundTaskCount: 1, updatedAt: 2_000 })
|
||||
markSessionSeen(session.id, 1_000)
|
||||
|
||||
@@ -176,11 +201,36 @@ describe('SessionRowSummary background status', () => {
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity')
|
||||
expect(container.querySelector('svg.animate-spin-slow.text-blue-400')).not.toBeNull()
|
||||
expectUnread()
|
||||
expect(container.querySelector('[data-testid="session-presence"]')).toHaveClass('bg-blue-400', 'animate-pulse')
|
||||
})
|
||||
|
||||
it('shows pending requests as an amber symbol, not a dot', () => {
|
||||
const { container } = render(
|
||||
<I18nProvider>
|
||||
<SessionRowSummary
|
||||
session={makeSummary({
|
||||
backgroundTaskCount: 0,
|
||||
pendingRequestsCount: 1,
|
||||
pendingRequestKinds: ['permission'],
|
||||
pendingRequests: [{ id: 'r1', kind: 'permission', tool: 'Bash', since: 0 }],
|
||||
})}
|
||||
showDetailedStatus={true}
|
||||
/>
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('Bash')
|
||||
expect(container.querySelector('.text-\\[var\\(--app-badge-warning-text\\)\\] svg')).not.toBeNull()
|
||||
expect(container.querySelectorAll('.rounded-full')).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
function expectUnread() {
|
||||
expect(screen.getByText('New activity')).toHaveClass('sr-only')
|
||||
expect(screen.getByText(/demo|Background/, { selector: '[title]' })).toHaveClass('font-semibold')
|
||||
}
|
||||
|
||||
describe('SessionRowSummary time label', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { SessionSummary } from '@/types/api'
|
||||
import { AgentFlavorIcon } from '@/components/AgentFlavorIcon'
|
||||
import { ScheduleIcon } from '@/components/icons'
|
||||
import { HoverTooltip, SESSION_ROW_TOOLTIP_FOCUS_CLASS, useSessionRowTooltipIds } from '@/components/HoverTooltip'
|
||||
import { getAttentionLabel, SessionAttentionIndicator, SessionSpinner } from '@/components/SessionAttentionIndicator'
|
||||
import { getAttentionLabel, SessionAttentionIndicator, SessionRequestIcon } from '@/components/SessionAttentionIndicator'
|
||||
import { classifySessionAttention } from '@/lib/sessionAttention'
|
||||
import { getSessionLastSeenAt, getSessionManualUnreadAt } from '@/lib/sessionLastSeen'
|
||||
import { formatRelativeTime } from '@/lib/relativeTime'
|
||||
@@ -35,13 +35,6 @@ function BulbIcon(props: { className?: string }) {
|
||||
)
|
||||
}
|
||||
|
||||
const ATTENTION_DOT_CLASS = {
|
||||
permission: 'bg-amber-500 animate-pulse',
|
||||
input: 'bg-blue-500',
|
||||
background: 'bg-blue-400',
|
||||
unread: 'bg-[var(--app-link)]',
|
||||
} as const
|
||||
|
||||
function getTodoProgress(session: SessionSummary): { completed: number; total: number } | null {
|
||||
if (!session.todoProgress) return null
|
||||
if (session.todoProgress.completed === session.todoProgress.total) return null
|
||||
@@ -78,7 +71,9 @@ function getSessionTimeLabel(
|
||||
|
||||
/**
|
||||
* Presentational session row — same chrome as the sidebar SessionItem body
|
||||
* (flavor, title, thinking/attention, schedule, todos, relative time, path).
|
||||
* (flavor icon with presence badge, title, request/schedule symbols, todos,
|
||||
* relative time, path). Visual language matches the native apps: no dimmed
|
||||
* rows or spinners; unread is a semibold title + accent time, not a dot.
|
||||
* Used by the session list and by rich-composer mention chip tooltips.
|
||||
*/
|
||||
export function SessionRowSummary(props: {
|
||||
@@ -151,140 +146,131 @@ export function SessionRowSummary(props: {
|
||||
const importedAt = useSyncExternalStore(subscribeCodexImportedSessions, () => getCodexImportedAt(codexSessionId))
|
||||
const timeLabel = getSessionTimeLabel(s, importedAt, t)
|
||||
|
||||
return (
|
||||
<div className={`flex w-full min-w-0 flex-col gap-1 ${className ?? ''}`}>
|
||||
<div className={`grid grid-cols-[minmax(9rem,1fr)_minmax(0,max-content)] items-center gap-2 ${!s.active ? 'opacity-50' : ''}`}>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<AgentFlavorIcon flavor={s.metadata?.flavor} className="h-4 w-4 shrink-0 -translate-y-px" />
|
||||
<div
|
||||
className={`min-w-0 flex-1 truncate text-sm font-medium ${s.active ? 'text-[var(--app-fg)]' : 'text-[var(--app-hint)]'}`}
|
||||
title={sessionName}
|
||||
>
|
||||
{sessionName}
|
||||
</div>
|
||||
{attention?.kind === 'unread' ? (
|
||||
<>
|
||||
{s.active && s.thinking ? (
|
||||
<SessionSpinner />
|
||||
) : s.active && (s.backgroundTaskCount ?? 0) > 0 ? (
|
||||
<SessionSpinner background />
|
||||
) : null}
|
||||
{nestedTooltips && attentionId ? (
|
||||
<SessionAttentionIndicator
|
||||
attention={attention}
|
||||
summary={s}
|
||||
label={attentionLabel ?? ''}
|
||||
tooltipId={attentionId}
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
className={`inline-flex h-2 w-2 shrink-0 rounded-full ${ATTENTION_DOT_CLASS.unread}`}
|
||||
title={attentionLabel ?? undefined}
|
||||
aria-label={attentionLabel ?? undefined}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : s.active && s.thinking ? (
|
||||
<SessionSpinner />
|
||||
) : urgentAttention && nestedTooltips && attentionId ? (
|
||||
<SessionAttentionIndicator
|
||||
attention={attention}
|
||||
summary={s}
|
||||
label={attentionLabel ?? ''}
|
||||
tooltipId={attentionId}
|
||||
/>
|
||||
) : urgentAttention ? (
|
||||
<span
|
||||
className={`inline-flex h-2 w-2 shrink-0 rounded-full ${ATTENTION_DOT_CLASS[attention.kind]}`}
|
||||
title={attentionLabel ?? undefined}
|
||||
aria-label={attentionLabel ?? undefined}
|
||||
/>
|
||||
) : showDetailedStatus && attention?.kind === 'background' && nestedTooltips && attentionId ? (
|
||||
<SessionAttentionIndicator
|
||||
attention={attention}
|
||||
summary={s}
|
||||
label={attentionLabel ?? ''}
|
||||
tooltipId={attentionId}
|
||||
/>
|
||||
) : (showDetailedStatus && attention?.kind === 'background') || (s.active && (s.backgroundTaskCount ?? 0) > 0) ? (
|
||||
<SessionSpinner background />
|
||||
) : s.active && (s.pendingRequestsCount ?? 0) > 0 ? (
|
||||
<span
|
||||
className="inline-flex shrink-0 items-center gap-1 text-[var(--app-badge-warning-text)]"
|
||||
title={t('session.item.pending')}
|
||||
>
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-current animate-pulse" aria-hidden="true" />
|
||||
{!inRunningSection ? (
|
||||
<span className="text-[11px] font-medium leading-none">{t('session.item.pending')}</span>
|
||||
) : null}
|
||||
</span>
|
||||
) : attention && nestedTooltips && attentionId ? (
|
||||
<SessionAttentionIndicator
|
||||
attention={attention}
|
||||
summary={s}
|
||||
label={attentionLabel ?? ''}
|
||||
tooltipId={attentionId}
|
||||
/>
|
||||
) : attention ? (
|
||||
<span
|
||||
className={`inline-flex h-2 w-2 shrink-0 rounded-full ${ATTENTION_DOT_CLASS[attention.kind]}`}
|
||||
title={attentionLabel ?? undefined}
|
||||
aria-label={attentionLabel ?? undefined}
|
||||
/>
|
||||
) : null}
|
||||
{hasScheduleTooltip && nestedTooltips && scheduleId ? (
|
||||
<HoverTooltip
|
||||
id={scheduleId}
|
||||
target={<ScheduleIcon className="h-3.5 w-3.5 text-[var(--app-hint)]" />}
|
||||
side="bottom"
|
||||
align="start"
|
||||
className="shrink-0"
|
||||
revealOnParentFocusClass={SESSION_ROW_TOOLTIP_FOCUS_CLASS}
|
||||
>
|
||||
<span className="block">
|
||||
<span className="block font-medium">{scheduledLabel}</span>
|
||||
<span className="mt-1 block text-[var(--app-hint)]">
|
||||
{formatScheduledTooltipDetail(s, t)}
|
||||
</span>
|
||||
</span>
|
||||
</HoverTooltip>
|
||||
) : hasScheduleTooltip ? (
|
||||
<span className="shrink-0" aria-label={scheduledLabel} title={scheduledLabel}>
|
||||
<ScheduleIcon className="h-3.5 w-3.5 text-[var(--app-hint)]" />
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex min-w-0 items-center justify-end gap-2 overflow-hidden text-xs">
|
||||
{todoProgress ? (
|
||||
<span className="flex shrink-0 items-center gap-1 text-[var(--app-hint)]">
|
||||
<BulbIcon className="h-3 w-3" />
|
||||
{todoProgress.completed}/{todoProgress.total}
|
||||
</span>
|
||||
) : null}
|
||||
{!attention && s.active && s.pendingRequestsCount > 0 ? (
|
||||
<span className="shrink-0 text-[var(--app-badge-warning-text)]">
|
||||
{t('session.item.pending')} {s.pendingRequestsCount}
|
||||
</span>
|
||||
) : null}
|
||||
{timeLabel ? (
|
||||
<span className="min-w-0 truncate whitespace-nowrap tabular-nums text-[var(--app-hint)]">{timeLabel}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{projectLabel || machineLabel ? (
|
||||
<div className="truncate text-xs text-[var(--app-hint)]" title={[projectLabel, machineLabel].filter(Boolean).join(' · ')}>
|
||||
{[projectLabel, machineLabel].filter(Boolean).join(' · ')}
|
||||
</div>
|
||||
) : showPath || worktreeLabel ? (
|
||||
<div
|
||||
className="truncate text-xs text-[var(--app-hint)]"
|
||||
title={worktreeLabel
|
||||
? s.metadata?.worktree?.worktreePath ?? s.metadata?.path
|
||||
: undefined}
|
||||
>
|
||||
{worktreeLabel ?? s.metadata?.path ?? s.id}
|
||||
</div>
|
||||
// Presence lives on the agent icon (pulsing while a turn or background
|
||||
// work runs) instead of dimming disconnected rows or adding spinners.
|
||||
const isRunning = s.active && s.thinking
|
||||
const isBackgroundOnly = s.active && !s.thinking && (s.backgroundTaskCount ?? 0) > 0
|
||||
// Unread is a semibold title plus accent time — no dot, so the presence
|
||||
// badge stays the row's only dot. The label stays for screen readers.
|
||||
const isUnread = attention?.kind === 'unread'
|
||||
const requestKind = urgentAttention
|
||||
? attention.kind as 'permission' | 'input'
|
||||
: s.active && (s.pendingRequestsCount ?? 0) > 0
|
||||
? (s.pendingRequestKinds?.length && !s.pendingRequestKinds.includes('permission') ? 'input' : 'permission')
|
||||
: null
|
||||
const agentIcon = (
|
||||
<span className="relative inline-flex h-6 w-6 shrink-0 items-center justify-center">
|
||||
<AgentFlavorIcon flavor={s.metadata?.flavor} className="h-6 w-6" />
|
||||
{s.active ? (
|
||||
<span
|
||||
data-testid="session-presence"
|
||||
className={`absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full ring-2 ring-[var(--app-bg)] ${
|
||||
isBackgroundOnly ? 'bg-blue-400' : 'bg-[var(--app-badge-success-text)]'
|
||||
} ${isRunning || isBackgroundOnly ? 'animate-pulse' : ''}`}
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className={`flex w-full min-w-0 items-center gap-2.5 ${className ?? ''}`}>
|
||||
{attention?.kind === 'background' && nestedTooltips && attentionId ? (
|
||||
<SessionAttentionIndicator
|
||||
attention={attention}
|
||||
summary={s}
|
||||
label={attentionLabel ?? ''}
|
||||
tooltipId={attentionId}
|
||||
target={agentIcon}
|
||||
/>
|
||||
) : agentIcon}
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<div className="grid grid-cols-[minmax(9rem,1fr)_minmax(0,max-content)] items-center gap-2">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<div
|
||||
className={`min-w-0 flex-1 truncate text-sm text-[var(--app-fg)] ${isUnread ? 'font-semibold' : 'font-normal'}`}
|
||||
title={sessionName}
|
||||
>
|
||||
{sessionName}
|
||||
</div>
|
||||
{isUnread ? (
|
||||
<span id={nestedTooltips ? attentionId : undefined} className="sr-only">
|
||||
{attentionLabel}
|
||||
</span>
|
||||
) : null}
|
||||
{requestKind && urgentAttention && nestedTooltips && attentionId ? (
|
||||
<SessionAttentionIndicator
|
||||
attention={attention}
|
||||
summary={s}
|
||||
label={attentionLabel ?? ''}
|
||||
tooltipId={attentionId}
|
||||
/>
|
||||
) : requestKind ? (
|
||||
<span className="inline-flex shrink-0 items-center gap-1 text-[var(--app-badge-warning-text)]">
|
||||
<SessionRequestIcon
|
||||
kind={requestKind}
|
||||
label={attentionLabel ?? t('session.item.pending')}
|
||||
/>
|
||||
{!urgentAttention && !inRunningSection ? (
|
||||
<span className="text-[11px] font-medium leading-none">{t('session.item.pending')}</span>
|
||||
) : null}
|
||||
</span>
|
||||
) : null}
|
||||
{hasScheduleTooltip && nestedTooltips && scheduleId ? (
|
||||
<HoverTooltip
|
||||
id={scheduleId}
|
||||
target={<ScheduleIcon className="h-3.5 w-3.5 text-[var(--app-hint)]" />}
|
||||
side="bottom"
|
||||
align="start"
|
||||
className="shrink-0"
|
||||
revealOnParentFocusClass={SESSION_ROW_TOOLTIP_FOCUS_CLASS}
|
||||
>
|
||||
<span className="block">
|
||||
<span className="block font-medium">{scheduledLabel}</span>
|
||||
<span className="mt-1 block text-[var(--app-hint)]">
|
||||
{formatScheduledTooltipDetail(s, t)}
|
||||
</span>
|
||||
</span>
|
||||
</HoverTooltip>
|
||||
) : hasScheduleTooltip ? (
|
||||
<span className="shrink-0" aria-label={scheduledLabel} title={scheduledLabel}>
|
||||
<ScheduleIcon className="h-3.5 w-3.5 text-[var(--app-hint)]" />
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex min-w-0 items-center justify-end gap-2 overflow-hidden text-xs">
|
||||
{todoProgress ? (
|
||||
<span className="flex shrink-0 items-center gap-1 text-[var(--app-hint)]">
|
||||
<BulbIcon className="h-3 w-3" />
|
||||
{todoProgress.completed}/{todoProgress.total}
|
||||
</span>
|
||||
) : null}
|
||||
{!attention && s.active && s.pendingRequestsCount > 0 ? (
|
||||
<span className="shrink-0 text-[var(--app-badge-warning-text)]">
|
||||
{t('session.item.pending')} {s.pendingRequestsCount}
|
||||
</span>
|
||||
) : null}
|
||||
{timeLabel ? (
|
||||
<span className={`min-w-0 truncate whitespace-nowrap tabular-nums ${
|
||||
isUnread ? 'font-semibold text-[var(--app-link)]' : 'text-[var(--app-hint)]'
|
||||
}`}>{timeLabel}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{projectLabel || machineLabel ? (
|
||||
<div className="truncate text-xs text-[var(--app-hint)]" title={[projectLabel, machineLabel].filter(Boolean).join(' · ')}>
|
||||
{[projectLabel, machineLabel].filter(Boolean).join(' · ')}
|
||||
</div>
|
||||
) : showPath || worktreeLabel ? (
|
||||
<div
|
||||
className="truncate text-xs text-[var(--app-hint)]"
|
||||
title={worktreeLabel
|
||||
? s.metadata?.worktree?.worktreePath ?? s.metadata?.path
|
||||
: undefined}
|
||||
>
|
||||
{worktreeLabel ?? s.metadata?.path ?? s.id}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -157,6 +157,29 @@ export function ScheduleIcon(props: IconProps) {
|
||||
)
|
||||
}
|
||||
|
||||
/** Raised hand — a session waiting for permission approval. */
|
||||
export function HandIcon(props: IconProps) {
|
||||
return createIcon(
|
||||
<>
|
||||
<path d="M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2" />
|
||||
<path d="M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2" />
|
||||
<path d="M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8" />
|
||||
<path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15" />
|
||||
</>,
|
||||
props,
|
||||
2
|
||||
)
|
||||
}
|
||||
|
||||
/** Speech bubble — a session waiting for the user's reply. */
|
||||
export function MessageIcon(props: IconProps) {
|
||||
return createIcon(
|
||||
<path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z" />,
|
||||
props,
|
||||
2
|
||||
)
|
||||
}
|
||||
|
||||
/** Spinner spokes; callers add the spin animation and color. */
|
||||
export function LoaderIcon(props: IconProps) {
|
||||
return createIcon(
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { act, renderHook } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useDelayedFlag } from './useDelayedFlag'
|
||||
|
||||
describe('useDelayedFlag', () => {
|
||||
beforeEach(() => vi.useFakeTimers())
|
||||
afterEach(() => vi.useRealTimers())
|
||||
|
||||
it('reveals only after the value stays true for the delay', () => {
|
||||
const { result, rerender } = renderHook(({ value }) => useDelayedFlag(value, 2_000), {
|
||||
initialProps: { value: true },
|
||||
})
|
||||
expect(result.current).toBe(false)
|
||||
act(() => { vi.advanceTimersByTime(1_999) })
|
||||
expect(result.current).toBe(false)
|
||||
act(() => { vi.advanceTimersByTime(1) })
|
||||
expect(result.current).toBe(true)
|
||||
|
||||
rerender({ value: false })
|
||||
expect(result.current).toBe(false)
|
||||
})
|
||||
|
||||
it('never reveals a value that clears before the delay', () => {
|
||||
const { result, rerender } = renderHook(({ value }) => useDelayedFlag(value, 2_000), {
|
||||
initialProps: { value: true },
|
||||
})
|
||||
act(() => { vi.advanceTimersByTime(1_500) })
|
||||
rerender({ value: false })
|
||||
act(() => { vi.advanceTimersByTime(5_000) })
|
||||
expect(result.current).toBe(false)
|
||||
|
||||
rerender({ value: true })
|
||||
act(() => { vi.advanceTimersByTime(1_500) })
|
||||
expect(result.current).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
/**
|
||||
* True only once `value` has stayed true for `delayMs`; false immediately.
|
||||
* Transient connection states use it so a quick reconnect (tab refocus,
|
||||
* network handoff) never flashes a banner.
|
||||
*/
|
||||
export function useDelayedFlag(value: boolean, delayMs: number): boolean {
|
||||
const [revealed, setRevealed] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!value) {
|
||||
setRevealed(false)
|
||||
return
|
||||
}
|
||||
const timer = setTimeout(() => setRevealed(true), delayMs)
|
||||
return () => clearTimeout(timer)
|
||||
}, [value, delayMs])
|
||||
|
||||
return value && revealed
|
||||
}
|
||||
Reference in New Issue
Block a user