refactor(editor): split B1 navigation hooks, category count on the overview card
This commit is contained in:
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)]">
|
||||
|
||||
@@ -26,29 +26,29 @@ export interface AnnotationsTabProps extends EditorPlaceProps {
|
||||
onBack: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations: the drawing workspace (canvas with its tools, the overview or the
|
||||
* properties and creation panels), or one of its full-width sections. Read-only, the
|
||||
* same view is browsable (canvas, list, properties as text) with no tool and no action.
|
||||
*/
|
||||
export default function AnnotationsTab(props: AnnotationsTabProps) {
|
||||
/** A full-width section, once the document is loaded. */
|
||||
function SectionPlace(props: AnnotationsTabProps) {
|
||||
const doc = useSheetDocument()
|
||||
if (!doc || props.section === 'drawing') return null
|
||||
return (
|
||||
<AnnotationSection
|
||||
section={props.section}
|
||||
doc={doc}
|
||||
readOnly={props.readOnly}
|
||||
focus={props.focus}
|
||||
onBack={props.onBack}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** The drawing workspace: edit or read-only body of the same view. */
|
||||
function DrawingPlace(props: AnnotationsTabProps) {
|
||||
const t = useT()
|
||||
const doc = useSheetDocument()
|
||||
const preview = useEditorStore((s) => s.preview)
|
||||
const { section, readOnly, focus, navigate, onOpenSection, onBack } = props
|
||||
if (section !== 'drawing') {
|
||||
if (!doc) return null
|
||||
return (
|
||||
<AnnotationSection
|
||||
section={section}
|
||||
doc={doc}
|
||||
readOnly={readOnly}
|
||||
focus={focus}
|
||||
onBack={onBack}
|
||||
/>
|
||||
)
|
||||
}
|
||||
const body = { doc, navigate, onOpenSection, focus }
|
||||
const { readOnly, navigate, onOpenSection, focus } = props
|
||||
const body = { navigate, onOpenSection, focus }
|
||||
const ready = doc && preview
|
||||
return (
|
||||
<section
|
||||
data-place="annotations.drawing"
|
||||
@@ -56,16 +56,25 @@ export default function AnnotationsTab(props: AnnotationsTabProps) {
|
||||
aria-label={t('editor.tab.annotations')}
|
||||
className="min-h-24 space-y-3"
|
||||
>
|
||||
{doc && preview && readOnly && (
|
||||
<ReadOnlyAnnotations {...body} doc={doc} />
|
||||
)}
|
||||
{doc && preview && !readOnly && (
|
||||
<EditableAnnotations {...body} doc={doc} />
|
||||
)}
|
||||
{ready && readOnly && <ReadOnlyAnnotations {...body} doc={doc} />}
|
||||
{ready && !readOnly && <EditableAnnotations {...body} doc={doc} />}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations: the drawing workspace (canvas with its tools, the overview or the
|
||||
* properties and creation panels), or one of its full-width sections. Read-only, the
|
||||
* same view is browsable (canvas, list, properties as text) with no tool and no action.
|
||||
*/
|
||||
export default function AnnotationsTab(props: AnnotationsTabProps) {
|
||||
return props.section === 'drawing' ? (
|
||||
<DrawingPlace {...props} />
|
||||
) : (
|
||||
<SectionPlace {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
/** The shown view is gone (an undo elsewhere): back to the main view, selection cleared. */
|
||||
function useViewFallback(
|
||||
doc: AnatomicalSheetDocument,
|
||||
|
||||
Reference in new issue
Block a user