fix(editor): C1 review round 1, note endings tested, tile hook, pin guard

Tests: note ends on another tile's Modifier, on Ajouter une reference, and is
replaced (announced again) by a newer drop; long titles shortened.
Read-only toggle deletes the key from openKeys explicitly. Drop slot and tile
wrappers moved to useTileActions. pinEdited pins nothing for an absent key.
This commit is contained in:
bchanot committed 2026-11-13 11:25:50 +01:00
1 parent 3303530717
commit 1e19479853
4 files changed
+80 -13

No files matched your search

@@ -243,6 +243,26 @@ function useDroppedDrafts(editing: boolean, readOnly: boolean) {
return [dropped, setDropped] as const
}
/** The tile's own actions: « Terminer » refocuses the header, a toggle ends the note. */
function useTileActions(
props: TileProps,
headerRef: RefObject<HTMLButtonElement | null>,
) {
const { on, editing, readOnly } = props
const [dropped, setDropped] = useDroppedDrafts(editing, readOnly)
return {
dropped,
setDropped,
done: () => {
if (on.done()) headerRef.current?.focus()
},
toggle: () => {
setDropped(null)
on.toggle()
},
}
}
/** « Saisie non appliquée : … »: plain text, the live region says it once elsewhere. */
function DroppedNote({ fields }: { fields: readonly Field[] }) {
const droppedText = useDroppedText()
@@ -264,14 +284,7 @@ export default function ReferenceTile(props: TileProps) {
const t = useT()
const base = tileBase(host, position, reference)
const headerRef = useRef<HTMLButtonElement>(null)
const [dropped, setDropped] = useDroppedDrafts(editing, props.readOnly)
const done = () => {
if (on.done()) headerRef.current?.focus()
}
const toggle = () => {
setDropped(null)
on.toggle()
}
const { dropped, setDropped, done, toggle } = useTileActions(props, headerRef)
return (
<li
data-reference-tile
@@ -45,9 +45,9 @@ export function useReferenceView(
const [pinned, setPinned] = useState<Pinned | null>(null)
// The reset view is the sheet order: the tile in edit sits at its own position.
const pinEdited = (): Pinned | null =>
editingKey === null
editingKey === null || !keys.includes(editingKey)
? null
: { key: editingKey, index: Math.max(0, keys.indexOf(editingKey)) }
: { key: editingKey, index: keys.indexOf(editingKey) }
if (seen !== resetSignal) {
setSeen(resetSignal)
setView(INITIAL)
@@ -48,6 +48,11 @@ export function useTileState(keys: readonly string[] | null) {
if (editingKey === key) {
if (!readOnly) return void finish()
setEditingKey(null)
return setOpenKeys((prev) => {
const next = new Set(prev)
next.delete(key)
return next
})
}
setOpenKeys((prev) => {
const next = new Set(prev)