fix(editor): an explicit discard of the citations draft says nothing

This commit is contained in:
bchanot committed 2026-11-15 17:04:28 +01:00
1 parent 82bdf8de71
commit 7a5684aace
4 files changed
+69 -9

No files matched your search

@@ -17,8 +17,11 @@ import { CITATIONS_TITLE_ID } from './useCitationsPanel'
export interface CitationsDialogProps {
/** The family or finding node whose citations it shows; null while it is closed. */
citedBy: ElementKey | null
/** A close: a user one (✕, Escape, the backdrop) is refused by a draft; forced goes. */
onClose: (forced?: boolean) => boolean
/**
* A close: a user one (✕, Escape, the backdrop) is refused by a draft; forced goes;
* `discarded` after the user's « Abandonner » (nothing said).
*/
onClose: (forced?: boolean, discarded?: boolean) => boolean
/** « Tout afficher dans l'onglet Références ». */
onShowAll: () => void
/** « Aller à » a citing finding or a reference. */
@@ -67,7 +70,7 @@ function EditBody({ citedBy, mode, props }: BodyProps) {
guards={props.guards}
references={props.references}
onDone={mode.done}
onDiscardClose={() => props.onClose(true)}
onDiscardClose={() => props.onClose(true, true)}
/>
</>
)
@@ -125,7 +125,8 @@ function clearerOf(latest: { current: LeaveNav }): (layer: LayerName) => void {
const above = layersAbove(layer)
if (above.includes('reference') && state.reference) references.close(true)
const cited = above.includes('citations') && citationsOfView(state)
if (cited) closeCitations(true)
// Clean, or a draft the user just answered « Abandonner » for: nothing to say.
if (cited) closeCitations(true, true)
}
}
+6 -5
View File
@@ -138,9 +138,10 @@ export interface EditorNavigation {
openCitations: (citedBy: ElementKey, opener?: Opener) => void
/**
* A close of the citations dialog: a user one is refused by its draft (it asks first),
* a forced one goes (the draft is dropped, and said so).
* a forced one goes (the draft is dropped, and said so). `discarded`: the user already
* answered « Abandonner », the forced close says nothing (as the other forms).
*/
closeCitations: (forced?: boolean) => boolean
closeCitations: (forced?: boolean, discarded?: boolean) => boolean
/** « X références », where the focus returns once the citations dialog is closed. */
citationsTrigger: () => HTMLElement | null
/**
@@ -405,11 +406,11 @@ function useCitationsLayer(ctx: LayerContext, openers: Openers) {
[openers, dispatch, mark],
)
const closeCitations = useCallback(
(forced = false) => {
(forced = false, discarded = false) => {
const answer = guards.ask('citations', forced)
if (!answer.allowed) return false
// A forced close of a draft says it was dropped, as the other forced closes.
if (answer.note) announce(answer.note)
// A draft dropped by a move the user did not answer is said; an « Abandonner » is not.
if (answer.note && !discarded) announce(answer.note)
mark()
dispatch({ type: 'close_citations' })
return true