Code-review follow-ups: httputil, validation caps, a11y
Backend: - Extract shared internal/httputil (WriteJSON/ErrorJSON/BadRequest/ ServerError); drop the triple-duplicated helpers in docs, suggestions, vocab. ServerError now logs the real error and returns a generic 500 so raw DB/internal errors never reach the client. - vocab capture: validate doc_id ownership (blank -> none, unknown -> 400 instead of a leaked FK 500); rune-safe clamp word/gloss/definition/ phonetic/example. - vocab review(): wrap the read-modify-write in a transaction (TOCTOU). - /api request-size cap via MaxBytesReader middleware (2 MiB), exempting /api/images (own 10 MiB limit). Frontend: - StatusBar: drive the checking/voicing/collocating indicators from one array; llmDown uses !anyBusy. - Slide-overs: new useFocusTrap hook (focus-in, Tab trap, focus-restore) on GardenPanel + HistoryPanel, both role=dialog/aria-modal/aria-label. - speech.ts: export stopSpeech(); GardenPanel cancels audio on unmount. Tests: add doc_id-validation and field-clamp coverage; full suite green. Claude-Session: https://claude.ai/code/session_016Yr6jELuRc7hyzYLccQKZd
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Fragment, useEffect, useRef, useState } from 'react'
|
||||
import type { SaveStatus } from '../../hooks/useAutoSave'
|
||||
import { StatsPanel } from './StatsPanel'
|
||||
import { SoundToggle } from './SoundToggle'
|
||||
@@ -30,8 +30,40 @@ const SAVE_LABEL: Record<SaveStatus, string> = {
|
||||
// StatusBar is the slim footer: word count on the left, save state and the
|
||||
// grammar-checkpoint indicator on the right. The checkpoint dot is a soft rose
|
||||
// circle that breathes while a check is in flight (spec → Signature animations).
|
||||
// The live "Petal is working" indicators. Each is a breathing dot + label shown
|
||||
// while its pass is in flight; driving them from one array keeps the markup (and
|
||||
// the "nothing in flight" check below) in lockstep as passes are added.
|
||||
interface Indicator {
|
||||
active: boolean
|
||||
color: string
|
||||
title: string
|
||||
label: string
|
||||
}
|
||||
|
||||
export function StatusBar({ wordCount, text, saveStatus, checking, voicing, collocating, llmDown }: Props) {
|
||||
const label = SAVE_LABEL[saveStatus]
|
||||
|
||||
const indicators: Indicator[] = [
|
||||
{
|
||||
active: checking,
|
||||
color: 'var(--color-accent)',
|
||||
title: 'Petal is reading your writing…',
|
||||
label: 'Checking…',
|
||||
},
|
||||
{
|
||||
active: voicing,
|
||||
color: 'var(--color-honey)',
|
||||
title: 'Petal is reading your voice…',
|
||||
label: 'Reading your voice…',
|
||||
},
|
||||
{
|
||||
active: collocating,
|
||||
color: 'var(--color-blossom)',
|
||||
title: 'Petal is looking for more natural word pairings…',
|
||||
label: 'Finding natural phrasing…',
|
||||
},
|
||||
]
|
||||
const anyBusy = indicators.some((i) => i.active)
|
||||
// The expanded stats panel toggles open when the word count is clicked.
|
||||
const [statsOpen, setStatsOpen] = useState(false)
|
||||
const statsRef = useRef<HTMLDivElement>(null)
|
||||
@@ -68,43 +100,21 @@ export function StatusBar({ wordCount, text, saveStatus, checking, voicing, coll
|
||||
</button>
|
||||
{statsOpen && <StatsPanel text={text} wordCount={wordCount} />}
|
||||
</div>
|
||||
{checking && (
|
||||
<>
|
||||
<span aria-hidden>·</span>
|
||||
<span className="inline-flex items-center gap-1.5" title="Petal is reading your writing…">
|
||||
<span
|
||||
className="petal-checkpoint-dot inline-block h-2 w-2 rounded-full"
|
||||
style={{ background: 'var(--color-accent)' }}
|
||||
/>
|
||||
Checking…
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
{voicing && (
|
||||
<>
|
||||
<span aria-hidden>·</span>
|
||||
<span className="inline-flex items-center gap-1.5" title="Petal is reading your voice…">
|
||||
<span
|
||||
className="petal-checkpoint-dot inline-block h-2 w-2 rounded-full"
|
||||
style={{ background: 'var(--color-honey)' }}
|
||||
/>
|
||||
Reading your voice…
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
{collocating && (
|
||||
<>
|
||||
<span aria-hidden>·</span>
|
||||
<span className="inline-flex items-center gap-1.5" title="Petal is looking for more natural word pairings…">
|
||||
<span
|
||||
className="petal-checkpoint-dot inline-block h-2 w-2 rounded-full"
|
||||
style={{ background: 'var(--color-blossom)' }}
|
||||
/>
|
||||
Finding natural phrasing…
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
{llmDown && !checking && !voicing && !collocating && (
|
||||
{indicators
|
||||
.filter((i) => i.active)
|
||||
.map((i) => (
|
||||
<Fragment key={i.label}>
|
||||
<span aria-hidden>·</span>
|
||||
<span className="inline-flex items-center gap-1.5" title={i.title}>
|
||||
<span
|
||||
className="petal-checkpoint-dot inline-block h-2 w-2 rounded-full"
|
||||
style={{ background: i.color }}
|
||||
/>
|
||||
{i.label}
|
||||
</span>
|
||||
</Fragment>
|
||||
))}
|
||||
{llmDown && !anyBusy && (
|
||||
<>
|
||||
<span aria-hidden>·</span>
|
||||
<span
|
||||
|
||||
Reference in New Issue
Block a user