diff --git a/frontend/src/components/PersonCard.jsx b/frontend/src/components/PersonCard.jsx index badc9ff..09df9d4 100644 --- a/frontend/src/components/PersonCard.jsx +++ b/frontend/src/components/PersonCard.jsx @@ -16,6 +16,9 @@ import { firstNameLabel, fullNameLabel, isFirstNameUnknown } from '../utils/pers import { isYearOnly } from '../utils/dateInput.js' import DateField from './DateField.jsx' +// Aucune modification en cours (référence stable) +const NO_EDITS = Object.freeze({}) + const TYPE_LABELS = { photo: t('Photo'), video: t('Vidéo'), @@ -93,13 +96,17 @@ const PersonCard = ({ } }, [tab, person.id, treeId, immichToken, lifeRevision]) - // État local pour les modifications en mode édition - const [edits, setEdits] = useState({}) + // Modifications en cours, rattachées à la personne qu'elles concernent. Au changement de fiche, + // le premier rendu ne doit pas voir celles de la personne d'avant : un champ qui s'initialise à + // ce moment-là (DateField) les garderait, et la date d'une personne passait sur une autre. + const [editState, setEditState] = useState(() => ({ personId: person.id, values: {}, changed: false })) + const ownEdits = editState.personId === person.id + const edits = ownEdits ? editState.values : NO_EDITS + const hasChanges = ownEdits && editState.changed // Prénom inconnu (case cochée) et saisie de prénom vide sans case : le prénom est demandé avant l'enregistrement const [unknownFirstName, setUnknownFirstName] = useState(() => isFirstNameUnknown(person)) const [firstNameMissing, setFirstNameMissing] = useState(false) const [lastNameMissing, setLastNameMissing] = useState(false) - const [hasChanges, setHasChanges] = useState(false) const [saving, setSaving] = useState(false) const [saveSuccess, setSaveSuccess] = useState(false) const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) @@ -120,11 +127,10 @@ const PersonCard = ({ // Reset edits quand la personne change useEffect(() => { - setEdits({}) + setEditState({ personId: person.id, values: {}, changed: false }) setUnknownFirstName(isFirstNameUnknown(person)) setFirstNameMissing(false) setLastNameMissing(false) - setHasChanges(false) setShowDeleteConfirm(false) setActiveRelationSearch(null) setRelationSearchQuery('') @@ -201,8 +207,12 @@ const PersonCard = ({ } const handleFieldChange = (field, value) => { - setEdits(prev => ({ ...prev, [field]: value })) - setHasChanges(true) + const personId = person.id + setEditState(prev => ({ + personId, + values: { ...(prev.personId === personId ? prev.values : {}), [field]: value }, + changed: true, + })) } const handleSave = async () => { @@ -218,8 +228,9 @@ const PersonCard = ({ } setSaving(true) try { - await onSave(person.id, edits) - setHasChanges(false) + const savedFor = person.id + await onSave(savedFor, edits) + setEditState(prev => (prev.personId === savedFor ? { ...prev, changed: false } : prev)) setSaveSuccess(true) setTimeout(() => setSaveSuccess(false), 2000) } finally { diff --git a/frontend/src/components/galaxy/renderers.js b/frontend/src/components/galaxy/renderers.js index e541346..7926e76 100644 --- a/frontend/src/components/galaxy/renderers.js +++ b/frontend/src/components/galaxy/renderers.js @@ -101,9 +101,10 @@ function computeCouplePoints(p1Pos, p2Pos, unionPos, p1R, p2R, nodeRandomData, s export const FIL = { color: '#E3A590', width: 1.1, dot: '#D2694A', dotR: 2.6 } // Ligne de la fratrie : sous les prénoms et années des parents, au-dessus des enfants const BUS_DY = 100 -// Accolade : coins arrondis de rayon fixe (forme A, choisie par Patch), écart minimal en dessous duquel l'enfant descend droit +// Accolade : coins arrondis de rayon fixe (forme A, choisie par Patch). En dessous de deux rayons d'écart, +// deux coins ne tiennent pas sans faire une marche : l'enfant est relié par un trait droit depuis l'union. const SIB_R = 24 -const SIB_STRAIGHT_DX = 12 +const SIB_STRAIGHT_DX = SIB_R * 2 function busY(sourceId, sy) { let h = 0 @@ -123,7 +124,14 @@ export function traceSibship(ctx, sourceId, sourcePos, items) { for (const { cx: ex, cy: ey } of items) { const dx = ex - sx ctx.moveTo(sx, sy) - if (Math.abs(dx) < SIB_STRAIGHT_DX) { ctx.lineTo(sx, by); ctx.lineTo(ex, by); ctx.lineTo(ex, ey); continue } + if (Math.abs(dx) < SIB_STRAIGHT_DX) { + // Le tronc descend jusqu'à la barre, puis un S doux, vertical au départ et à l'arrivée, rejoint l'enfant : + // il se sépare là où se séparent les autres enfants, pas sous l'union + const h = ey - by + ctx.lineTo(sx, by) + ctx.bezierCurveTo(sx, by + h * 0.55, ex, ey - h * 0.45, ex, ey) + continue + } const dir = Math.sign(dx) const k = Math.min(rr, Math.abs(dx) / 2) ctx.lineTo(sx, by - k) diff --git a/frontend/src/components/galaxy/renderers.test.js b/frontend/src/components/galaxy/renderers.test.js index 93ddbe0..a600ef0 100644 --- a/frontend/src/components/galaxy/renderers.test.js +++ b/frontend/src/components/galaxy/renderers.test.js @@ -35,4 +35,17 @@ describe('traceSibship (accolade franche)', () => { traceSibship(ctx, 'u-1', src, [{ cx: 505, cy: 480 }]) expect(count('arcTo')).toBe(0) }) + + it('un enfant à moins de deux rayons de l\'aplomb est relié par un seul S, sans marche', () => { + const { ctx, calls } = recorder() + traceSibship(ctx, 'u-1', src, [{ cx: 515, cy: 480 }]) + expect(calls.filter(c => c[0] === 'arcTo').length).toBe(0) + // Tronc vertical jusqu'à la barre, puis le S + expect(calls.filter(c => c[0] === 'lineTo').map(c => c[1])).toEqual([500]) + const [curve] = calls.filter(c => c[0] === 'bezierCurveTo') + // Départ vertical sous l'union, arrivée verticale sur l'enfant + expect(curve[1]).toBe(500) + expect(curve[3]).toBe(515) + expect(curve.slice(5)).toEqual([515, 480]) + }) })