fix(app): a focus request is consumed once, not replayed on tab return
This commit is contained in:
1 parent
4f223e04cd
commit
3d589e1556
14 files changed
+99
-30
No files matched your search
@@ -30,7 +30,7 @@ import {
|
|||||||
storeCanEdit,
|
storeCanEdit,
|
||||||
} from '@/editor/mode'
|
} from '@/editor/mode'
|
||||||
import { leaveGuardArmed, useEditorStore } from '@/editor/state/editorStore'
|
import { leaveGuardArmed, useEditorStore } from '@/editor/state/editorStore'
|
||||||
import type { FocusRequest } from '@/editor/focusRequest'
|
import { FocusConsumedContext, type FocusRequest } from '@/editor/focusRequest'
|
||||||
import type { EditorTabId, EditorTabProps } from '@/editor/tabs'
|
import type { EditorTabId, EditorTabProps } from '@/editor/tabs'
|
||||||
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
||||||
import { useTabTier } from '@/editor/useViewport'
|
import { useTabTier } from '@/editor/useViewport'
|
||||||
@@ -80,6 +80,8 @@ function DraftEditor({
|
|||||||
const tier = useTabTier()
|
const tier = useTabTier()
|
||||||
const [tab, setTab] = useState<EditorTabId>(FIRST_TAB)
|
const [tab, setTab] = useState<EditorTabId>(FIRST_TAB)
|
||||||
const [focus, setFocus] = useState<FocusRequest | undefined>()
|
const [focus, setFocus] = useState<FocusRequest | undefined>()
|
||||||
|
const clearFocus = (serial: number) =>
|
||||||
|
setFocus((prev) => (prev?.serial === serial ? undefined : prev))
|
||||||
const goTo: EditorTabProps['onGoTo'] = (next, key) => {
|
const goTo: EditorTabProps['onGoTo'] = (next, key) => {
|
||||||
setTab(next)
|
setTab(next)
|
||||||
setFocus((prev) => ({ key, serial: (prev?.serial ?? 0) + 1 }))
|
setFocus((prev) => ({ key, serial: (prev?.serial ?? 0) + 1 }))
|
||||||
@@ -129,14 +131,16 @@ function DraftEditor({
|
|||||||
<CopyIssueNotice />
|
<CopyIssueNotice />
|
||||||
<EditorTabs active={tab} tier={tier} onSelect={setTab} />
|
<EditorTabs active={tab} tier={tier} onSelect={setTab} />
|
||||||
<div id={PANEL_ID} role="tabpanel" aria-label={t(`editor.tab.${tab}`)}>
|
<div id={PANEL_ID} role="tabpanel" aria-label={t(`editor.tab.${tab}`)}>
|
||||||
<EditorTabBody
|
<FocusConsumedContext value={clearFocus}>
|
||||||
tab={tab}
|
<EditorTabBody
|
||||||
readOnly={readOnly}
|
tab={tab}
|
||||||
onSelectTab={setTab}
|
readOnly={readOnly}
|
||||||
focus={focus}
|
onSelectTab={setTab}
|
||||||
onGoTo={goTo}
|
focus={focus}
|
||||||
reloadSheet={reloadSheet}
|
onGoTo={goTo}
|
||||||
/>
|
reloadSheet={reloadSheet}
|
||||||
|
/>
|
||||||
|
</FocusConsumedContext>
|
||||||
</div>
|
</div>
|
||||||
<ConflictDialog />
|
<ConflictDialog />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import type {
|
|||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
||||||
import { annotationFocus } from '@/editor/annotations/focusTarget'
|
import { annotationFocus } from '@/editor/annotations/focusTarget'
|
||||||
import { useFocusRequest } from '@/editor/focusRequest'
|
|
||||||
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
|
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
|
||||||
import { parseFrame, type Frame } from '@/editor/annotations/frame'
|
import { parseFrame, type Frame } from '@/editor/annotations/frame'
|
||||||
import { isEditable } from '@/editor/annotations/geometryEdit'
|
import { isEditable } from '@/editor/annotations/geometryEdit'
|
||||||
@@ -23,6 +22,7 @@ import {
|
|||||||
useViewModel,
|
useViewModel,
|
||||||
type ViewModel,
|
type ViewModel,
|
||||||
} from '@/editor/annotations/useViewModel'
|
} from '@/editor/annotations/useViewModel'
|
||||||
|
import { useFocusRequest } from '@/editor/focusRequest'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorTabProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
@@ -10,12 +9,15 @@ import TextField from '@/components/editor/fields/TextField'
|
|||||||
import DeleteDialog, {
|
import DeleteDialog, {
|
||||||
type DeleteTarget,
|
type DeleteTarget,
|
||||||
} from '@/components/editor/DeleteDialog'
|
} from '@/components/editor/DeleteDialog'
|
||||||
|
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
||||||
import { isBlank, nullable } from '@/editor/sheetDocument'
|
import { isBlank, nullable } from '@/editor/sheetDocument'
|
||||||
import { useEditCommand } from '@/editor/useEditCommand'
|
import { useEditCommand } from '@/editor/useEditCommand'
|
||||||
import type { Locale } from '@/i18n/types'
|
import type { Locale } from '@/i18n/types'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|
||||||
|
const CARD = 'rounded-lg border border-[var(--color-border)] p-3'
|
||||||
|
|
||||||
/** Annotation categories: list, rename, colour, add, delete with dependents. */
|
/** Annotation categories: list, rename, colour, add, delete with dependents. */
|
||||||
export default function CategoriesSection({
|
export default function CategoriesSection({
|
||||||
doc,
|
doc,
|
||||||
@@ -78,7 +80,7 @@ function CategoryRow({
|
|||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
{...focusAttrs({ kind: 'category', id: category.id })}
|
{...focusAttrs({ kind: 'category', id: category.id })}
|
||||||
className={`rounded-lg border border-[var(--color-border)] p-3 ${FOCUS_CLASS}`}
|
className={`${CARD} ${FOCUS_CLASS}`}
|
||||||
>
|
>
|
||||||
<div className="grid gap-3 md:grid-cols-3">
|
<div className="grid gap-3 md:grid-cols-3">
|
||||||
{(['fr', 'en'] as const).map((locale) => (
|
{(['fr', 'en'] as const).map((locale) => (
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import { useEditCommand } from '@/editor/useEditCommand'
|
|||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { REFERENCE_TYPES } from './referenceTypes'
|
import { REFERENCE_TYPES } from './referenceTypes'
|
||||||
|
|
||||||
|
const CARD = 'space-y-3 rounded-lg border border-[var(--color-border)] p-3'
|
||||||
|
|
||||||
/** One reference: fields commit one by one, ↑ / ↓ reorder, delete asks the core. */
|
/** One reference: fields commit one by one, ↑ / ↓ reorder, delete asks the core. */
|
||||||
export default function ReferenceRow({
|
export default function ReferenceRow({
|
||||||
reference,
|
reference,
|
||||||
@@ -38,10 +40,7 @@ export default function ReferenceRow({
|
|||||||
}))
|
}))
|
||||||
const prefix = `reference-${reference.id}`
|
const prefix = `reference-${reference.id}`
|
||||||
return (
|
return (
|
||||||
<li
|
<li {...focusAttrs(key)} className={`${CARD} ${FOCUS_CLASS}`}>
|
||||||
{...focusAttrs(key)}
|
|
||||||
className={`space-y-3 rounded-lg border border-[var(--color-border)] p-3 ${FOCUS_CLASS}`}
|
|
||||||
>
|
|
||||||
<div className="grid gap-3 md:grid-cols-2">
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
<SelectField
|
<SelectField
|
||||||
id={`${prefix}-type`}
|
id={`${prefix}-type`}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import PropertiesPanel from '@/components/editor/annotations/PropertiesPanel'
|
|||||||
import ViewSwitcher from '@/components/editor/annotations/ViewSwitcher'
|
import ViewSwitcher from '@/components/editor/annotations/ViewSwitcher'
|
||||||
import SelectionTag from '@/components/editor/annotations/SelectionTag'
|
import SelectionTag from '@/components/editor/annotations/SelectionTag'
|
||||||
import { annotationFocus } from '@/editor/annotations/focusTarget'
|
import { annotationFocus } from '@/editor/annotations/focusTarget'
|
||||||
import { useFocusRequest } from '@/editor/focusRequest'
|
|
||||||
import { mainViewId, useViewModel } from '@/editor/annotations/useViewModel'
|
import { mainViewId, useViewModel } from '@/editor/annotations/useViewModel'
|
||||||
|
import { useFocusRequest } from '@/editor/focusRequest'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import { useEditorStore } from '@/editor/state/editorStore'
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorTabProps } from '@/editor/tabs'
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import AttributionSection from '@/components/editor/general/AttributionSection'
|
import AttributionSection from '@/components/editor/general/AttributionSection'
|
||||||
import CategoriesSection from '@/components/editor/general/CategoriesSection'
|
import CategoriesSection from '@/components/editor/general/CategoriesSection'
|
||||||
import TextsSection from '@/components/editor/general/TextsSection'
|
import TextsSection from '@/components/editor/general/TextsSection'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
|
||||||
import { useRowFocus } from '@/editor/focusRequest'
|
import { useRowFocus } from '@/editor/focusRequest'
|
||||||
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorTabProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import DeleteDialog, {
|
|||||||
} from '@/components/editor/DeleteDialog'
|
} from '@/components/editor/DeleteDialog'
|
||||||
import ReferenceForm from '@/components/editor/references/ReferenceForm'
|
import ReferenceForm from '@/components/editor/references/ReferenceForm'
|
||||||
import ReferenceRow from '@/components/editor/references/ReferenceRow'
|
import ReferenceRow from '@/components/editor/references/ReferenceRow'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
|
||||||
import { useRowFocus } from '@/editor/focusRequest'
|
import { useRowFocus } from '@/editor/focusRequest'
|
||||||
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorTabProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import DeleteDialog, {
|
|||||||
} from '@/components/editor/DeleteDialog'
|
} from '@/components/editor/DeleteDialog'
|
||||||
import RegionForm from '@/components/editor/vertebrae/RegionForm'
|
import RegionForm from '@/components/editor/vertebrae/RegionForm'
|
||||||
import RegionRow from '@/components/editor/vertebrae/RegionRow'
|
import RegionRow from '@/components/editor/vertebrae/RegionRow'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
|
||||||
import { useRowFocus } from '@/editor/focusRequest'
|
import { useRowFocus } from '@/editor/focusRequest'
|
||||||
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorTabProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import DeleteDialog, {
|
|||||||
import DetailViewForm from '@/components/editor/views/DetailViewForm'
|
import DetailViewForm from '@/components/editor/views/DetailViewForm'
|
||||||
import DetailViewRow from '@/components/editor/views/DetailViewRow'
|
import DetailViewRow from '@/components/editor/views/DetailViewRow'
|
||||||
import MainViewCard from '@/components/editor/views/MainViewCard'
|
import MainViewCard from '@/components/editor/views/MainViewCard'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
|
||||||
import { useRowFocus } from '@/editor/focusRequest'
|
import { useRowFocus } from '@/editor/focusRequest'
|
||||||
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorTabProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import type { VertebralRegion } from '@faunosteo/core-wasm/types'
|
import type { VertebralRegion } from '@faunosteo/core-wasm/types'
|
||||||
import ActionButton from '@/components/editor/fields/ActionButton'
|
import ActionButton from '@/components/editor/fields/ActionButton'
|
||||||
import MoveButtons from '@/components/editor/fields/MoveButtons'
|
import MoveButtons from '@/components/editor/fields/MoveButtons'
|
||||||
import ReadOnlyValue from '@/components/editor/fields/ReadOnlyValue'
|
import ReadOnlyValue from '@/components/editor/fields/ReadOnlyValue'
|
||||||
import TextField from '@/components/editor/fields/TextField'
|
import TextField from '@/components/editor/fields/TextField'
|
||||||
|
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
||||||
import { isBlank } from '@/editor/sheetDocument'
|
import { isBlank } from '@/editor/sheetDocument'
|
||||||
import { useEditCommand } from '@/editor/useEditCommand'
|
import { useEditCommand } from '@/editor/useEditCommand'
|
||||||
import type { Locale } from '@/i18n/types'
|
import type { Locale } from '@/i18n/types'
|
||||||
@@ -12,6 +12,8 @@ import { useT } from '@/i18n/useT'
|
|||||||
import RangeFields from './RangeFields'
|
import RangeFields from './RangeFields'
|
||||||
import { parseRange, wholeNumber } from './numbers'
|
import { parseRange, wholeNumber } from './numbers'
|
||||||
|
|
||||||
|
const CARD = 'space-y-3 rounded-lg border border-[var(--color-border)] p-3'
|
||||||
|
|
||||||
const textOf = (value: number | undefined): string =>
|
const textOf = (value: number | undefined): string =>
|
||||||
value === undefined ? '' : String(value)
|
value === undefined ? '' : String(value)
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ export default function RegionRow({
|
|||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
{...focusAttrs({ kind: 'region', code: region.code })}
|
{...focusAttrs({ kind: 'region', code: region.code })}
|
||||||
className={`space-y-3 rounded-lg border border-[var(--color-border)] p-3 ${FOCUS_CLASS}`}
|
className={`${CARD} ${FOCUS_CLASS}`}
|
||||||
>
|
>
|
||||||
<div className="grid gap-3 md:grid-cols-4">
|
<div className="grid gap-3 md:grid-cols-4">
|
||||||
<ReadOnlyValue
|
<ReadOnlyValue
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
|
||||||
import type { DetailView, SheetView } from '@faunosteo/core-wasm/types'
|
import type { DetailView, SheetView } from '@faunosteo/core-wasm/types'
|
||||||
import ActionButton from '@/components/editor/fields/ActionButton'
|
import ActionButton from '@/components/editor/fields/ActionButton'
|
||||||
import SelectField from '@/components/editor/fields/SelectField'
|
import SelectField from '@/components/editor/fields/SelectField'
|
||||||
|
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
||||||
import { useViewUpdate } from '@/editor/useViewUpdate'
|
import { useViewUpdate } from '@/editor/useViewUpdate'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
@@ -9,6 +9,8 @@ import CropEditor from './CropEditor'
|
|||||||
import ViewDrawing from './ViewDrawing'
|
import ViewDrawing from './ViewDrawing'
|
||||||
import ViewNames from './ViewNames'
|
import ViewNames from './ViewNames'
|
||||||
|
|
||||||
|
const CARD = 'space-y-3 rounded-lg border border-[var(--color-border)] p-3'
|
||||||
|
|
||||||
/** One detail view: names, parent, own drawing, crop (one crop canvas open at a time). */
|
/** One detail view: names, parent, own drawing, crop (one crop canvas open at a time). */
|
||||||
export default function DetailViewRow({
|
export default function DetailViewRow({
|
||||||
view,
|
view,
|
||||||
@@ -38,7 +40,7 @@ export default function DetailViewRow({
|
|||||||
<li
|
<li
|
||||||
aria-label={view.name[locale]}
|
aria-label={view.name[locale]}
|
||||||
{...focusAttrs({ kind: 'view', id: view.id })}
|
{...focusAttrs({ kind: 'view', id: view.id })}
|
||||||
className={`space-y-3 rounded-lg border border-[var(--color-border)] p-3 ${FOCUS_CLASS}`}
|
className={`${CARD} ${FOCUS_CLASS}`}
|
||||||
>
|
>
|
||||||
<div className="grid gap-3 md:grid-cols-3">
|
<div className="grid gap-3 md:grid-cols-3">
|
||||||
<ViewNames view={view} readOnly={readOnly} views={edit} />
|
<ViewNames view={view} readOnly={readOnly} views={edit} />
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
|
||||||
import type { MainView } from '@faunosteo/core-wasm/types'
|
import type { MainView } from '@faunosteo/core-wasm/types'
|
||||||
|
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
||||||
import { useViewUpdate } from '@/editor/useViewUpdate'
|
import { useViewUpdate } from '@/editor/useViewUpdate'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import ViewDrawing from './ViewDrawing'
|
import ViewDrawing from './ViewDrawing'
|
||||||
import ViewNames from './ViewNames'
|
import ViewNames from './ViewNames'
|
||||||
|
|
||||||
|
const CARD = 'space-y-3 rounded-lg border border-[var(--color-border)] p-3'
|
||||||
|
|
||||||
/** The main view: its names and its drawing (state, detail, « Choisir une illustration »). */
|
/** The main view: its names and its drawing (state, detail, « Choisir une illustration »). */
|
||||||
export default function MainViewCard({
|
export default function MainViewCard({
|
||||||
view,
|
view,
|
||||||
@@ -19,7 +21,7 @@ export default function MainViewCard({
|
|||||||
<section
|
<section
|
||||||
aria-labelledby="views-main-title"
|
aria-labelledby="views-main-title"
|
||||||
{...focusAttrs({ kind: 'view', id: view.id })}
|
{...focusAttrs({ kind: 'view', id: view.id })}
|
||||||
className={`space-y-3 rounded-lg border border-[var(--color-border)] p-3 ${FOCUS_CLASS}`}
|
className={`${CARD} ${FOCUS_CLASS}`}
|
||||||
>
|
>
|
||||||
<h3 id="views-main-title" className="text-base font-semibold">
|
<h3 id="views-main-title" className="text-base font-semibold">
|
||||||
{t('editor.views.main_title')}
|
{t('editor.views.main_title')}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef } from 'react'
|
import { createContext, useContext, useEffect, useRef } from 'react'
|
||||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||||
|
|
||||||
/** « Aller à … »: the element to show and a serial so each request is consumed once. */
|
/** « Aller à … »: the element to show and a serial so each request is consumed once. */
|
||||||
@@ -19,17 +19,24 @@ export function focusAttrs(key: ElementKey) {
|
|||||||
export const FOCUS_CLASS =
|
export const FOCUS_CLASS =
|
||||||
'focus:outline focus:outline-2 focus:outline-[var(--color-accent)]'
|
'focus:outline focus:outline-2 focus:outline-[var(--color-accent)]'
|
||||||
|
|
||||||
/** Runs `apply` once per request serial, after the tab has rendered. */
|
/** The route's answer to a consumed request: it clears it, so a remounted tab never replays. */
|
||||||
|
export const FocusConsumedContext = createContext<(serial: number) => void>(
|
||||||
|
() => undefined,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Runs `apply` once per request, after the tab has rendered, then reports it consumed. */
|
||||||
export function useFocusRequest(
|
export function useFocusRequest(
|
||||||
focus: FocusRequest | undefined,
|
focus: FocusRequest | undefined,
|
||||||
apply: (key: ElementKey) => void,
|
apply: (key: ElementKey) => void,
|
||||||
): void {
|
): void {
|
||||||
const handled = useRef<number | null>(null)
|
const handled = useRef<number | null>(null)
|
||||||
|
const consumed = useContext(FocusConsumedContext)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!focus || handled.current === focus.serial) return
|
if (!focus || handled.current === focus.serial) return
|
||||||
handled.current = focus.serial
|
handled.current = focus.serial
|
||||||
apply(focus.key)
|
apply(focus.key)
|
||||||
})
|
consumed(focus.serial)
|
||||||
|
}, [focus, apply, consumed])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Scrolls to and focuses the row tagged with `key`. */
|
/** Scrolls to and focuses the row tagged with `key`. */
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
/** Lot J fix: « Aller à … » seeds each tab's own selection once. */
|
/** Lot J fix: « Aller à … » seeds each tab's own selection once. */
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import { useState } from 'react'
|
||||||
import { cleanup, render, screen } from '@testing-library/react'
|
import { cleanup, render, screen } from '@testing-library/react'
|
||||||
|
import userEvent from '@testing-library/user-event'
|
||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
ElementKey,
|
ElementKey,
|
||||||
@@ -9,6 +11,7 @@ import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
|||||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
||||||
import VertebraeTab from '@/components/editor/tabs/VertebraeTab'
|
import VertebraeTab from '@/components/editor/tabs/VertebraeTab'
|
||||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||||
|
import { FocusConsumedContext, type FocusRequest } from '@/editor/focusRequest'
|
||||||
import { issueTarget } from '@/editor/verification'
|
import { issueTarget } from '@/editor/verification'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { edit, insert, point } from '../helpers/editorFixtures'
|
import { edit, insert, point } from '../helpers/editorFixtures'
|
||||||
@@ -192,3 +195,51 @@ describe('issueTarget', () => {
|
|||||||
expect(issueTarget(d, 'nothing', 'fr')).toBeNull()
|
expect(issueTarget(d, 'nothing', 'fr')).toBeNull()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** The route's contract: one tab mounted at a time, the request cleared once consumed. */
|
||||||
|
function Harness() {
|
||||||
|
const [tab, setTab] = useState<'references' | 'vertebrae'>('references')
|
||||||
|
const [focus, setFocus] = useState<FocusRequest | undefined>({
|
||||||
|
key: { kind: 'reference', id: 'ref-a' },
|
||||||
|
serial: 1,
|
||||||
|
})
|
||||||
|
const clear = (serial: number) =>
|
||||||
|
setFocus((prev) => (prev?.serial === serial ? undefined : prev))
|
||||||
|
const Body = tab === 'references' ? ReferencesTab : VertebraeTab
|
||||||
|
return (
|
||||||
|
<FocusConsumedContext value={clear}>
|
||||||
|
<button
|
||||||
|
onClick={() =>
|
||||||
|
setTab(tab === 'references' ? 'vertebrae' : 'references')
|
||||||
|
}
|
||||||
|
>
|
||||||
|
switch
|
||||||
|
</button>
|
||||||
|
<Body {...base} focus={focus} />
|
||||||
|
</FocusConsumedContext>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('a consumed request', () => {
|
||||||
|
it('is not replayed when the tab is left and reopened', async () => {
|
||||||
|
const text = insert(baseText(), {
|
||||||
|
kind: 'reference',
|
||||||
|
value: {
|
||||||
|
id: 'ref-a',
|
||||||
|
type: 'book',
|
||||||
|
citation: 'Alpha',
|
||||||
|
url: null,
|
||||||
|
doi: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await openReady({ text })
|
||||||
|
const user = userEvent.setup()
|
||||||
|
render(<Harness />)
|
||||||
|
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||||||
|
'ref-a',
|
||||||
|
)
|
||||||
|
await user.click(screen.getByText('switch'))
|
||||||
|
await user.click(screen.getByText('switch'))
|
||||||
|
expect(document.activeElement?.getAttribute('data-focus-key')).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in new issue
Block a user