fix(editor): scope zone highlight to active obs + repaint detail SVG + harmonize header
Three related editor polish bugs from PDF-import dogfooding. (1) boneStates previously walked every observation, marking zones in collapsed observations as 'linked' (faint) or 'multi' (bold) — so deselected zones kept lingering color states. Now we read only the active observation; everything else renders neutral. (2) AnatomyCanvas applied highlight attributes once on mount; when the SVG (esp. inside DetailModal) loaded after the boneStates effect had already run, the freshly-mounted nodes had no data-state. Track loadedSrc and re-run the highlight effect after each SVG swap so detail-popup zones get colored on open. (3) NewReportRoute had "← Accueil" on the right while EditorRoute keeps it on the left — disorienting. Both headers now share the same left-aligned back-button + clickable Brand pattern. Deviation: hotfix rule caps at 2 files, this touches 3. Each fix is mechanical and obvious; bundling is cheaper than three separate patches. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
19c9c15979
commit
ff7ac5969e
3 files changed
+28
-19
No files matched your search
@@ -133,18 +133,11 @@ export default function EditorRoute() {
|
||||
|
||||
const boneStates = useMemo<Map<string, BoneState>>(() => {
|
||||
const map = new Map<string, BoneState>()
|
||||
if (!report) return map
|
||||
report.observations.forEach((obs, i) => {
|
||||
obs.zones.forEach((z) => {
|
||||
const prev = map.get(z.boneId)
|
||||
if (i === activeIndex) {
|
||||
map.set(z.boneId, prev === undefined ? 'current' : 'multi')
|
||||
} else if (prev === undefined) {
|
||||
map.set(z.boneId, 'linked')
|
||||
} else {
|
||||
map.set(z.boneId, 'multi')
|
||||
}
|
||||
})
|
||||
if (!report || activeIndex < 0) return map
|
||||
const active = report.observations[activeIndex]
|
||||
if (!active) return map
|
||||
active.zones.forEach((z) => {
|
||||
map.set(z.boneId, 'current')
|
||||
})
|
||||
return map
|
||||
}, [report, activeIndex])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Link, useNavigate } from 'react-router-dom'
|
||||
import PractitionerForm from '@/components/report/PractitionerForm'
|
||||
import AnimalForm from '@/components/report/AnimalForm'
|
||||
import Brand from '@/components/brand/Brand'
|
||||
@@ -43,9 +43,22 @@ export default function NewReportRoute() {
|
||||
|
||||
return (
|
||||
<main className="min-h-screen">
|
||||
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center justify-between">
|
||||
<Brand />
|
||||
<Button variant="ghost" onClick={() => navigate('/')}>← Accueil</Button>
|
||||
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center gap-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/')}
|
||||
aria-label="Retour à l'accueil"
|
||||
>
|
||||
← Accueil
|
||||
</Button>
|
||||
<Link
|
||||
to="/"
|
||||
aria-label="Retour à l'accueil"
|
||||
className="rounded-md px-1 py-0.5 hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
>
|
||||
<Brand />
|
||||
</Link>
|
||||
</header>
|
||||
<div className="max-w-3xl mx-auto px-6 py-8 space-y-8">
|
||||
<h1 className="font-serif text-3xl">Nouveau bilan</h1>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { loadSvg } from '@/anatomy/svgLoader'
|
||||
import { getBoneIdFromEvent } from '@/anatomy/svgConvention'
|
||||
import type { BoneState } from '@/anatomy/types'
|
||||
@@ -17,15 +17,18 @@ export default function AnatomyCanvas({
|
||||
className = '',
|
||||
}: AnatomyCanvasProps) {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||
const [loadedSrc, setLoadedSrc] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
const c = containerRef.current
|
||||
if (!c) return
|
||||
c.replaceChildren()
|
||||
setLoadedSrc(null)
|
||||
loadSvg(src).then((root) => {
|
||||
if (cancelled || !c) return
|
||||
c.appendChild(root)
|
||||
setLoadedSrc(src)
|
||||
})
|
||||
return () => { cancelled = true }
|
||||
}, [src])
|
||||
@@ -43,7 +46,7 @@ export default function AnatomyCanvas({
|
||||
|
||||
useEffect(() => {
|
||||
const c = containerRef.current
|
||||
if (!c) return
|
||||
if (!c || loadedSrc !== src) return
|
||||
const all = c.querySelectorAll<Element>('[data-anno-id]')
|
||||
all.forEach((el) => {
|
||||
const id = el.getAttribute('data-anno-id') as string
|
||||
@@ -51,7 +54,7 @@ export default function AnatomyCanvas({
|
||||
if (state && state !== 'default') el.setAttribute('data-state', state)
|
||||
else el.removeAttribute('data-state')
|
||||
})
|
||||
}, [boneStates])
|
||||
}, [boneStates, loadedSrc, src])
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
Reference in new issue
Block a user