feat(editor): tell the practitioner when a restored draft was rebased on a different sheet
This commit is contained in:
1 parent
5ed4a4b620
commit
e8f1734424
5 files changed
+64
-5
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import AnatomyCanvas from '@/components/canvas/AnatomyCanvas'
|
||||
import DetailModal from '@/components/canvas/DetailModal'
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
import type { ViewStates } from '@/anatomy/drawing'
|
||||
import { exportReportToPdf } from '@/pdf/export'
|
||||
import type { ExportWarning } from '@faunosteo/pdf'
|
||||
import type { RebaseOutcome } from '@faunosteo/domain'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
|
||||
|
||||
@@ -39,6 +40,11 @@ function missingItemsOf(warnings: readonly ExportWarning[]): string[] {
|
||||
return warnings.map((w) => (w.kind === 'logo_failed' ? w.slot : w.viewId))
|
||||
}
|
||||
|
||||
/** Zones and findings a draft rebase could not find on the loaded sheet. */
|
||||
function unresolvedCountOf(outcome: RebaseOutcome): number {
|
||||
return outcome.unresolvedZones + outcome.unresolvedFindings
|
||||
}
|
||||
|
||||
/** Editor on the reference sheet: wires the canvas, the pickers and the store. */
|
||||
export default function EditorRoute() {
|
||||
const navigate = useNavigate()
|
||||
@@ -55,18 +61,28 @@ export default function EditorRoute() {
|
||||
const [disclaimer, setDisclaimer] = useState<string | null>(null)
|
||||
const [exporting, setExporting] = useState(false)
|
||||
const [editDraft, setEditDraft] = useState<Identity | null>(null)
|
||||
// One alert per restore, even if the effect runs again before the re-render.
|
||||
const rebaseAlerted = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
window.scrollTo({ top: 0, left: 0, behavior: 'auto' })
|
||||
}, [])
|
||||
|
||||
// No report in memory: restore the per-tab draft once the sheet is known.
|
||||
// A draft rebased on another sheet is announced with its unresolved count.
|
||||
useEffect(() => {
|
||||
if (report) return
|
||||
if (sheet.status === 'ready') store.restoreDraft(sheet.index)
|
||||
if (sheet.status === 'ready') {
|
||||
const outcome = store.restoreDraft(sheet.index)
|
||||
if (outcome?.rebased && !rebaseAlerted.current) {
|
||||
rebaseAlerted.current = true
|
||||
const count = String(unresolvedCountOf(outcome))
|
||||
window.alert(t('editor.draft_rebased').replace('{count}', count))
|
||||
}
|
||||
}
|
||||
if (sheet.status !== 'loading' && !useReportStore.getState().report)
|
||||
navigate('/')
|
||||
}, [report, sheet, store, navigate])
|
||||
}, [report, sheet, store, navigate, t])
|
||||
|
||||
useEffect(() => {
|
||||
if (sheet.status !== 'ready' || typeof sessionStorage === 'undefined')
|
||||
|
||||
Reference in new issue
Block a user