fix(activity): animate the braille spinner in SVG and tighten the activity lists

- Draw the TUI braille spinner as a 2x4 SVG dot cell stepped by declarative
  <animate> timelines derived from SPINNER_FRAMES: no JavaScript timer or React
  render per frame, and it keeps animating under prefers-reduced-motion so an
  active session never looks stalled
- Enlarge the spinner cell and dots so it stays legible next to 14px text
- Add a compact ActivityList variant for the mobile More drawer and Repos sheet:
  one flat list capped at five rows, single-line rows, no group subheadings
- Let ActivityList callers own navigation so a row tap navigates once instead of
  pushing a duplicate history entry
- Share the picker keyboard navigation between the session and project tabs and
  reuse the shared session merge helpers in the sidebar repo groups
This commit is contained in:
Chris Scott committed 2026-10-16 11:42:03 -04:00
1 parent d8f2fcf29c
commit 8b6251d83b
24 files changed
+858 -787

No files matched your search

@@ -1,14 +1,7 @@
import { act, cleanup, render } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { stubMatchMedia } from '@/test/test-utils'
import { cleanup, render } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { ActivitySpinner, SPINNER_FRAMES, brailleDots } from './activity-spinner'
const advanceFrames = (count: number) => {
act(() => {
vi.advanceTimersByTime(80 * count)
})
}
const circles = (root: ParentNode) => Array.from(root.querySelectorAll('circle'))
const litIndexes = (root: ParentNode) =>
@@ -21,24 +14,17 @@ const litIndexesFor = (frame: string) =>
.map((lit, index) => (lit ? index : -1))
.filter((index) => index >= 0)
const pattern = (root: ParentNode) => circles(root).map((circle) => circle.getAttribute('fill-opacity'))
describe('brailleDots', () => {
it('lights dots 1, 2 and 4 for the first frame', () => {
expect(brailleDots('⠋')).toEqual([true, true, false, true, false, false, false, false])
})
it('lights dots 1 through 4 for the fourth frame', () => {
it('lights dots 1 through 4 for the last frame', () => {
expect(brailleDots('⠏')).toEqual([true, true, true, true, false, false, false, false])
})
})
describe('ActivitySpinner', () => {
beforeEach(() => {
vi.useFakeTimers()
stubMatchMedia(false)
})
afterEach(() => {
cleanup()
vi.useRealTimers()
@@ -52,67 +38,35 @@ describe('ActivitySpinner', () => {
expect(container.querySelector('svg')).toHaveAttribute('aria-hidden', 'true')
})
it('advances one frame every 80ms and wraps after the last frame', () => {
it('steps every dot through all frames in order with a discrete, endless 80ms-per-frame animation', () => {
const { container } = render(<ActivitySpinner />)
expect(litIndexes(container)).toEqual(litIndexesFor(SPINNER_FRAMES[0]))
circles(container).forEach((circle, dotIndex) => {
const animate = circle.querySelector('animate')
expect(animate).toHaveAttribute('attributeName', 'fill-opacity')
expect(animate).toHaveAttribute('calcMode', 'discrete')
expect(animate).toHaveAttribute('repeatCount', 'indefinite')
expect(animate).toHaveAttribute('dur', `${80 * SPINNER_FRAMES.length}ms`)
advanceFrames(1)
expect(litIndexes(container)).toEqual(litIndexesFor(SPINNER_FRAMES[1]))
advanceFrames(1)
expect(litIndexes(container)).toEqual(litIndexesFor(SPINNER_FRAMES[2]))
advanceFrames(SPINNER_FRAMES.length - 2)
expect(litIndexes(container)).toEqual(litIndexesFor(SPINNER_FRAMES[0]))
const values = animate?.getAttribute('values')?.split(';')
expect(values).toEqual(SPINNER_FRAMES.map((frame) => (brailleDots(frame)[dotIndex] ? '1' : '0.25')))
})
})
it('drives every mounted spinner from a single shared ticker', () => {
const { container } = render(
it('schedules no JavaScript timers however many spinners are mounted', () => {
vi.useFakeTimers()
render(
<>
<ActivitySpinner />
<ActivitySpinner />
<ActivitySpinner />
</>,
)
expect(vi.getTimerCount()).toBe(1)
const [first, second] = Array.from(container.querySelectorAll('svg'))
expect(pattern(first)).toEqual(pattern(second))
advanceFrames(1)
expect(litIndexes(first)).toEqual(litIndexesFor(SPINNER_FRAMES[1]))
expect(pattern(first)).toEqual(pattern(second))
})
it('clears the shared ticker when the last spinner unmounts', () => {
const { unmount } = render(
<>
<ActivitySpinner />
<ActivitySpinner />
</>,
)
expect(vi.getTimerCount()).toBe(1)
unmount()
expect(vi.getTimerCount()).toBe(0)
})
it('keeps animating when the user prefers reduced motion', () => {
stubMatchMedia(true)
const { container } = render(<ActivitySpinner />)
expect(vi.getTimerCount()).toBe(1)
advanceFrames(1)
expect(litIndexes(container)).toEqual(litIndexesFor(SPINNER_FRAMES[1]))
})
it('keeps every dot inside the cell and clear of its neighbours', () => {
const { container } = render(<ActivitySpinner />)
+21 -41
View File
@@ -1,9 +1,9 @@
import { useSyncExternalStore } from 'react'
import { cn } from '@/lib/utils'
export const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] as const
const FRAME_INTERVAL_MS = 80
const CYCLE_DURATION = `${FRAME_INTERVAL_MS * SPINNER_FRAMES.length}ms`
const BRAILLE_BASE = 0x2800
const DOT_GRID: ReadonlyArray<readonly [number, number]> = [
@@ -19,41 +19,9 @@ const DOT_GRID: ReadonlyArray<readonly [number, number]> = [
const COLUMN_X = [2.25, 6.75] as const
const ROW_Y = [2.25, 6, 9.75, 13.5] as const
const DOT_RADIUS = 1.6
const LIT_DOT_OPACITY = 1
const UNLIT_DOT_OPACITY = 0.25
let frameIndex = 0
const listeners = new Set<() => void>()
let ticker: ReturnType<typeof setInterval> | null = null
function emit() {
for (const listener of listeners) {
listener()
}
}
function subscribe(listener: () => void) {
listeners.add(listener)
if (ticker === null) {
ticker = setInterval(() => {
frameIndex = (frameIndex + 1) % SPINNER_FRAMES.length
emit()
}, FRAME_INTERVAL_MS)
}
return () => {
listeners.delete(listener)
if (listeners.size === 0 && ticker !== null) {
clearInterval(ticker)
ticker = null
frameIndex = 0
}
}
}
function getSnapshot() {
return frameIndex
}
/**
* Decodes one braille frame into its eight dot positions, ordered by braille dot numbering:
* dot1, dot2 and dot3 are the left column top-to-bottom, dot4, dot5 and dot6 the right column
@@ -64,17 +32,21 @@ export function brailleDots(frame: string): boolean[] {
return DOT_GRID.map((_, index) => (bits & (1 << index)) !== 0)
}
const FRAME_DOTS = SPINNER_FRAMES.map(brailleDots)
const DOT_OPACITY_TIMELINES = DOT_GRID.map((_, index) =>
FRAME_DOTS.map((dots) => (dots[index] ? LIT_DOT_OPACITY : UNLIT_DOT_OPACITY)),
)
/**
* Braille spinner mirroring the OpenCode TUI activity spinner as an inline SVG cell so the dots
* stay visible at small text sizes. Every mounted instance shares one module-level 80 ms ticker,
* which starts with the first subscriber and stops with the last. It animates regardless of
* stay visible at small text sizes. Each dot steps through its opacity for every frame with a
* declarative SVG `<animate>` derived from `SPINNER_FRAMES`, so frames advance in the browser
* with no JavaScript or React render per frame. It animates regardless of
* `prefers-reduced-motion`: a still frame is indistinguishable from a stalled spinner, and the
* motion is a small in-place status cue like the platform activity indicators.
*/
export function ActivitySpinner({ className }: { className?: string }) {
const frame = useSyncExternalStore(subscribe, getSnapshot, getSnapshot)
const dots = brailleDots(SPINNER_FRAMES[frame])
return (
<svg
aria-hidden="true"
@@ -88,8 +60,16 @@ export function ActivitySpinner({ className }: { className?: string }) {
cy={ROW_Y[row]}
r={DOT_RADIUS}
fill="currentColor"
fillOpacity={dots[index] ? 1 : UNLIT_DOT_OPACITY}
/>
fillOpacity={DOT_OPACITY_TIMELINES[index][0]}
>
<animate
attributeName="fill-opacity"
values={DOT_OPACITY_TIMELINES[index].join(';')}
dur={CYCLE_DURATION}
calcMode="discrete"
repeatCount="indefinite"
/>
</circle>
))}
</svg>
)