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

@@ -78,12 +78,13 @@ function useViewFallback(
}, [doc, shown, dispatch])
}
function useScene({ doc, navigate, onOpenSection, focus }: Props): Scene {
const [ui, dispatch] = useReducer(uiReducer, initialUi)
const [root, setRoot] = useState<RootAttributes | null>(null)
const viewId = ui.viewId ?? mainViewId(doc)
const model = useViewModel(doc, viewId)
const own = model.measured && root?.viewId === viewId
/** « Aller à » an annotation: the request, with what it needs of the drawing's state. */
function useSceneRequest(
{ doc, focus }: Props,
ui: UiState,
viewId: string,
dispatch: Dispatch<UiAction>,
) {
useViewFallback(doc, ui.viewId, dispatch)
useAnnotationRequest(focus, doc, {
viewId,
@@ -94,6 +95,16 @@ function useScene({ doc, navigate, onOpenSection, focus }: Props): Scene {
dispatch({ type: 'select', id })
},
})
}
function useScene(props: Props): Scene {
const { doc, navigate, onOpenSection } = props
const [ui, dispatch] = useReducer(uiReducer, initialUi)
const [root, setRoot] = useState<RootAttributes | null>(null)
const viewId = ui.viewId ?? mainViewId(doc)
const model = useViewModel(doc, viewId)
const own = model.measured && root?.viewId === viewId
useSceneRequest(props, ui, viewId, dispatch)
return {
doc,
ui,
@@ -129,8 +129,17 @@ function CategoriesCard(props: OverviewPanelProps) {
const counts = useOverviewCounts(doc)
return (
<section aria-labelledby="overview-categories" className={CARD}>
<h3 id="overview-categories" className={TITLE}>
<h3
id="overview-categories"
className={`${TITLE} flex items-center justify-between`}
>
{t('editor.overview.categories')}
<span
data-testid="overview-categories-count"
className="font-normal text-[var(--color-ink-muted)]"
>
{doc.categories.length}
</span>
</h3>
{doc.categories.length === 0 && (
<p className="text-sm text-[var(--color-ink-muted)]">