refactor(editor): split B1 navigation hooks, category count on the overview card

This commit is contained in:
bchanot committed 2026-11-06 20:31:26 +01:00
1 parent bc2dba7c14
commit ca184da4d9
6 files changed
+166 -82

No files matched your search

+34 -11
View File
@@ -5,6 +5,7 @@ import type {
} from '@faunosteo/core-wasm/types'
import {
AnnounceContext,
type FocusOutcome,
useFocusRequest,
visibleElement,
type FocusRequest,
@@ -39,6 +40,33 @@ const BUSY_TARGET = {
const focusFirst = (selector: string) => visibleElement(selector)?.focus()
/** A creation or tracing in progress keeps the request: focus its panel, say why. */
function keepBusy(
busy: NonNullable<DrawingState['busy']>,
announce: (text: string) => void,
say: string,
): FocusOutcome {
announce(say)
focusFirst(BUSY_TARGET[busy])
return 'kept'
}
/** Shows the annotation: at once when it is already shown, else after the next render. */
function showAnnotation(
found: { viewId: string; annotationId: string },
drawing: DrawingState,
awaiting: { current: string | null },
): void {
const same =
drawing.selectedId === found.annotationId && drawing.viewId === found.viewId
if (same) {
focusFirst('[data-properties-heading]')
return
}
awaiting.current = found.annotationId
drawing.show(found.viewId, found.annotationId)
}
/**
* « Aller à » an annotation on the drawing: shows its view, selects it, then focuses the
* properties heading once it has rendered. While a creation or a tracing is in progress
@@ -57,18 +85,13 @@ export function useAnnotationRequest(
const found = target.key ? annotationFocus(doc, target.key) : null
if (!found) return 'none'
if (drawing.busy) {
announce(t(`editor.live.${drawing.busy}_kept`))
focusFirst(BUSY_TARGET[drawing.busy])
return 'kept'
}
const same =
drawing.selectedId === found.annotationId &&
drawing.viewId === found.viewId
if (same) focusFirst('[data-properties-heading]')
else {
awaiting.current = found.annotationId
drawing.show(found.viewId, found.annotationId)
return keepBusy(
drawing.busy,
announce,
t(`editor.live.${drawing.busy}_kept`),
)
}
showAnnotation(found, drawing, awaiting)
return 'found'
})
useEffect(() => {